From 7580b9dcff89ed7dee1f7094e938acdee94464af Mon Sep 17 00:00:00 2001 From: Yosuke Kurami Date: Tue, 14 Feb 2017 17:32:00 +0900 Subject: [PATCH 01/45] Add "keyof" to reserved words (#102) --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 4abaeed..9d2386e 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -122,7 +122,7 @@ syntax keyword typescriptGlobalObjects Array Boolean Date Function Infinity Math syntax keyword typescriptExceptions try catch throw finally Error EvalError RangeError ReferenceError SyntaxError TypeError URIError -syntax keyword typescriptReserved constructor declare as interface module abstract enum int short export interface static byte extends long super char final native synchronized class float package throws goto private transient debugger implements protected volatile double import public type namespace from get set +syntax keyword typescriptReserved constructor declare as interface module abstract enum int short export interface static byte extends long super char final native synchronized class float package throws goto private transient debugger implements protected volatile double import public type namespace from get set keyof "}}} "" typescript/DOM/HTML/CSS specified things"{{{ From 5028d2eb8aa33447934fd40d16661fa1ecc1e28c Mon Sep 17 00:00:00 2001 From: Leaf Garland Date: Tue, 14 Feb 2017 21:43:52 +1300 Subject: [PATCH 02/45] Replace indent script with javascript one The indent script from pangloss/vim-javascript should work fine for most of our requirements. fix #97, fix #101, fix #103, fix #105 --- indent/typescript.vim | 714 +++++++++++++++++------------------------- 1 file changed, 287 insertions(+), 427 deletions(-) diff --git a/indent/typescript.vim b/indent/typescript.vim index 824d47e..be4ed6d 100644 --- a/indent/typescript.vim +++ b/indent/typescript.vim @@ -1,501 +1,361 @@ " Vim indent file -" Language: Typescript -" Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org - -" 0. Initialization {{{1 -" ================= +" Language: Javascript +" Maintainer: Chris Paul ( https://github.com/bounceme ) +" URL: https://github.com/pangloss/vim-javascript +" Last Change: February 8, 2017 " Only load this indent file when no other was loaded. -if exists("b:did_indent") +if exists('b:did_indent') finish endif let b:did_indent = 1 -setlocal nosmartindent - " Now, set up our indentation expression and keys that trigger it. -setlocal indentexpr=GetTypescriptIndent() -setlocal formatexpr=Fixedgq(v:lnum,v:count) -setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e +setlocal indentexpr=GetJavascriptIndent() +setlocal autoindent nolisp nosmartindent +setlocal indentkeys+=0],0) + +let b:undo_indent = 'setlocal indentexpr< smartindent< autoindent< indentkeys<' " Only define the function once. -if exists("*GetTypescriptIndent") +if exists('*GetJavascriptIndent') finish endif let s:cpo_save = &cpo set cpo&vim -" 1. Variables {{{1 -" ============ +" Get shiftwidth value +if exists('*shiftwidth') + function s:sw() + return shiftwidth() + endfunction +else + function s:sw() + return &sw + endfunction +endif -let s:ts_keywords = '^\s*\(break\|case\|catch\|continue\|debugger\|default\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)' +" searchpair() wrapper +if has('reltime') + function s:GetPair(start,end,flags,skip,time,...) + return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 2000,0] + a:000),a:time) + endfunction +else + function s:GetPair(start,end,flags,skip,...) + return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 1000,get(a:000,1)])) + endfunction +endif " Regex of syntax group names that are or delimit string or are comments. -let s:syng_strcom = 'string\|regex\|comment\c' - -" Regex of syntax group names that are strings. -let s:syng_string = 'regex\c' - -" Regex of syntax group names that are strings or documentation. -let s:syng_multiline = 'comment\c' - -" Regex of syntax group names that are line comment. -let s:syng_linecom = 'linecomment\c' - +let s:syng_strcom = 'string\|comment\|regex\|special\|doc\|template\%(braces\)\@!' +let s:syng_str = 'string\|template\|special' +let s:syng_com = 'comment\|doc' " Expression used to check whether we should skip a match with searchpair(). -let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'" - -let s:line_term = '\s*\%(\%(\/\/\).*\)\=$' - -" Regex that defines continuation lines, not including (, {, or [. -let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@[^{;]*' . s:line_term - -" Regex that defines blocks. -let s:block_regex = '\%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term - -let s:var_stmt = '^\s*var' - -let s:comma_first = '^\s*,' -let s:comma_last = ',\s*$' +let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'" -let s:ternary = '^\s\+[?|:]' -let s:ternary_q = '^\s\+?' - -" 2. Auxiliary Functions {{{1 -" ====================== - -" Check if the character at lnum:col is inside a string, comment, or is ascii. -function s:IsInStringOrComment(lnum, col) - return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom +function s:skip_func() + if !s:free || search('\m`\|\${\|\*\/','nW',s:looksyn) + let s:free = !eval(s:skip_expr) + let s:looksyn = line('.') + return !s:free + endif + let s:looksyn = line('.') + return getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$' && + \ eval(s:skip_expr) endfunction -" Check if the character at lnum:col is inside a string. -function s:IsInString(lnum, col) - return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string +function s:alternatePair(stop) + let pos = getpos('.')[1:2] + while search('\m[][(){}]','bW',a:stop) + if !s:skip_func() + let idx = stridx('])}',s:looking_at()) + if idx + 1 + if s:GetPair(['\[','(','{'][idx], '])}'[idx],'bW','s:skip_func()',2000,a:stop) <= 0 + break + endif + else + return + endif + endif + endwhile + call call('cursor',pos) endfunction -" Check if the character at lnum:col is inside a multi-line comment. -function s:IsInMultilineComment(lnum, col) - return !s:IsLineComment(a:lnum, a:col) && synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline +function s:save_pos(f,...) + let l:pos = getpos('.')[1:2] + let ret = call(a:f,a:000) + call call('cursor',l:pos) + return ret endfunction -" Check if the character at lnum:col is a line comment. -function s:IsLineComment(lnum, col) - return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_linecom +function s:syn_at(l,c) + return synIDattr(synID(a:l,a:c,0),'name') endfunction -" Find line above 'lnum' that isn't empty, in a comment, or in a string. -function s:PrevNonBlankNonString(lnum) - let in_block = 0 - let lnum = prevnonblank(a:lnum) - while lnum > 0 - " Go in and out of blocks comments as necessary. - " If the line isn't empty (with opt. comment) or in a string, end search. - let line = getline(lnum) - if line =~ '/\*' - if in_block - let in_block = 0 - else - break - endif - elseif !in_block && line =~ '\*/' - let in_block = 1 - elseif !in_block && line !~ '^\s*\%(//\).*$' && !(s:IsInStringOrComment(lnum, 1) && s:IsInStringOrComment(lnum, strlen(line))) - break - endif - let lnum = prevnonblank(lnum - 1) - endwhile - return lnum +function s:looking_at() + return getline('.')[col('.')-1] endfunction -" Find line above 'lnum' that started the continuation 'lnum' may be part of. -function s:GetMSL(lnum, in_one_line_scope) - " Start on the line we're at and use its indent. - let msl = a:lnum - let lnum = s:PrevNonBlankNonString(a:lnum - 1) - while lnum > 0 - " If we have a continuation line, or we're in a string, use line as MSL. - " Otherwise, terminate search as we have found our MSL already. - let line = getline(lnum) - let col = match(line, s:msl_regex) + 1 - if (col > 0 && !s:IsInStringOrComment(lnum, col)) || s:IsInString(lnum, strlen(line)) - let msl = lnum - else - " Don't use lines that are part of a one line scope as msl unless the - " flag in_one_line_scope is set to 1 - " - if a:in_one_line_scope - break - end - let msl_one_line = s:Match(lnum, s:one_line_scope_regex) - if msl_one_line == 0 - break - endif - endif - let lnum = s:PrevNonBlankNonString(lnum - 1) - endwhile - return msl +function s:token() + return s:looking_at() =~ '\k' ? expand('') : s:looking_at() endfunction -function s:RemoveTrailingComments(content) - let single = '\/\/\(.*\)\s*$' - let multi = '\/\*\(.*\)\*\/\s*$' - return substitute(substitute(a:content, single, '', ''), multi, '', '') +function s:previous_token() + let l:n = line('.') + if (s:looking_at() !~ '\k' || search('\m\<','cbW')) && search('\m\S','bW') + if (getline('.')[col('.')-2:col('.')-1] == '*/' || line('.') != l:n && + \ getline('.') =~ '\%<'.col('.').'c\/\/') && s:syn_at(line('.'),col('.')) =~? s:syng_com + while search('\m\/\ze[/*]','cbW') + if !search('\m\S','bW') + break + elseif s:syn_at(line('.'),col('.')) !~? s:syng_com + return s:token() + endif + endwhile + else + return s:token() + endif + endif + return '' endfunction -" Find if the string is inside var statement (but not the first string) -function s:InMultiVarStatement(lnum) - let lnum = s:PrevNonBlankNonString(a:lnum - 1) - -" let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name') - - " loop through previous expressions to find a var statement - while lnum > 0 - let line = getline(lnum) - - " if the line is a ts keyword - if (line =~ s:ts_keywords) - " check if the line is a var stmt - " if the line has a comma first or comma last then we can assume that we - " are in a multiple var statement - if (line =~ s:var_stmt) - return lnum - endif - - " other ts keywords, not a var - return 0 - endif +function s:others(p) + return "((line2byte(line('.')) + col('.')) <= ".(line2byte(a:p[0]) + a:p[1]).") || ".s:skip_expr +endfunction - let lnum = s:PrevNonBlankNonString(lnum - 1) - endwhile +function s:tern_skip(p) + return s:GetPair('{','}','nbW',s:others(a:p),200,a:p[0]) > 0 +endfunction - " beginning of program, not a var - return 0 +function s:tern_col(p) + return s:GetPair('?',':\@ 0 endfunction -" Find line above with beginning of the var statement or returns 0 if it's not -" this statement -function s:GetVarIndent(lnum) - let lvar = s:InMultiVarStatement(a:lnum) - let prev_lnum = s:PrevNonBlankNonString(a:lnum - 1) - - if lvar - let line = s:RemoveTrailingComments(getline(prev_lnum)) - - " if the previous line doesn't end in a comma, return to regular indent - if (line !~ s:comma_last) - return indent(prev_lnum) - &sw - else - return indent(lvar) + &sw - endif +function s:label_col() + let pos = getpos('.')[1:2] + let [s:looksyn,s:free] = pos + call s:alternatePair(0) + if s:save_pos('s:IsBlock') + let poss = getpos('.')[1:2] + return call('cursor',pos) || !s:tern_col(poss) + elseif s:looking_at() == ':' + return !s:tern_col([0,0]) endif +endfunction - return -1 +" configurable regexes that define continuation lines, not including (, {, or [. +let s:opfirst = '^' . get(g:,'javascript_opfirst', + \ '\%([<>=,?^%|*/&]\|\([-.:+]\)\1\@!\|!=\|in\%(stanceof\)\=\>\)') +let s:continuation = get(g:,'javascript_continuation', + \ '\%([-+<>=,.~!?/*^%|&:]\|\<\%(typeof\|delete\|void\|in\|instanceof\)\)') . '$' + +function s:continues(ln,con) + return !cursor(a:ln, match(' '.a:con,s:continuation)) && + \ eval( (['s:syn_at(line("."),col(".")) !~? "regex"'] + + \ repeat(['getline(".")[col(".")-2] != tr(s:looking_at(),">","=")'],3) + + \ repeat(['s:previous_token() != "."'],5) + [1])[ + \ index(split('/ > - + typeof in instanceof void delete'),s:token())]) endfunction +" get the line of code stripped of comments and move cursor to the last +" non-comment char. +function s:Trim(ln) + call cursor(a:ln+1,1) + call s:previous_token() + return strpart(getline('.'),0,col('.')) +endfunction -" Check if line 'lnum' has more opening brackets than closing ones. -function s:LineHasOpeningBrackets(lnum) - let open_0 = 0 - let open_2 = 0 - let open_4 = 0 - let line = getline(a:lnum) - let pos = match(line, '[][(){}]', 0) - while pos != -1 - if !s:IsInStringOrComment(a:lnum, pos + 1) - let idx = stridx('(){}[]', line[pos]) - if idx % 2 == 0 - let open_{idx} = open_{idx} + 1 - else - let open_{idx - 1} = open_{idx - 1} - 1 - endif - endif - let pos = match(line, '[][(){}]', pos + 1) +" Find line above 'lnum' that isn't empty or in a comment +function s:PrevCodeLine(lnum) + let l:n = prevnonblank(a:lnum) + while l:n + if getline(l:n) =~ '^\s*\/[/*]' + if (stridx(getline(l:n),'`') > 0 || getline(l:n-1)[-1:] == '\') && + \ s:syn_at(l:n,1) =~? s:syng_str + return l:n + endif + let l:n = prevnonblank(l:n-1) + elseif getline(l:n) =~ '\([/*]\)\1\@![/*]' && s:syn_at(l:n,1) =~? s:syng_com + let l:n = s:save_pos('eval', + \ 'cursor('.l:n.',1) + search(''\m\/\*'',"bW")') + else + return l:n + endif endwhile - return (open_0 > 0) . (open_2 > 0) . (open_4 > 0) endfunction -function s:Match(lnum, regex) - let col = match(getline(a:lnum), a:regex) + 1 - return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0 +" Check if line 'lnum' has a balanced amount of parentheses. +function s:Balanced(lnum) + let l:open = 0 + let l:line = getline(a:lnum) + let pos = match(l:line, '[][(){}]', 0) + while pos != -1 + if s:syn_at(a:lnum,pos + 1) !~? s:syng_strcom + let l:open += match(' ' . l:line[pos],'[[({]') + if l:open < 0 + return + endif + endif + let pos = match(l:line, '[][(){}]', pos + 1) + endwhile + return !l:open endfunction -function s:IndentWithContinuation(lnum, ind, width) - " Set up variables to use and search for MSL to the previous line. - let p_lnum = a:lnum - let lnum = s:GetMSL(a:lnum, 1) - let line = getline(lnum) - - " If the previous line wasn't a MSL and is continuation return its indent. - " TODO: the || s:IsInString() thing worries me a bit. - if p_lnum != lnum - if s:Match(p_lnum,s:continuation_regex)||s:IsInString(p_lnum,strlen(line)) - return a:ind - endif - endif - - " Set up more variables now that we know we aren't continuation bound. - let msl_ind = indent(lnum) - - " If the previous line ended with [*+/.-=], start a continuation that - " indents an extra level. - if s:Match(lnum, s:continuation_regex) - if lnum == p_lnum - return msl_ind + a:width - else - return msl_ind - endif +function s:OneScope(lnum) + let pline = s:Trim(a:lnum) + let kw = 'else do' + if pline[-1:] == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 + call s:previous_token() + let kw = 'for if let while with' + if index(split('await each'),s:token()) + 1 + call s:previous_token() + let kw = 'for' + endif endif - - return a:ind + return pline[-2:] == '=>' || index(split(kw),s:token()) + 1 && + \ s:save_pos('s:previous_token') != '.' endfunction -function s:InOneLineScope(lnum) - let msl = s:GetMSL(a:lnum, 1) - if msl > 0 && s:Match(msl, s:one_line_scope_regex) - return msl - endif - return 0 +" returns braceless levels started by 'i' and above lines * &sw. 'num' is the +" lineNr which encloses the entire context, 'cont' if whether line 'i' + 1 is +" a continued expression, which could have started in a braceless context +function s:iscontOne(i,num,cont) + let [l:i, l:num, bL] = [a:i, a:num + !a:num, 0] + let pind = a:num ? indent(l:num) + s:W : 0 + let ind = indent(l:i) + (a:cont ? 0 : s:W) + while l:i >= l:num && (ind > pind || l:i == l:num) + if indent(l:i) < ind && s:OneScope(l:i) + let bL += s:W + let l:i = line('.') + elseif !a:cont || bL || ind < indent(a:i) + break + endif + let ind = min([ind, indent(l:i)]) + let l:i = s:PrevCodeLine(l:i - 1) + endwhile + return bL endfunction -function s:ExitingOneLineScope(lnum) - let msl = s:GetMSL(a:lnum, 1) - if msl > 0 - " if the current line is in a one line scope .. - if s:Match(msl, s:one_line_scope_regex) - return 0 - else - let prev_msl = s:GetMSL(msl - 1, 1) - if s:Match(prev_msl, s:one_line_scope_regex) - return prev_msl - endif - endif +" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader +function s:IsBlock() + if s:looking_at() == '{' + let l:n = line('.') + let char = s:previous_token() + if match(s:stack,'xml\|jsx') + 1 && s:syn_at(line('.'),col('.')-1) =~? 'xml\|jsx' + return char != '{' + elseif char =~ '\k' + return index(split('return const let import export yield default delete var await void typeof throw case new in instanceof') + \ ,char) < (line('.') != l:n) || s:previous_token() == '.' + elseif char == '>' + return getline('.')[col('.')-2] == '=' || s:syn_at(line('.'),col('.')) =~? '^jsflow' + elseif char == ':' + return getline('.')[col('.')-2] != ':' && s:label_col() + elseif char == '/' + return s:syn_at(line('.'),col('.')) =~? 'regex' + endif + return char !~ '[=~!<*,?^%|&([]' && + \ (char !~ '[-+]' || l:n != line('.') && getline('.')[col('.')-2] == char) endif - return 0 endfunction -" 3. GetTypescriptIndent Function {{{1 -" ========================= - -function GetTypescriptIndent() - " 3.1. Setup {{{2 - " ---------- - - " Set up variables for restoring position in file. Could use v:lnum here. - let vcol = col('.') - - " 3.2. Work on the current line {{{2 - " ----------------------------- - - let ind = -1 +function GetJavascriptIndent() + let b:js_cache = get(b:,'js_cache',[0,0,0]) " Get the current line. - let line = getline(v:lnum) - " previous nonblank line number - let prevline = prevnonblank(v:lnum - 1) - - " If we got a closing bracket on an empty line, find its match and indent - " according to it. For parentheses we indent to its column - 1, for the - " others we indent to the containing line's MSL's level. Return -1 if fail. - let col = matchend(line, '^\s*[],})]') - if col > 0 && !s:IsInStringOrComment(v:lnum, col) - call cursor(v:lnum, col) - - let lvar = s:InMultiVarStatement(v:lnum) - if lvar - let prevline_contents = s:RemoveTrailingComments(getline(prevline)) - - " check for comma first - if (line[col - 1] =~ ',') - " if the previous line ends in comma or semicolon don't indent - if (prevline_contents =~ '[;,]\s*$') - return indent(s:GetMSL(line('.'), 0)) - " get previous line indent, if it's comma first return prevline indent - elseif (prevline_contents =~ s:comma_first) - return indent(prevline) - " otherwise we indent 1 level - else - return indent(lvar) + &sw - endif - endif - endif - - - let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2) - if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0 - if line[col-1]==')' && col('.') != col('$') - 1 - let ind = virtcol('.')-1 - else - let ind = indent(s:GetMSL(line('.'), 0)) - endif - endif - return ind + call cursor(v:lnum,1) + let l:line = getline('.') + " use synstack as it validates syn state and works in an empty line + let s:stack = synstack(v:lnum,1) + let syns = synIDattr(get(s:stack,-1),'name') + + " start with strings,comments,etc. + if syns =~? s:syng_com + if l:line =~ '^\s*\*' + return cindent(v:lnum) + elseif l:line !~ '^\s*\/[/*]' + return -1 + endif + elseif syns =~? s:syng_str && l:line !~ '^[''"]' + if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1) + let b:js_cache[0] = v:lnum + endif + return -1 endif - - " If the line is comma first, dedent 1 level - if (getline(prevline) =~ s:comma_first) - return indent(prevline) - &sw + let l:lnum = s:PrevCodeLine(v:lnum - 1) + if !l:lnum + return endif - if (line =~ s:ternary) - if (getline(prevline) =~ s:ternary_q) - return indent(prevline) - else - return indent(prevline) + &sw - endif + let l:line = substitute(l:line,'^\s*','','') + if l:line[:1] == '/*' + let l:line = substitute(l:line,'^\%(\/\*.\{-}\*\/\s*\)*','','') endif - - " If we are in a multi-line comment, cindent does the right thing. - if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1) - return cindent(v:lnum) + if l:line =~ '^\/[/*]' + let l:line = '' endif - " Check for multiple var assignments -" let var_indent = s:GetVarIndent(v:lnum) -" if var_indent >= 0 -" return var_indent -" endif - - " 3.3. Work on the previous line. {{{2 - " ------------------------------- - - " If the line is empty and the previous nonblank line was a multi-line - " comment, use that comment's indent. Deduct one char to account for the - " space in ' */'. - if line =~ '^\s*$' && s:IsInMultilineComment(prevline, 1) - return indent(prevline) - 1 - endif - - " Find a non-blank, non-multi-line string line above the current line. - let lnum = s:PrevNonBlankNonString(v:lnum - 1) - - " If the line is empty and inside a string, use the previous line. - if line =~ '^\s*$' && lnum != prevline - return indent(prevnonblank(v:lnum)) - endif - - " At the start of the file use zero indent. - if lnum == 0 - return 0 - endif - - " Set up variables for current line. - let line = getline(lnum) - let ind = indent(lnum) - - " If the previous line ended with a block opening, add a level of indent. - if s:Match(lnum, s:block_regex) - return indent(s:GetMSL(lnum, 0)) + &sw + " the containing paren, bracket, or curly. Many hacks for performance + let idx = index([']',')','}'],l:line[0]) + if b:js_cache[0] >= l:lnum && b:js_cache[0] < v:lnum && + \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum)) + call call('cursor',b:js_cache[1:]) + else + let [s:looksyn, s:free, top] = [v:lnum - 1, 1, (!indent(l:lnum) && + \ s:syn_at(l:lnum,1) !~? s:syng_str) * l:lnum] + if idx + 1 + call s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:skip_func()',2000,top) + elseif getline(v:lnum) !~ '^\S' && syns =~? 'block' + call s:GetPair('{','}','bW','s:skip_func()',2000,top) + else + call s:alternatePair(top) + endif endif - " If the previous line contained an opening bracket, and we are still in it, - " add indent depending on the bracket type. - if line =~ '[[({]' - let counts = s:LineHasOpeningBrackets(lnum) - if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0 - if col('.') + 1 == col('$') - return ind + &sw - else - return virtcol('.') - endif - elseif counts[1] == '1' || counts[2] == '1' - return ind + &sw - else - call cursor(v:lnum, vcol) - end + let b:js_cache = [v:lnum] + (line('.') == v:lnum ? [0,0] : getpos('.')[1:2]) + let num = b:js_cache[1] + + let [s:W, isOp, bL, switch_offset] = [s:sw(),0,0,0] + if !num || s:IsBlock() + let ilnum = line('.') + let pline = s:save_pos('s:Trim',l:lnum) + if num && s:looking_at() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0 + let num = ilnum == num ? line('.') : num + if idx < 0 && s:previous_token() ==# 'switch' && s:previous_token() != '.' + if &cino !~ ':' + let switch_offset = s:W + else + let cinc = matchlist(&cino,'.*:\zs\(-\)\=\(\d*\)\(\.\d\+\)\=\(s\)\=\C') + let switch_offset = max([cinc[0] is '' ? 0 : (cinc[1].1) * + \ ((strlen(cinc[2].cinc[3]) ? str2nr(cinc[2].str2nr(cinc[3][1])) : 10) * + \ (cinc[4] is '' ? 1 : s:W)) / 10, -indent(num)]) + endif + if pline[-1:] != '.' && l:line =~# '^\%(default\|case\)\>' + return indent(num) + switch_offset + endif + endif + endif + if idx < 0 && pline !~ '[{;]$' + if pline =~# ':\@ 0 - let ind = ind + &sw - else - let ols = s:ExitingOneLineScope(lnum) - while ols > 0 && ind > 0 - let ind = ind - &sw - let ols = s:InOneLineScope(ols - 1) - endwhile + " main return + if idx + 1 || l:line[:1] == '|}' + return indent(num) + elseif num + return indent(num) + s:W + switch_offset + bL + isOp endif - - return ind + return bL + isOp endfunction -" }}}1 - 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 s:IsLineComment(a:lnum, l:first_char) || s: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\") - else - let l:count = l:count - 1 - endif - - " run gq on new lines - if l:count == 1 - call feedkeys("gqq") - endif - - return 0 -endfunction From a6cf874d282464895e39f318272dea70598262e8 Mon Sep 17 00:00:00 2001 From: Leaf Garland Date: Tue, 14 Feb 2017 21:45:49 +1300 Subject: [PATCH 03/45] Update indent file header --- indent/typescript.vim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/indent/typescript.vim b/indent/typescript.vim index be4ed6d..5ff49bf 100644 --- a/indent/typescript.vim +++ b/indent/typescript.vim @@ -1,8 +1,6 @@ " Vim indent file -" Language: Javascript -" Maintainer: Chris Paul ( https://github.com/bounceme ) -" URL: https://github.com/pangloss/vim-javascript -" Last Change: February 8, 2017 +" Language: Typescript +" Acknowledgement: Almost direct copy from https://github.com/pangloss/vim-javascript " Only load this indent file when no other was loaded. if exists('b:did_indent') From 8c13e2e72104abf79e98fde3c482b4c8ff791664 Mon Sep 17 00:00:00 2001 From: Leaf Garland Date: Tue, 14 Feb 2017 21:47:50 +1300 Subject: [PATCH 04/45] Replace global javascript names We don't want to clash with the javascript plugin, so change them to use typescript names. --- indent/typescript.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/indent/typescript.vim b/indent/typescript.vim index 5ff49bf..1047b16 100644 --- a/indent/typescript.vim +++ b/indent/typescript.vim @@ -9,14 +9,14 @@ endif let b:did_indent = 1 " Now, set up our indentation expression and keys that trigger it. -setlocal indentexpr=GetJavascriptIndent() +setlocal indentexpr=GetTypescriptIndent() setlocal autoindent nolisp nosmartindent setlocal indentkeys+=0],0) let b:undo_indent = 'setlocal indentexpr< smartindent< autoindent< indentkeys<' " Only define the function once. -if exists('*GetJavascriptIndent') +if exists('*GetTypescriptIndent') finish endif @@ -144,9 +144,9 @@ function s:label_col() endfunction " configurable regexes that define continuation lines, not including (, {, or [. -let s:opfirst = '^' . get(g:,'javascript_opfirst', +let s:opfirst = '^' . get(g:,'typescript_opfirst', \ '\%([<>=,?^%|*/&]\|\([-.:+]\)\1\@!\|!=\|in\%(stanceof\)\=\>\)') -let s:continuation = get(g:,'javascript_continuation', +let s:continuation = get(g:,'typescript_continuation', \ '\%([-+<>=,.~!?/*^%|&:]\|\<\%(typeof\|delete\|void\|in\|instanceof\)\)') . '$' function s:continues(ln,con) @@ -258,7 +258,7 @@ function s:IsBlock() endif endfunction -function GetJavascriptIndent() +function GetTypescriptIndent() let b:js_cache = get(b:,'js_cache',[0,0,0]) " Get the current line. call cursor(v:lnum,1) From 0e427185fad2cabe3d69e0d9a261395ce2c54434 Mon Sep 17 00:00:00 2001 From: Leaf Garland Date: Tue, 14 Feb 2017 22:10:26 +1300 Subject: [PATCH 05/45] Check `g:typescript_indent_disable` When loading the indent script, check to see if we should not bother. fix #104 --- indent/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/typescript.vim b/indent/typescript.vim index 1047b16..8137398 100644 --- a/indent/typescript.vim +++ b/indent/typescript.vim @@ -3,7 +3,7 @@ " Acknowledgement: Almost direct copy from https://github.com/pangloss/vim-javascript " Only load this indent file when no other was loaded. -if exists('b:did_indent') +if exists('b:did_indent') || get(g:, 'typescript_indent_disable', 0) finish endif let b:did_indent = 1 From d539ff45393a0f1231a91452550ce0f4c5812f2c Mon Sep 17 00:00:00 2001 From: Leaf Garland Date: Tue, 14 Feb 2017 22:11:17 +1300 Subject: [PATCH 06/45] Update readme to mention pangloss/vim-javascript The indent script is almost entirely their work. Also describe how to set indentkeys and disable indentation for .foo() lines. --- README.md | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bfb1e91..5e0ad65 100644 --- a/README.md +++ b/README.md @@ -38,15 +38,37 @@ automatically enabled anytime you edit a `.ts` file. Indenting --------- -This plugin includes a custom indenter (based on `indent/java.vim`), it works -pretty well but there are cases where it fails. If these bother you or want to -use other indent settings you can disable it by setting a flag in your +This plugin includes a custom indenter (based on [pangloss/vim-javascript's +indenter](https://github.com/pangloss/vim-javascript/blob/master/indent/javascript.vim)), +it works pretty well but there are cases where it fails. If these bother you or +want to use other indent settings you can disable it by setting a flag in your `.vimrc`: ```vim let g:typescript_indent_disable = 1 ``` +If you want the indenter to automatically indent chained method calls as you type. + +```typescript +something + .foo() + .bar(); +``` + +Then add something like `setlocal indentkeys+=0.` to your `.vimrc`, see `:help +'indentkeys'` in vim for more information. + +If you use the `=` operator to re-indent code it will always indent +chained method calls - this can be disabled by changing the regex the +indent script uses to identify indented lines. In this case removing '.' +from the regex means that it wont indent lines starting with '.'. Note, +this is not ideal as the regex may change making your setting out of date. + +```vim +let g:typescript_opfirst='\%([<>=,?^%|*/&]\|\([-:+]\)\1\@!\|!=\|in\%(stanceof\)\=\>\)' +``` + Compiler settings ----------------- From 38112cebf32ffc6cf9f442d9fed019168f07b578 Mon Sep 17 00:00:00 2001 From: albert Date: Tue, 7 Mar 2017 09:20:35 +0100 Subject: [PATCH 07/45] Add 'object' Typescript type --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 9d2386e..c2d0274 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -132,7 +132,7 @@ syntax keyword typescriptReserved constructor declare as interface module abstra syn match typescriptParameters "([a-zA-Z0-9_?.$][\w?.$]*)\s*:\s*([a-zA-Z0-9_?.$][\w?.$]*)" contained skipwhite "}}} " DOM2 Objects"{{{ - syntax keyword typescriptType DOMImplementation DocumentFragment Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction void any string boolean number symbol never + syntax keyword typescriptType DOMImplementation DocumentFragment Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction void any string boolean number symbol never object syntax keyword typescriptExceptions DOMException "}}} " DOM2 CONSTANT"{{{ From 236d433cd86b3f6fb4ba9311fb1abedce19c4db0 Mon Sep 17 00:00:00 2001 From: Kenneth Ballenegger Date: Tue, 14 Mar 2017 15:20:33 -0700 Subject: [PATCH 08/45] Remove *.tsx detection as discussion in issue #110 --- ftdetect/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftdetect/typescript.vim b/ftdetect/typescript.vim index 481aa47..eef435b 100644 --- a/ftdetect/typescript.vim +++ b/ftdetect/typescript.vim @@ -1 +1 @@ -autocmd BufNewFile,BufRead *.ts,*.tsx setlocal filetype=typescript +autocmd BufNewFile,BufRead *.ts setlocal filetype=typescript From a2db0cb5e7c7be873663365d9aa947d3d34eea15 Mon Sep 17 00:00:00 2001 From: Leaf Garland Date: Wed, 15 Mar 2017 15:00:24 +1300 Subject: [PATCH 09/45] Do not override previous filetype for *.tsx There are other plugins (like ianks/vim-tsx) that set their own filetype for *.tsx files and we don't want to override them. Using `setfiletype` does that by only setting the filetype if it has not already been set. For *.ts files we continue to use `set filetype` as that will overwrite the default for *.ts files. fix #110 close #111 --- ftdetect/typescript.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ftdetect/typescript.vim b/ftdetect/typescript.vim index eef435b..7c10206 100644 --- a/ftdetect/typescript.vim +++ b/ftdetect/typescript.vim @@ -1 +1,4 @@ -autocmd BufNewFile,BufRead *.ts setlocal filetype=typescript +" use `set filetype` to override default filetype=xml for *.ts files +autocmd BufNewFile,BufRead *.ts set filetype=typescript +" use `setfiletype` to not override any other plugins like ianks/vim-tsx +autocmd BufNewFile,BufRead *.tsx setfiletype typescript From 03142831c89ca9f0fa759927e1ef34d69d827418 Mon Sep 17 00:00:00 2001 From: Drew Neil Date: Wed, 20 Sep 2017 16:20:31 +0100 Subject: [PATCH 10/45] Use CompilerSet to set the makeprg using local/global settings --- compiler/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/typescript.vim b/compiler/typescript.vim index 57506c5..260a42f 100644 --- a/compiler/typescript.vim +++ b/compiler/typescript.vim @@ -15,6 +15,6 @@ if exists(":CompilerSet") != 2 command! -nargs=* CompilerSet setlocal endif -let &l:makeprg = g:typescript_compiler_binary . ' ' . g:typescript_compiler_options . ' $* %' +execute 'CompilerSet makeprg=' . escape(g:typescript_compiler_binary, ' ') . '\ ' . escape(g:typescript_compiler_options, ' ') . escape(' $* %', ' ') CompilerSet errorformat=%+A\ %#%f\ %#(%l\\\,%c):\ %m,%C%m From dbe450d27118e4a9ebe590cfa0adf64a460e1e58 Mon Sep 17 00:00:00 2001 From: Drew Neil Date: Wed, 20 Sep 2017 16:28:00 +0100 Subject: [PATCH 11/45] Use line continuation to break up long line --- compiler/typescript.vim | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/typescript.vim b/compiler/typescript.vim index 260a42f..77121eb 100644 --- a/compiler/typescript.vim +++ b/compiler/typescript.vim @@ -15,6 +15,16 @@ if exists(":CompilerSet") != 2 command! -nargs=* CompilerSet setlocal endif -execute 'CompilerSet makeprg=' . escape(g:typescript_compiler_binary, ' ') . '\ ' . escape(g:typescript_compiler_options, ' ') . escape(' $* %', ' ') +let s:cpo_save = &cpo +set cpo-=C + +execute 'CompilerSet makeprg=' + \ . escape(g:typescript_compiler_binary, ' ') + \ . '\ ' + \ . escape(g:typescript_compiler_options, ' ') + \ . '\ $*\ %' CompilerSet errorformat=%+A\ %#%f\ %#(%l\\\,%c):\ %m,%C%m + +let &cpo = s:cpo_save +unlet s:cpo_save From f348d520ec72eebec07f05e7acabbbebb50836bd Mon Sep 17 00:00:00 2001 From: Srishan Bhattarai Date: Fri, 13 Oct 2017 08:39:02 +0545 Subject: [PATCH 12/45] Update typescript.vim --- ftplugin/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/typescript.vim b/ftplugin/typescript.vim index 83814d3..da4b1e8 100644 --- a/ftplugin/typescript.vim +++ b/ftplugin/typescript.vim @@ -13,7 +13,7 @@ setlocal commentstring=//\ %s " " and insert the comment leader when hitting or using "o". setlocal formatoptions-=t formatoptions+=croql -setlocal suffixesadd+=.ts +setlocal suffixesadd+=.ts,.tsx let b:undo_ftplugin = "setl fo< ofu< com< cms<" From 74760423c412ccf675bc3663d5a064a6333409d9 Mon Sep 17 00:00:00 2001 From: vagrant Date: Sun, 22 Oct 2017 19:23:47 +0000 Subject: [PATCH 13/45] Added Installation-Wiki Link Added a link in the _Installation_ section of the README, to the Installation Wiki page. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5e0ad65..ae78638 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ The simplest way to install is via a Vim add-in manager such as [Vundle](https://github.com/gmarik/vundle) or [Pathogen](https://github.com/tpope/vim-pathogen/). +_See the [Installation Wiki](https://github.com/leafgarland/typescript-vim/wiki/Installation)_ + ### Pathogen ``` From be2efbb8ea3516aa8a5ea340c400c2a38ab27902 Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 11 Jan 2018 11:52:02 +0900 Subject: [PATCH 14/45] Support numeric separator (i.e. 123_456) ECMAScript numeric separator proposal is now on stage3 https://github.com/tc39/proposal-numeric-separator and will come to TypeScript at version 2.7. https://github.com/Microsoft/TypeScript/pull/20324 Example: ```typescript const i = 123_456; const x = 0x1fa_EF6; const f = 123_456.0_456; const f2 = 123_456.4_5e1_2; ``` --- syntax/typescript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index c2d0274..ee9664f 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -65,14 +65,14 @@ syn region typescriptInterpolation matchgroup=typescriptInterpolationDelimiter \ start=/${/ end=/}/ contained \ contains=@typescriptExpression -syn match typescriptNumber "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>" +syn match typescriptNumber "-\=\<\d[0-9_]*L\=\>\|0[xX][0-9a-fA-F][0-9a-fA-F_]*\>" syn region typescriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline " syntax match typescriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\." " syntax region typescriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=typescriptSpecial,@htmlPreproc " syntax region typescriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=typescriptSpecial,@htmlPreproc " syntax region typescriptRegexpString start=+/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=typescriptSpecial,@htmlPreproc oneline " syntax match typescriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/ -syntax match typescriptFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/ +syntax match typescriptFloat /\<-\=\%(\d[0-9_]*\.\d[0-9_]*\|\d[0-9_]*\.\|\.\d[0-9]*\)\%([eE][+-]\=\d[0-9_]*\)\=\>/ " syntax match typescriptLabel /\(?\s*\)\@/ From ba0d89cb4d90f004ea47e087064f8ed3fd242619 Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 11 Jan 2018 15:13:48 +0900 Subject: [PATCH 15/45] add support for binary and octal literals --- syntax/typescript.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index ee9664f..0db04b8 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -65,7 +65,9 @@ syn region typescriptInterpolation matchgroup=typescriptInterpolationDelimiter \ start=/${/ end=/}/ contained \ contains=@typescriptExpression -syn match typescriptNumber "-\=\<\d[0-9_]*L\=\>\|0[xX][0-9a-fA-F][0-9a-fA-F_]*\>" +syn match typescriptNumber "-\=\<0[xX][0-9a-fA-F][0-9a-fA-F_]*\>" display +syn match typescriptNumber "-\=\<0[bB][01][01_]*\>" display +syn match typescriptNumber "-\=\<0[oO]\o[0-7_]*\>" display syn region typescriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline " syntax match typescriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\." " syntax region typescriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=typescriptSpecial,@htmlPreproc From af501dd1fc92b62cb524112cc6b52781f542f84d Mon Sep 17 00:00:00 2001 From: Alex Luecke Date: Sat, 13 Jan 2018 11:59:18 -0800 Subject: [PATCH 16/45] allow typed return values. Fixes #131. --- syntax/typescript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index c2d0274..fc35083 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -45,8 +45,8 @@ if !exists("typescript_ignore_typescriptdoc") "unlet b:current_syntax syntax region typescriptDocComment start="/\*\*\s*$" end="\*/" contains=typescriptDocTags,typescriptCommentTodo,typescriptCvsTag,@typescriptHtml,@Spell fold extend - syntax match typescriptDocTags contained "@\(param\|argument\|requires\|exception\|throws\|type\|class\|extends\|see\|link\|member\|module\|method\|title\|namespace\|optional\|default\|base\|file\)\>" nextgroup=typescriptDocParam,typescriptDocSeeTag skipwhite - syntax match typescriptDocTags contained "@\(beta\|deprecated\|description\|fileoverview\|author\|license\|version\|returns\=\|constructor\|private\|protected\|final\|ignore\|addon\|exec\)\>" + syntax match typescriptDocTags contained "@\(param\|argument\|requires\|exception\|throws\|type\|class\|extends\|see\|link\|member\|module\|method\|title\|namespace\|optional\|default\|base\|file\|returns\=\)\>" nextgroup=typescriptDocParam,typescriptDocSeeTag skipwhite + syntax match typescriptDocTags contained "@\(beta\|deprecated\|description\|fileoverview\|author\|license\|version\|constructor\|private\|protected\|final\|ignore\|addon\|exec\)\>" syntax match typescriptDocParam contained "\%(#\|\w\|\.\|:\|\/\)\+" syntax region typescriptDocSeeTag contained matchgroup=typescriptDocSeeTag start="{" end="}" contains=typescriptDocTags From 1c3cb0c048be7b6dec3d1a4a3fd231775dd65355 Mon Sep 17 00:00:00 2001 From: rhysd Date: Wed, 7 Mar 2018 11:06:48 +0900 Subject: [PATCH 17/45] fix integer literal --- syntax/typescript.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 98346e3..d2bb2d9 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -65,6 +65,7 @@ syn region typescriptInterpolation matchgroup=typescriptInterpolationDelimiter \ start=/${/ end=/}/ contained \ contains=@typescriptExpression +syn match typescriptNumber "-\=\<\d[0-9_]*L\=\>" display syn match typescriptNumber "-\=\<0[xX][0-9a-fA-F][0-9a-fA-F_]*\>" display syn match typescriptNumber "-\=\<0[bB][01][01_]*\>" display syn match typescriptNumber "-\=\<0[oO]\o[0-7_]*\>" display From f981a4106b9da049fac13974793215abfc520d57 Mon Sep 17 00:00:00 2001 From: Alvin Chan Date: Wed, 27 Jun 2018 11:25:18 -0700 Subject: [PATCH 18/45] Split StorageClass keywords from Identifiers --- syntax/typescript.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index d2bb2d9..701746e 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -106,7 +106,8 @@ syntax keyword typescriptEventListenerMethods contained scrollIntoView addEventL " }}} "" Programm Keywords"{{{ syntax keyword typescriptSource import export from as -syntax keyword typescriptIdentifier arguments this let var void const +syntax keyword typescriptIdentifier arguments this void +syntax keyword typescriptStorageClass let var const syntax keyword typescriptOperator delete new instanceof typeof syntax keyword typescriptBoolean true false syntax keyword typescriptNull null undefined @@ -185,7 +186,7 @@ syntax match typescriptDotNotation "\.style\." nextgroup=typescriptCssStyles "" Code blocks -syntax cluster typescriptAll contains=typescriptComment,typescriptLineComment,typescriptDocComment,typescriptStringD,typescriptStringS,typescriptStringB,typescriptRegexpString,typescriptNumber,typescriptFloat,typescriptDecorators,typescriptLabel,typescriptSource,typescriptType,typescriptOperator,typescriptBoolean,typescriptNull,typescriptFuncKeyword,typescriptConditional,typescriptGlobal,typescriptRepeat,typescriptBranch,typescriptStatement,typescriptGlobalObjects,typescriptMessage,typescriptIdentifier,typescriptExceptions,typescriptReserved,typescriptDeprecated,typescriptDomErrNo,typescriptDomNodeConsts,typescriptHtmlEvents,typescriptDotNotation,typescriptBrowserObjects,typescriptDOMObjects,typescriptAjaxObjects,typescriptPropietaryObjects,typescriptDOMMethods,typescriptHtmlElemProperties,typescriptDOMProperties,typescriptEventListenerKeywords,typescriptEventListenerMethods,typescriptAjaxProperties,typescriptAjaxMethods,typescriptFuncArg +syntax cluster typescriptAll contains=typescriptComment,typescriptLineComment,typescriptDocComment,typescriptStringD,typescriptStringS,typescriptStringB,typescriptRegexpString,typescriptNumber,typescriptFloat,typescriptDecorators,typescriptLabel,typescriptSource,typescriptType,typescriptOperator,typescriptBoolean,typescriptNull,typescriptFuncKeyword,typescriptConditional,typescriptGlobal,typescriptRepeat,typescriptBranch,typescriptStatement,typescriptGlobalObjects,typescriptMessage,typescriptIdentifier,typescriptStorageClass,typescriptExceptions,typescriptReserved,typescriptDeprecated,typescriptDomErrNo,typescriptDomNodeConsts,typescriptHtmlEvents,typescriptDotNotation,typescriptBrowserObjects,typescriptDOMObjects,typescriptAjaxObjects,typescriptPropietaryObjects,typescriptDOMMethods,typescriptHtmlElemProperties,typescriptDOMProperties,typescriptEventListenerKeywords,typescriptEventListenerMethods,typescriptAjaxProperties,typescriptAjaxMethods,typescriptFuncArg if main_syntax == "typescript" syntax sync clear @@ -261,6 +262,7 @@ if version >= 508 || !exists("did_typescript_syn_inits") HiLink typescriptConditional Conditional HiLink typescriptBranch Conditional HiLink typescriptIdentifier Identifier + HiLink typescriptStorageClass StorageClass HiLink typescriptRepeat Repeat HiLink typescriptStatement Statement HiLink typescriptFuncKeyword Function From 648629c4751441c61055df7f4fe4d94aa68a25e7 Mon Sep 17 00:00:00 2001 From: Masataka Pocke Kuwabara Date: Tue, 31 Jul 2018 19:57:48 +0900 Subject: [PATCH 19/45] Highlight unknown as typescriptType unknown type is added since TypeScript 3. https://blogs.msdn.microsoft.com/typescript/2018/07/30/announcing-typescript-3-0/#the-unknown-type --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index d2bb2d9..fa46414 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -135,7 +135,7 @@ syntax keyword typescriptReserved constructor declare as interface module abstra syn match typescriptParameters "([a-zA-Z0-9_?.$][\w?.$]*)\s*:\s*([a-zA-Z0-9_?.$][\w?.$]*)" contained skipwhite "}}} " DOM2 Objects"{{{ - syntax keyword typescriptType DOMImplementation DocumentFragment Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction void any string boolean number symbol never object + syntax keyword typescriptType DOMImplementation DocumentFragment Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction void any string boolean number symbol never object unknown syntax keyword typescriptExceptions DOMException "}}} " DOM2 CONSTANT"{{{ From 61a386b8c3e910d7b930bca0e7b07f93f3eedcd2 Mon Sep 17 00:00:00 2001 From: rhysd Date: Wed, 8 Aug 2018 12:13:42 +0900 Subject: [PATCH 20/45] Fix code points notation in string literals --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index d2bb2d9..06d5a1d 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -56,7 +56,7 @@ endif "" JSDoc end syntax case match "" Syntax in the typescript code"{{{ -syn match typescriptSpecial "\\\d\d\d\|\\." +syn match typescriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}" contained containedin=typescriptStringD,typescriptStringS,typescriptStringB display syn region typescriptStringD start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=typescriptSpecial,@htmlPreproc extend syn region typescriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=typescriptSpecial,@htmlPreproc extend syn region typescriptStringB start=+`+ skip=+\\\\\|\\`+ end=+`+ contains=typescriptInterpolation,typescriptSpecial,@htmlPreproc extend From f35c66b09f1feef883f86c0a5f2390de41f8e85e Mon Sep 17 00:00:00 2001 From: rhysd Date: Wed, 8 Aug 2018 12:30:11 +0900 Subject: [PATCH 21/45] add g:typescript_ignore_browserwords not to highlight browser things --- syntax/typescript.vim | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index d2bb2d9..a6e6703 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -85,24 +85,26 @@ syntax keyword typescriptPrototype contained prototype "}}} " DOM, Browser and Ajax Support {{{ """""""""""""""""""""""" -syntax keyword typescriptBrowserObjects window navigator screen history location - -syntax keyword typescriptDOMObjects document event HTMLElement Anchor Area Base Body Button Form Frame Frameset Image Link Meta Option Select Style Table TableCell TableRow Textarea -syntax keyword typescriptDOMMethods contained createTextNode createElement insertBefore replaceChild removeChild appendChild hasChildNodes cloneNode normalize isSupported hasAttributes getAttribute setAttribute removeAttribute getAttributeNode setAttributeNode removeAttributeNode getElementsByTagName hasAttribute getElementById adoptNode close compareDocumentPosition createAttribute createCDATASection createComment createDocumentFragment createElementNS createEvent createExpression createNSResolver createProcessingInstruction createRange createTreeWalker elementFromPoint evaluate getBoxObjectFor getElementsByClassName getSelection getUserData hasFocus importNode -syntax keyword typescriptDOMProperties contained nodeName nodeValue nodeType parentNode childNodes firstChild lastChild previousSibling nextSibling attributes ownerDocument namespaceURI prefix localName tagName - -syntax keyword typescriptAjaxObjects XMLHttpRequest -syntax keyword typescriptAjaxProperties contained readyState responseText responseXML statusText -syntax keyword typescriptAjaxMethods contained onreadystatechange abort getAllResponseHeaders getResponseHeader open send setRequestHeader - -syntax keyword typescriptPropietaryObjects ActiveXObject -syntax keyword typescriptPropietaryMethods contained attachEvent detachEvent cancelBubble returnValue - -syntax keyword typescriptHtmlElemProperties contained className clientHeight clientLeft clientTop clientWidth dir href id innerHTML lang length offsetHeight offsetLeft offsetParent offsetTop offsetWidth scrollHeight scrollLeft scrollTop scrollWidth style tabIndex target title - -syntax keyword typescriptEventListenerKeywords contained blur click focus mouseover mouseout load item - -syntax keyword typescriptEventListenerMethods contained scrollIntoView addEventListener dispatchEvent removeEventListener preventDefault stopPropagation +if get(g:, 'typescript_ignore_browserwords', 0) + syntax keyword typescriptBrowserObjects window navigator screen history location + + syntax keyword typescriptDOMObjects document event HTMLElement Anchor Area Base Body Button Form Frame Frameset Image Link Meta Option Select Style Table TableCell TableRow Textarea + syntax keyword typescriptDOMMethods contained createTextNode createElement insertBefore replaceChild removeChild appendChild hasChildNodes cloneNode normalize isSupported hasAttributes getAttribute setAttribute removeAttribute getAttributeNode setAttributeNode removeAttributeNode getElementsByTagName hasAttribute getElementById adoptNode close compareDocumentPosition createAttribute createCDATASection createComment createDocumentFragment createElementNS createEvent createExpression createNSResolver createProcessingInstruction createRange createTreeWalker elementFromPoint evaluate getBoxObjectFor getElementsByClassName getSelection getUserData hasFocus importNode + syntax keyword typescriptDOMProperties contained nodeName nodeValue nodeType parentNode childNodes firstChild lastChild previousSibling nextSibling attributes ownerDocument namespaceURI prefix localName tagName + + syntax keyword typescriptAjaxObjects XMLHttpRequest + syntax keyword typescriptAjaxProperties contained readyState responseText responseXML statusText + syntax keyword typescriptAjaxMethods contained onreadystatechange abort getAllResponseHeaders getResponseHeader open send setRequestHeader + + syntax keyword typescriptPropietaryObjects ActiveXObject + syntax keyword typescriptPropietaryMethods contained attachEvent detachEvent cancelBubble returnValue + + syntax keyword typescriptHtmlElemProperties contained className clientHeight clientLeft clientTop clientWidth dir href id innerHTML lang length offsetHeight offsetLeft offsetParent offsetTop offsetWidth scrollHeight scrollLeft scrollTop scrollWidth style tabIndex target title + + syntax keyword typescriptEventListenerKeywords contained blur click focus mouseover mouseout load item + + syntax keyword typescriptEventListenerMethods contained scrollIntoView addEventListener dispatchEvent removeEventListener preventDefault stopPropagation +endif " }}} "" Programm Keywords"{{{ syntax keyword typescriptSource import export from as From aaf0d3ef1e0ac250d9d3ec415d91b292d9145fb0 Mon Sep 17 00:00:00 2001 From: rhysd Date: Wed, 15 Aug 2018 11:58:43 +0900 Subject: [PATCH 22/45] add a section about customizing syntax highlighting --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index ae78638..60d6150 100644 --- a/README.md +++ b/README.md @@ -109,4 +109,14 @@ autocmd QuickFixCmdPost [^l]* nested cwindow autocmd QuickFixCmdPost l* nested lwindow ``` +Syntax highlighting +------------------- + +Syntax highlighting for TypeScript can be customized by following variables. + +- `g:typescript_ignore_typescriptdoc`: When this variable is defined, doccomments will not be + highlighted. +- `g:typescript_ignore_browserwords`: When this variable is set to `1`, browser API names such as + `window` or `document` will not be highlighted. (default to `0`) + ![Obligatory screenshot](https://raw.github.com/leafgarland/typescript-vim/master/vimshot01.png) From 09091e88772480e4987c9d0a4305180b3d9e9bd8 Mon Sep 17 00:00:00 2001 From: dt-rush Date: Mon, 15 Oct 2018 18:37:17 -0400 Subject: [PATCH 23/45] added a small example of compiler options specification --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 60d6150..4f02a99 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,10 @@ let g:typescript_compiler_binary = 'tsc' let g:typescript_compiler_options = '' ``` +These options will be passed to the binary as command arguments. For example, +if `g:typescript_compiler_binary = 'tsc'` and `g:typescript_compiler_options = '--lib es6'`, +`l:makeprg` will be: `tsc --lib es6 $* %`. + You can completely override this plugin's compiler settings with something like this in your `.vimrc`, where you can set makeprg to whatever you want. From 2db69f94621a0acf9284fc239bc3fc58c073b5dc Mon Sep 17 00:00:00 2001 From: April Arcus <2045543+AprilArcus@users.noreply.github.com> Date: Mon, 8 Apr 2019 12:14:59 -0700 Subject: [PATCH 24/45] Fix Typo: gackgroundPosition -> backgroundPosition --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 8d9604e..d10acbb 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -172,7 +172,7 @@ if exists("typescript_enable_domhtmlcss") syntax keyword typescriptCssStyles contained border borderBottom borderLeft borderRight borderTop borderBottomColor borderLeftColor borderTopColor borderBottomStyle borderLeftStyle borderRightStyle borderTopStyle borderBottomWidth borderLeftWidth borderRightWidth borderTopWidth borderColor borderStyle borderWidth borderCollapse borderSpacing captionSide emptyCells tableLayout syntax keyword typescriptCssStyles contained margin marginBottom marginLeft marginRight marginTop outline outlineColor outlineStyle outlineWidth padding paddingBottom paddingLeft paddingRight paddingTop syntax keyword typescriptCssStyles contained listStyle listStyleImage listStylePosition listStyleType - syntax keyword typescriptCssStyles contained background backgroundAttachment backgroundColor backgroundImage gackgroundPosition backgroundPositionX backgroundPositionY backgroundRepeat + syntax keyword typescriptCssStyles contained background backgroundAttachment backgroundColor backgroundImage backgroundPosition backgroundPositionX backgroundPositionY backgroundRepeat syntax keyword typescriptCssStyles contained clear clip clipBottom clipLeft clipRight clipTop content counterIncrement counterReset cssFloat cursor direction display filter layoutGrid layoutGridChar layoutGridLine layoutGridMode layoutGridType syntax keyword typescriptCssStyles contained marks maxHeight maxWidth minHeight minWidth opacity MozOpacity overflow overflowX overflowY verticalAlign visibility zoom cssText syntax keyword typescriptCssStyles contained scrollbar3dLightColor scrollbarArrowColor scrollbarBaseColor scrollbarDarkShadowColor scrollbarFaceColor scrollbarHighlightColor scrollbarShadowColor scrollbarTrackColor From c91c4fc3076d8e8e6deff1fbe9fbadb8327072c0 Mon Sep 17 00:00:00 2001 From: louib Date: Thu, 2 May 2019 23:00:33 -0400 Subject: [PATCH 25/45] Adding ! as logical operator It was missing from the `typescriptLogicSymbols` class, where I think it belongs. --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index d10acbb..369a2bb 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -206,7 +206,7 @@ syn match typescriptBraces "[{}\[\]]" syn match typescriptParens "[()]" syn match typescriptOpSymbols "=\{1,3}\|!==\|!=\|<\|>\|>=\|<=\|++\|+=\|--\|-=" syn match typescriptEndColons "[;,]" -syn match typescriptLogicSymbols "\(&&\)\|\(||\)" +syn match typescriptLogicSymbols "\(&&\)\|\(||\)\|\(!\)" " typescriptFold Function {{{ From 4eabcd56b276ba6f78fca2e5e6e60565a14ffbe3 Mon Sep 17 00:00:00 2001 From: louib Date: Thu, 2 May 2019 23:04:15 -0400 Subject: [PATCH 26/45] Adding JSON as global object. --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index d10acbb..7cc8da3 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -124,7 +124,7 @@ syntax keyword typescriptBranch break continue yield await syntax keyword typescriptLabel case default async readonly syntax keyword typescriptStatement return with -syntax keyword typescriptGlobalObjects Array Boolean Date Function Infinity Math Number NaN Object Packages RegExp String Symbol netscape +syntax keyword typescriptGlobalObjects Array Boolean Date Function Infinity JSON Math Number NaN Object Packages RegExp String Symbol netscape syntax keyword typescriptExceptions try catch throw finally Error EvalError RangeError ReferenceError SyntaxError TypeError URIError From 1516ae4e24f86819380306870bbe21bc6ec8adc1 Mon Sep 17 00:00:00 2001 From: Geoffrey Date: Thu, 20 Jun 2019 17:35:28 +1200 Subject: [PATCH 27/45] Add installation method for recent versions of Vim. --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f02a99..fdce308 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,12 @@ and other features for TypeScript editing. Install ------- -The simplest way to install is via a Vim add-in manager such as +From Vim 8 onward, the plugin can be installed as simply as: +``` +git clone https://github.com/leafgarland/typescript-vim.git ~/.vim/pack/typescript/start/typescript-vim +``` + +For older versions of Vim, the simplest way to install is via a Vim add-in manager such as [Plug](https://github.com/junegunn/vim-plug), [Vundle](https://github.com/gmarik/vundle) or [Pathogen](https://github.com/tpope/vim-pathogen/). From 83ad139d0989565e899af31d17fb57b4458d719f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20Nordstr=C3=B6m?= Date: Thu, 28 Nov 2019 11:46:10 +0100 Subject: [PATCH 28/45] Add support for new typescriptreact filetype --- compiler/typescriptreact.vim | 1 + ftplugin/typescriptreact.vim | 1 + indent/typescriptreact.vim | 1 + syntax/typescriptreact.vim | 1 + 4 files changed, 4 insertions(+) create mode 100644 compiler/typescriptreact.vim create mode 100644 ftplugin/typescriptreact.vim create mode 100644 indent/typescriptreact.vim create mode 100644 syntax/typescriptreact.vim diff --git a/compiler/typescriptreact.vim b/compiler/typescriptreact.vim new file mode 100644 index 0000000..0f73409 --- /dev/null +++ b/compiler/typescriptreact.vim @@ -0,0 +1 @@ +runtime! compiler/typescript.vim diff --git a/ftplugin/typescriptreact.vim b/ftplugin/typescriptreact.vim new file mode 100644 index 0000000..c23ec13 --- /dev/null +++ b/ftplugin/typescriptreact.vim @@ -0,0 +1 @@ +runtime! ftplugin/typescript.vim diff --git a/indent/typescriptreact.vim b/indent/typescriptreact.vim new file mode 100644 index 0000000..36f89ae --- /dev/null +++ b/indent/typescriptreact.vim @@ -0,0 +1 @@ +runtime! indent/typescript.vim diff --git a/syntax/typescriptreact.vim b/syntax/typescriptreact.vim new file mode 100644 index 0000000..8fc4480 --- /dev/null +++ b/syntax/typescriptreact.vim @@ -0,0 +1 @@ +runtime! syntax/typescript.vim From 09cf6a6ecdef11cd32d38213093cfe86660255aa Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 4 Dec 2019 12:57:22 +0000 Subject: [PATCH 29/45] Updated installation instructions to working command line for Powershell --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fdce308..c487381 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,16 @@ and other features for TypeScript editing. Install ------- -From Vim 8 onward, the plugin can be installed as simply as: +From Vim 8 onward, the plugin can be installed as simply as (Unix/Mac): ``` git clone https://github.com/leafgarland/typescript-vim.git ~/.vim/pack/typescript/start/typescript-vim ``` +On Windows/Powershell, use the following: +``` +git clone https://github.com/leafgarland/typescript-vim.git $home/vimfiles/pack/typescript/start/typescript-vim +``` + For older versions of Vim, the simplest way to install is via a Vim add-in manager such as [Plug](https://github.com/junegunn/vim-plug), [Vundle](https://github.com/gmarik/vundle) or From efc0c33f9130c80452d80dca718dacea5987eab5 Mon Sep 17 00:00:00 2001 From: Jon Smithers Date: Sun, 15 Dec 2019 14:05:33 -0500 Subject: [PATCH 30/45] Make sure to overwrite vim's built-in syntax highlighting --- syntax/typescript.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 09f2ef6..908d24a 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -223,10 +223,11 @@ syn region foldBraces start=/{/ skip=/\(\/\/.*\)\|\(\/.*\/\)/ end=/}/ transparen " }}} " Define the default highlighting. -" For version 5.7 and earlier: only when not done already +" For version 5.7 and earlier: only when not done already by this script " For version 5.8 and later: only when an item doesn't have highlighting yet +" For version 8.1.1486 and later: only when not done already by this script (need to override vim's new typescript support) if version >= 508 || !exists("did_typescript_syn_inits") - if version < 508 + if version < 508 || has('patch-8.1.1486') let did_typescript_syn_inits = 1 command -nargs=+ HiLink hi link else From 323232d2d3438a340a8a2f458e1740f769114dcc Mon Sep 17 00:00:00 2001 From: Sam Roeca Date: Wed, 18 Dec 2019 22:39:58 -0500 Subject: [PATCH 31/45] Remove trailing whitespace --- syntax/typescript.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 09f2ef6..6158147 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -87,22 +87,22 @@ syntax keyword typescriptPrototype contained prototype """""""""""""""""""""""" if get(g:, 'typescript_ignore_browserwords', 0) syntax keyword typescriptBrowserObjects window navigator screen history location - + syntax keyword typescriptDOMObjects document event HTMLElement Anchor Area Base Body Button Form Frame Frameset Image Link Meta Option Select Style Table TableCell TableRow Textarea syntax keyword typescriptDOMMethods contained createTextNode createElement insertBefore replaceChild removeChild appendChild hasChildNodes cloneNode normalize isSupported hasAttributes getAttribute setAttribute removeAttribute getAttributeNode setAttributeNode removeAttributeNode getElementsByTagName hasAttribute getElementById adoptNode close compareDocumentPosition createAttribute createCDATASection createComment createDocumentFragment createElementNS createEvent createExpression createNSResolver createProcessingInstruction createRange createTreeWalker elementFromPoint evaluate getBoxObjectFor getElementsByClassName getSelection getUserData hasFocus importNode syntax keyword typescriptDOMProperties contained nodeName nodeValue nodeType parentNode childNodes firstChild lastChild previousSibling nextSibling attributes ownerDocument namespaceURI prefix localName tagName - + syntax keyword typescriptAjaxObjects XMLHttpRequest syntax keyword typescriptAjaxProperties contained readyState responseText responseXML statusText syntax keyword typescriptAjaxMethods contained onreadystatechange abort getAllResponseHeaders getResponseHeader open send setRequestHeader - + syntax keyword typescriptPropietaryObjects ActiveXObject syntax keyword typescriptPropietaryMethods contained attachEvent detachEvent cancelBubble returnValue - + syntax keyword typescriptHtmlElemProperties contained className clientHeight clientLeft clientTop clientWidth dir href id innerHTML lang length offsetHeight offsetLeft offsetParent offsetTop offsetWidth scrollHeight scrollLeft scrollTop scrollWidth style tabIndex target title - + syntax keyword typescriptEventListenerKeywords contained blur click focus mouseover mouseout load item - + syntax keyword typescriptEventListenerMethods contained scrollIntoView addEventListener dispatchEvent removeEventListener preventDefault stopPropagation endif " }}} From 3d9b0e577587eefcbd4214dd86f98655e0b7f601 Mon Sep 17 00:00:00 2001 From: Sam Roeca Date: Wed, 18 Dec 2019 22:40:16 -0500 Subject: [PATCH 32/45] typesciptFuncKeyword is Keyword, not Function See ":help group-name" in Vim's help menu. Function: function name (also: methods for classes) Keyword: any other keyword --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 6158147..705016d 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -267,7 +267,7 @@ if version >= 508 || !exists("did_typescript_syn_inits") HiLink typescriptStorageClass StorageClass HiLink typescriptRepeat Repeat HiLink typescriptStatement Statement - HiLink typescriptFuncKeyword Function + HiLink typescriptFuncKeyword Keyword HiLink typescriptMessage Keyword HiLink typescriptDeprecated Exception HiLink typescriptError Error From 857d6ddd006a788dc24d906858bd4e4c9e7645c7 Mon Sep 17 00:00:00 2001 From: Sam Roeca Date: Sun, 26 Jan 2020 18:34:33 -0500 Subject: [PATCH 33/45] Add closing '>' to containing groups Now paired '<>' close like (), {}, and []. Eg: ```typescript const myFunction = < GenericA, GenericB, GenericC >(a: GenericA, b: GenericB, c:GenericC): GenericA => { return a } ``` --- indent/typescript.vim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/indent/typescript.vim b/indent/typescript.vim index 8137398..3ee9aa0 100644 --- a/indent/typescript.vim +++ b/indent/typescript.vim @@ -169,7 +169,7 @@ endfunction function s:PrevCodeLine(lnum) let l:n = prevnonblank(a:lnum) while l:n - if getline(l:n) =~ '^\s*\/[/*]' + if getline(l:n) =~ '^\s*\/[/*]' if (stridx(getline(l:n),'`') > 0 || getline(l:n-1)[-1:] == '\') && \ s:syn_at(l:n,1) =~? s:syng_str return l:n @@ -293,8 +293,9 @@ function GetTypescriptIndent() let l:line = '' endif - " the containing paren, bracket, or curly. Many hacks for performance - let idx = index([']',')','}'],l:line[0]) + " the containing paren, bracket, curly, or closing '>'. + " Many hacks for performance + let idx = index([']',')','}','>'],l:line[0]) if b:js_cache[0] >= l:lnum && b:js_cache[0] < v:lnum && \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum)) call call('cursor',b:js_cache[1:]) From 1557953395ba2a89c3b5f21f794da7e3ae7c520d Mon Sep 17 00:00:00 2001 From: z0rzi Date: Wed, 4 Mar 2020 12:00:32 +0100 Subject: [PATCH 34/45] exclamation character wrong group The exclamation character is considered as a `typescriptLogicSymbols` when in a `!==`, which breaks some fonts due to the color change. With this line exchange, the exclamation is interpreted as it should be (`typescriptOpSymbols`) --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 8c6ecf2..45a5cd5 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -204,9 +204,9 @@ syntax keyword typescriptFuncKeyword function syn match typescriptBraces "[{}\[\]]" syn match typescriptParens "[()]" -syn match typescriptOpSymbols "=\{1,3}\|!==\|!=\|<\|>\|>=\|<=\|++\|+=\|--\|-=" syn match typescriptEndColons "[;,]" syn match typescriptLogicSymbols "\(&&\)\|\(||\)\|\(!\)" +syn match typescriptOpSymbols "=\{1,3}\|!==\|!=\|<\|>\|>=\|<=\|++\|+=\|--\|-=" " typescriptFold Function {{{ From bf5bddd9be5e867b6d9b73d1bfa5029124abd6e8 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Thu, 20 Aug 2020 09:47:53 -0700 Subject: [PATCH 35/45] fix: support all legal regex flags See https://tc39.es/ecma262/#sec-get-regexp.prototype.flags --- syntax/typescript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 8c6ecf2..cb9b935 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -69,11 +69,11 @@ syn match typescriptNumber "-\=\<\d[0-9_]*L\=\>" display syn match typescriptNumber "-\=\<0[xX][0-9a-fA-F][0-9a-fA-F_]*\>" display syn match typescriptNumber "-\=\<0[bB][01][01_]*\>" display syn match typescriptNumber "-\=\<0[oO]\o[0-7_]*\>" display -syn region typescriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline +syn region typescriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gimsuy]\{0,2\}\s*$+ end=+/[gimsuy]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline " syntax match typescriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\." " syntax region typescriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=typescriptSpecial,@htmlPreproc " syntax region typescriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=typescriptSpecial,@htmlPreproc -" syntax region typescriptRegexpString start=+/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=typescriptSpecial,@htmlPreproc oneline +" syntax region typescriptRegexpString start=+/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gimsuy]\{,3}+ contains=typescriptSpecial,@htmlPreproc oneline " syntax match typescriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/ syntax match typescriptFloat /\<-\=\%(\d[0-9_]*\.\d[0-9_]*\|\d[0-9_]*\.\|\.\d[0-9]*\)\%([eE][+-]\=\d[0-9_]*\)\=\>/ " syntax match typescriptLabel /\(?\s*\)\@ Date: Mon, 7 Sep 2020 19:14:21 +1000 Subject: [PATCH 36/45] Extend global objects with js and node keywords --- syntax/typescript.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 8c6ecf2..9616450 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -124,7 +124,8 @@ syntax keyword typescriptBranch break continue yield await syntax keyword typescriptLabel case default async readonly syntax keyword typescriptStatement return with -syntax keyword typescriptGlobalObjects Array Boolean Date Function Infinity JSON Math Number NaN Object Packages RegExp String Symbol netscape +syntax keyword typescriptGlobalObjects Array Boolean Date Function Infinity JSON Math Number NaN Object Packages RegExp String Symbol netscape ArrayBuffer BigInt64Array BigUint64Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray Buffer Collator DataView DateTimeFormat Intl Iterator Map Set WeakMap WeakSet NumberFormat ParallelArray Promise Proxy Reflect Uint8ClampedArray WebAssembly console document fetch window +syntax keyword typescriptGlobalNodeObjects module exports global process __dirname __filename syntax keyword typescriptExceptions try catch throw finally Error EvalError RangeError ReferenceError SyntaxError TypeError URIError @@ -188,7 +189,7 @@ syntax match typescriptDotNotation "\.style\." nextgroup=typescriptCssStyles "" Code blocks -syntax cluster typescriptAll contains=typescriptComment,typescriptLineComment,typescriptDocComment,typescriptStringD,typescriptStringS,typescriptStringB,typescriptRegexpString,typescriptNumber,typescriptFloat,typescriptDecorators,typescriptLabel,typescriptSource,typescriptType,typescriptOperator,typescriptBoolean,typescriptNull,typescriptFuncKeyword,typescriptConditional,typescriptGlobal,typescriptRepeat,typescriptBranch,typescriptStatement,typescriptGlobalObjects,typescriptMessage,typescriptIdentifier,typescriptStorageClass,typescriptExceptions,typescriptReserved,typescriptDeprecated,typescriptDomErrNo,typescriptDomNodeConsts,typescriptHtmlEvents,typescriptDotNotation,typescriptBrowserObjects,typescriptDOMObjects,typescriptAjaxObjects,typescriptPropietaryObjects,typescriptDOMMethods,typescriptHtmlElemProperties,typescriptDOMProperties,typescriptEventListenerKeywords,typescriptEventListenerMethods,typescriptAjaxProperties,typescriptAjaxMethods,typescriptFuncArg +syntax cluster typescriptAll contains=typescriptComment,typescriptLineComment,typescriptDocComment,typescriptStringD,typescriptStringS,typescriptStringB,typescriptRegexpString,typescriptNumber,typescriptFloat,typescriptDecorators,typescriptLabel,typescriptSource,typescriptType,typescriptOperator,typescriptBoolean,typescriptNull,typescriptFuncKeyword,typescriptConditional,typescriptGlobal,typescriptRepeat,typescriptBranch,typescriptStatement,typescriptGlobalObjects,typescriptMessage,typescriptIdentifier,typescriptStorageClass,typescriptExceptions,typescriptReserved,typescriptDeprecated,typescriptDomErrNo,typescriptDomNodeConsts,typescriptHtmlEvents,typescriptDotNotation,typescriptBrowserObjects,typescriptDOMObjects,typescriptAjaxObjects,typescriptPropietaryObjects,typescriptDOMMethods,typescriptHtmlElemProperties,typescriptDOMProperties,typescriptEventListenerKeywords,typescriptEventListenerMethods,typescriptAjaxProperties,typescriptAjaxMethods,typescriptFuncArg,typescriptGlobalNodeObjects if main_syntax == "typescript" syntax sync clear @@ -288,6 +289,7 @@ if version >= 508 || !exists("did_typescript_syn_inits") HiLink typescriptSpecial Special HiLink typescriptSource Special HiLink typescriptGlobalObjects Special + HiLink typescriptGlobalNodeObjects Special HiLink typescriptExceptions Special HiLink typescriptDomErrNo Constant From e0160e7cbba85be136d987fcf00476c7fc809927 Mon Sep 17 00:00:00 2001 From: SeungukLee Date: Mon, 9 Nov 2020 12:06:23 +0900 Subject: [PATCH 37/45] Fix wrong link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c487381..a880998 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Typescript Syntax for Vim Syntax file and other settings for [TypeScript](http://typescriptlang.org). The syntax file is taken from this [blog -post](http://blogs.msdn.com/b/interoperability/archive/2012/10/01/sublime-text-vi-emacs-typescript-enabled.aspx). +post](https://docs.microsoft.com/en-us/archive/blogs/interoperability/sublime-text-vi-emacs-typescript-enabled). Checkout [Tsuquyomi](https://github.com/Quramy/tsuquyomi) for omni-completion and other features for TypeScript editing. From ee61b9600e7aac7a72642caedc5948a5a20d8915 Mon Sep 17 00:00:00 2001 From: Andrei Bartashevich Date: Fri, 11 Dec 2020 17:18:21 +0300 Subject: [PATCH 38/45] Add nullish coalescing operator (??) --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 474e228..46498b5 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -206,7 +206,7 @@ syntax keyword typescriptFuncKeyword function syn match typescriptBraces "[{}\[\]]" syn match typescriptParens "[()]" syn match typescriptEndColons "[;,]" -syn match typescriptLogicSymbols "\(&&\)\|\(||\)\|\(!\)" +syn match typescriptLogicSymbols "\(&&\)\|\(||\)\|\(??\)\|\(!\)" syn match typescriptOpSymbols "=\{1,3}\|!==\|!=\|<\|>\|>=\|<=\|++\|+=\|--\|-=" " typescriptFold Function {{{ From e95a02029a4d0df42212ffec10a43c8f50ecc595 Mon Sep 17 00:00:00 2001 From: Ben Weedon Date: Sat, 5 Mar 2022 23:32:10 -0500 Subject: [PATCH 39/45] Override neovim 0.5.0 and up's typescript support This version of neovim has the same typescript support as vim 8 patch-8.1.1486, so we should override it as well. --- syntax/typescript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 474e228..328021c 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -226,9 +226,9 @@ syn region foldBraces start=/{/ skip=/\(\/\/.*\)\|\(\/.*\/\)/ end=/}/ transparen " Define the default highlighting. " For version 5.7 and earlier: only when not done already by this script " For version 5.8 and later: only when an item doesn't have highlighting yet -" For version 8.1.1486 and later: only when not done already by this script (need to override vim's new typescript support) +" For version 8.1.1486 and later, and nvim 0.5.0 and later: only when not done already by this script (need to override vim's new typescript support) if version >= 508 || !exists("did_typescript_syn_inits") - if version < 508 || has('patch-8.1.1486') + if version < 508 || has('patch-8.1.1486') || has('nvim-0.5.0') let did_typescript_syn_inits = 1 command -nargs=+ HiLink hi link else From d099d32a4bd6b56f792bba6aaa546ec4b520c26d Mon Sep 17 00:00:00 2001 From: Thomas Dy Date: Thu, 11 May 2023 12:01:29 +0900 Subject: [PATCH 40/45] Fix undo_ftplugin This should unset any options the plugin sets but we were also unsetting options we weren't setting here. --- ftplugin/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/typescript.vim b/ftplugin/typescript.vim index da4b1e8..8770454 100644 --- a/ftplugin/typescript.vim +++ b/ftplugin/typescript.vim @@ -15,7 +15,7 @@ setlocal formatoptions-=t formatoptions+=croql setlocal suffixesadd+=.ts,.tsx -let b:undo_ftplugin = "setl fo< ofu< com< cms<" +let b:undo_ftplugin = "setl cms< fo< sua<" let &cpo = s:cpo_save unlet s:cpo_save From 169f6783e786fa8f9ad82c8b97ca0dfe80286118 Mon Sep 17 00:00:00 2001 From: Greg Hurrell Date: Sat, 7 Oct 2023 14:56:48 +0200 Subject: [PATCH 41/45] fix: prefer default links except on ancient Vim versions Implements the suggestion posted in: https://github.com/leafgarland/typescript-vim/pull/193#issuecomment-1751705278 Which aligns the plugin with what other popular plugins that override bundled syntax files do. eg. - https://github.com/plasticboy/vim-markdown (uses `hi def link` on version 508 and above) - https://github.com/tpope/vim-markdown (uses `hi def link` unconditionally) This stops highlighting from getting obliterated when activating a colorscheme that uses `:hi clear` (which will reset highlights back to defaults), such as a Base16 theme: - https://github.com/chriskempson/base16-vim/blob/3be3cd82cd31acfcab9a41bad853d9c68d30478d/colors/base16-one-light.vim#L146 or Dracula: - https://github.com/dracula/vim/blob/b2cc39273abbb6b38a3d173d2a5d8c2d1c79fc19/colors/dracula.vim#L19-L24 and presumably others. --- syntax/typescript.vim | 198 ++++++++++++++++++++---------------------- 1 file changed, 96 insertions(+), 102 deletions(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 5ae3722..f273816 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -224,110 +224,104 @@ syn region foldBraces start=/{/ skip=/\(\/\/.*\)\|\(\/.*\/\)/ end=/}/ transparen " }}} " Define the default highlighting. -" For version 5.7 and earlier: only when not done already by this script -" For version 5.8 and later: only when an item doesn't have highlighting yet -" For version 8.1.1486 and later, and nvim 0.5.0 and later: only when not done already by this script (need to override vim's new typescript support) -if version >= 508 || !exists("did_typescript_syn_inits") - if version < 508 || has('patch-8.1.1486') || has('nvim-0.5.0') - let did_typescript_syn_inits = 1 - command -nargs=+ HiLink hi link - else - command -nargs=+ HiLink hi def link - endif - - "typescript highlighting - HiLink typescriptParameters Operator - HiLink typescriptSuperBlock Operator - - HiLink typescriptEndColons Exception - HiLink typescriptOpSymbols Operator - HiLink typescriptLogicSymbols Boolean - HiLink typescriptBraces Function - HiLink typescriptParens Operator - HiLink typescriptComment Comment - HiLink typescriptLineComment Comment - HiLink typescriptRefComment Include - HiLink typescriptRefS String - HiLink typescriptRefD String - HiLink typescriptDocComment Comment - HiLink typescriptCommentTodo Todo - HiLink typescriptCvsTag Function - HiLink typescriptDocTags Special - HiLink typescriptDocSeeTag Function - HiLink typescriptDocParam Function - HiLink typescriptStringS String - HiLink typescriptStringD String - HiLink typescriptStringB String - HiLink typescriptInterpolationDelimiter Delimiter - HiLink typescriptRegexpString String - HiLink typescriptGlobal Constant - HiLink typescriptCharacter Character - HiLink typescriptPrototype Type - HiLink typescriptConditional Conditional - HiLink typescriptBranch Conditional - HiLink typescriptIdentifier Identifier - HiLink typescriptStorageClass StorageClass - HiLink typescriptRepeat Repeat - HiLink typescriptStatement Statement - HiLink typescriptFuncKeyword Keyword - HiLink typescriptMessage Keyword - HiLink typescriptDeprecated Exception - HiLink typescriptError Error - HiLink typescriptParensError Error - HiLink typescriptParensErrA Error - HiLink typescriptParensErrB Error - HiLink typescriptParensErrC Error - HiLink typescriptReserved Keyword - HiLink typescriptOperator Operator - HiLink typescriptType Type - HiLink typescriptNull Type - HiLink typescriptNumber Number - HiLink typescriptFloat Number - HiLink typescriptDecorators Special - HiLink typescriptBoolean Boolean - HiLink typescriptLabel Label - HiLink typescriptSpecial Special - HiLink typescriptSource Special - HiLink typescriptGlobalObjects Special - HiLink typescriptGlobalNodeObjects Special - HiLink typescriptExceptions Special - - HiLink typescriptDomErrNo Constant - HiLink typescriptDomNodeConsts Constant - HiLink typescriptDomElemAttrs Label - HiLink typescriptDomElemFuncs PreProc - - HiLink typescriptHtmlElemAttrs Label - HiLink typescriptHtmlElemFuncs PreProc - - HiLink typescriptCssStyles Label - - " Ajax Highlighting - HiLink typescriptBrowserObjects Constant - - HiLink typescriptDOMObjects Constant - HiLink typescriptDOMMethods Function - HiLink typescriptDOMProperties Special - - HiLink typescriptAjaxObjects Constant - HiLink typescriptAjaxMethods Function - HiLink typescriptAjaxProperties Special - - HiLink typescriptFuncDef Title - HiLink typescriptFuncArg Special - HiLink typescriptFuncComma Operator - - HiLink typescriptHtmlEvents Special - HiLink typescriptHtmlElemProperties Special - - HiLink typescriptEventListenerKeywords Keyword - - HiLink typescriptNumber Number - HiLink typescriptPropietaryObjects Constant - - delcommand HiLink +if version < 508 + command -nargs=+ HiLink hi link +else + command -nargs=+ HiLink hi def link endif +"typescript highlighting +HiLink typescriptParameters Operator +HiLink typescriptSuperBlock Operator + +HiLink typescriptEndColons Exception +HiLink typescriptOpSymbols Operator +HiLink typescriptLogicSymbols Boolean +HiLink typescriptBraces Function +HiLink typescriptParens Operator +HiLink typescriptComment Comment +HiLink typescriptLineComment Comment +HiLink typescriptRefComment Include +HiLink typescriptRefS String +HiLink typescriptRefD String +HiLink typescriptDocComment Comment +HiLink typescriptCommentTodo Todo +HiLink typescriptCvsTag Function +HiLink typescriptDocTags Special +HiLink typescriptDocSeeTag Function +HiLink typescriptDocParam Function +HiLink typescriptStringS String +HiLink typescriptStringD String +HiLink typescriptStringB String +HiLink typescriptInterpolationDelimiter Delimiter +HiLink typescriptRegexpString String +HiLink typescriptGlobal Constant +HiLink typescriptCharacter Character +HiLink typescriptPrototype Type +HiLink typescriptConditional Conditional +HiLink typescriptBranch Conditional +HiLink typescriptIdentifier Identifier +HiLink typescriptStorageClass StorageClass +HiLink typescriptRepeat Repeat +HiLink typescriptStatement Statement +HiLink typescriptFuncKeyword Keyword +HiLink typescriptMessage Keyword +HiLink typescriptDeprecated Exception +HiLink typescriptError Error +HiLink typescriptParensError Error +HiLink typescriptParensErrA Error +HiLink typescriptParensErrB Error +HiLink typescriptParensErrC Error +HiLink typescriptReserved Keyword +HiLink typescriptOperator Operator +HiLink typescriptType Type +HiLink typescriptNull Type +HiLink typescriptNumber Number +HiLink typescriptFloat Number +HiLink typescriptDecorators Special +HiLink typescriptBoolean Boolean +HiLink typescriptLabel Label +HiLink typescriptSpecial Special +HiLink typescriptSource Special +HiLink typescriptGlobalObjects Special +HiLink typescriptGlobalNodeObjects Special +HiLink typescriptExceptions Special + +HiLink typescriptDomErrNo Constant +HiLink typescriptDomNodeConsts Constant +HiLink typescriptDomElemAttrs Label +HiLink typescriptDomElemFuncs PreProc + +HiLink typescriptHtmlElemAttrs Label +HiLink typescriptHtmlElemFuncs PreProc + +HiLink typescriptCssStyles Label + +" Ajax Highlighting +HiLink typescriptBrowserObjects Constant + +HiLink typescriptDOMObjects Constant +HiLink typescriptDOMMethods Function +HiLink typescriptDOMProperties Special + +HiLink typescriptAjaxObjects Constant +HiLink typescriptAjaxMethods Function +HiLink typescriptAjaxProperties Special + +HiLink typescriptFuncDef Title +HiLink typescriptFuncArg Special +HiLink typescriptFuncComma Operator + +HiLink typescriptHtmlEvents Special +HiLink typescriptHtmlElemProperties Special + +HiLink typescriptEventListenerKeywords Keyword + +HiLink typescriptNumber Number +HiLink typescriptPropietaryObjects Constant + +delcommand HiLink + " Define the htmltypescript for HTML syntax html.vim "syntax clear htmltypescript "syntax clear typescriptExpression From e83ccab88c7a045ce795583adb66956afd464a31 Mon Sep 17 00:00:00 2001 From: Leaf Garland Date: Mon, 5 Feb 2024 11:23:59 +1300 Subject: [PATCH 42/45] Include alternatives to this syntax in README I think it's time that people moved on to other ways of highlighting Typescript code. --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a880998..8030231 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,18 @@ -Typescript Syntax for Vim +An old Typescript Syntax for Vim ========================= +--- + +NOTE: This Typescript syntax was created before Typescript's 1.0 release, more than a decade ago. I hope it +has been helpful but there are now other options available. Vim has included +[Typescript syntax](https://github.com/vim/vim/blob/master/runtime/syntax/typescript.vim) for some years, +which receives more frequent updates at its own [repository](https://github.com/HerringtonDarkholme/yats.vim). +Neovim can also use a [treesitter grammar](https://github.com/tree-sitter/tree-sitter-typescript) for highlighting. + +--- + Syntax file and other settings for [TypeScript](http://typescriptlang.org). The -syntax file is taken from this [blog +syntax file was originally from this 2012 [blog post](https://docs.microsoft.com/en-us/archive/blogs/interoperability/sublime-text-vi-emacs-typescript-enabled). Checkout [Tsuquyomi](https://github.com/Quramy/tsuquyomi) for omni-completion From 122daf8760bb8bf7f7269e234635dd49a0064ef1 Mon Sep 17 00:00:00 2001 From: tga Date: Mon, 8 Apr 2024 15:53:59 +0800 Subject: [PATCH 43/45] add satisfies to keywords --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index f273816..c0c5448 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -129,7 +129,7 @@ syntax keyword typescriptGlobalNodeObjects module exports global process __dirn syntax keyword typescriptExceptions try catch throw finally Error EvalError RangeError ReferenceError SyntaxError TypeError URIError -syntax keyword typescriptReserved constructor declare as interface module abstract enum int short export interface static byte extends long super char final native synchronized class float package throws goto private transient debugger implements protected volatile double import public type namespace from get set keyof +syntax keyword typescriptReserved constructor declare as interface module abstract enum int short export interface static byte extends long super char final native synchronized class float package throws goto private transient debugger implements protected volatile double import public type namespace from get set keyof satisfies "}}} "" typescript/DOM/HTML/CSS specified things"{{{ From 1b19693055bb759fcdec5f1f033fdaa260362bfe Mon Sep 17 00:00:00 2001 From: tga Date: Tue, 21 May 2024 20:28:39 +0800 Subject: [PATCH 44/45] rm status from typescriptMessage --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index c0c5448..311ed07 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -113,7 +113,7 @@ syntax keyword typescriptStorageClass let var const syntax keyword typescriptOperator delete new instanceof typeof syntax keyword typescriptBoolean true false syntax keyword typescriptNull null undefined -syntax keyword typescriptMessage alert confirm prompt status +syntax keyword typescriptMessage alert confirm prompt syntax keyword typescriptGlobal self top parent syntax keyword typescriptDeprecated escape unescape all applets alinkColor bgColor fgColor linkColor vlinkColor xmlEncoding "}}} From 5fc0e70e13e43ea131ebd32928a3dae0958efa17 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Wed, 11 Dec 2024 17:31:10 +0100 Subject: [PATCH 45/45] Add `using` as a recognized keyword This keyword is recognized as of TypeScript 5.2: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html --- syntax/typescript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/typescript.vim b/syntax/typescript.vim index 311ed07..6905134 100644 --- a/syntax/typescript.vim +++ b/syntax/typescript.vim @@ -109,7 +109,7 @@ endif "" Programm Keywords"{{{ syntax keyword typescriptSource import export from as syntax keyword typescriptIdentifier arguments this void -syntax keyword typescriptStorageClass let var const +syntax keyword typescriptStorageClass let var const using syntax keyword typescriptOperator delete new instanceof typeof syntax keyword typescriptBoolean true false syntax keyword typescriptNull null undefined