1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
if has_key(g:polyglot_is_disabled, 'typescript')
finish
endif
" set Vi-incompatible, compiler and commentstring
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1
let s:cpo_save = &cpo
set cpo-=C
compiler typescript
setlocal commentstring=//\ %s
" Set 'formatoptions' to break comment lines but not other lines,
" " and insert the comment leader when hitting <CR> or using "o".
setlocal formatoptions-=t formatoptions+=croql
if !&l:formatexpr && !&l:formatprg
setlocal formatexpr=Fixedgq(v:lnum,v:count)
endif
" setlocal foldmethod=syntax
let &cpo = s:cpo_save
unlet s:cpo_save
function! Fixedgq(lnum, count)
let l:tw = &tw ? &tw : 80
let l:count = a:count
let l:first_char = indent(a:lnum) + 1
if mode() == 'i' " gq was not pressed, but tw was set
return 1
endif
" This gq is only meant to do code with strings, not comments
if yats#IsLineComment(a:lnum, l:first_char) || yats#IsInMultilineComment(a:lnum, l:first_char)
return 1
endif
if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq
return 1
endif
" Put all the lines on one line and do normal spliting after that
if l:count > 1
while l:count > 1
let l:count -= 1
normal! J
endwhile
endif
let l:winview = winsaveview()
call cursor(a:lnum, l:tw + 1)
let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum)
call cursor(a:lnum, l:tw + 1)
let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum)
" No need for special treatment, normal gq handles edgecases better
if breakpoint[1] == orig_breakpoint[1]
call winrestview(l:winview)
return 1
endif
" Try breaking after string
if breakpoint[1] <= indent(a:lnum)
call cursor(a:lnum, l:tw + 1)
let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum)
endif
if breakpoint[1] != 0
call feedkeys("r\<CR>")
else
let l:count = l:count - 1
endif
" run gq on new lines
if l:count == 1
call feedkeys("gqq")
endif
return 0
endfunction
function! TsIncludeExpr(file)
if (filereadable(a:file))
return l:file
else
let l:file2=substitute(a:file,'$','/index.ts','g')
return l:file2
endif
endfunction
set path+=./node_modules/**,node_modules/**
set include=import\_s.\\zs[^'\"]*\\ze
set includeexpr=TsIncludeExpr(v:fname)
set suffixesadd+=.ts
"
" TagBar
"
let g:tagbar_type_typescript = {
\ 'ctagstype' : 'typescript',
\ 'kinds' : [
\ 'c:classes',
\ 'a:abstract classes',
\ 't:types',
\ 'n:modules',
\ 'f:functions',
\ 'v:variables',
\ 'l:varlambdas',
\ 'm:members',
\ 'i:interfaces',
\ 'e:enums'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 'c' : 'classes',
\ 'a' : 'abstract classes',
\ 't' : 'types',
\ 'f' : 'functions',
\ 'v' : 'variables',
\ 'l' : 'varlambdas',
\ 'm' : 'members',
\ 'i' : 'interfaces',
\ 'e' : 'enums'
\ },
\ 'scope2kind' : {
\ 'classes' : 'c',
\ 'abstract classes' : 'a',
\ 'types' : 't',
\ 'functions' : 'f',
\ 'variables' : 'v',
\ 'varlambdas' : 'l',
\ 'members' : 'm',
\ 'interfaces' : 'i',
\ 'enums' : 'e'
\ }
\ }
" In case you've updated/customized your ~/.ctags and prefer to use it.
if get(g:, 'typescript_use_builtin_tagbar_defs', 1)
let g:tagbar_type_typescript.deffile = expand('<sfile>:p:h:h') . '/ctags/typescript.ctags'
endif
|