vim-patch:818c641: runtime(vim): Update base-syntax file, improve class, enum and interface highlighting

- Enable folding of class, enum and interface declarations.
- Highlight constructor names with the Function highlight group, like
  other special methods.
- Mark function definitions using special method names as errors.
- Highlight :type arguments.

fixes: vim/vim#14393#issuecomment-2042796198.
closes: vim/vim#13810

818c641b6f

Co-authored-by: Doug Kearns <dougkearns@gmail.com>
This commit is contained in:
zeertzjq 2024-11-10 10:00:35 +08:00
parent e9dc9be469
commit 93dbf1d86c
2 changed files with 158 additions and 21 deletions

View File

@ -3493,7 +3493,7 @@ This option is disabled by default.
Some folding is now supported with when 'foldmethod' is set to "syntax": >
g:vimsyn_folding == 0 or doesn't exist: no syntax-based folding
g:vimsyn_folding =~ 'a' : augroups
g:vimsyn_folding =~ 'a' : fold augroups
g:vimsyn_folding =~ 'f' : fold functions
g:vimsyn_folding =~ 'h' : fold heredocs
g:vimsyn_folding =~ 'l' : fold Lua script

View File

@ -74,12 +74,22 @@ syn case match
com! -nargs=* Vim9 execute <q-args> s:vim9script ? "" : "contained"
com! -nargs=* VimL execute <q-args> s:vim9script ? "contained" : ""
if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[afhHlmpPrt]'
if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[acefhiHlmpPrt]'
if g:vimsyn_folding =~# 'a'
com! -nargs=* VimFolda <args> fold
else
com! -nargs=* VimFolda <args>
endif
if g:vimsyn_folding =~# 'c'
com! -nargs=* VimFoldc <args> fold
else
com! -nargs=* VimFoldc <args>
endif
if g:vimsyn_folding =~# 'e'
com! -nargs=* VimFolde <args> fold
else
com! -nargs=* VimFolde <args>
endif
if g:vimsyn_folding =~# 'f'
com! -nargs=* VimFoldf <args> fold
else
@ -95,6 +105,11 @@ if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[afhHlmpPrt]'
else
com! -nargs=* VimFoldH <args>
endif
if g:vimsyn_folding =~# 'i'
com! -nargs=* VimFoldi <args> fold
else
com! -nargs=* VimFoldi <args>
endif
if g:vimsyn_folding =~# 'l'
com! -nargs=* VimFoldl <args> fold
else
@ -127,7 +142,10 @@ if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[afhHlmpPrt]'
endif
else
com! -nargs=* VimFolda <args>
com! -nargs=* VimFoldc <args>
com! -nargs=* VimFolde <args>
com! -nargs=* VimFoldf <args>
com! -nargs=* VimFoldi <args>
com! -nargs=* VimFoldh <args>
com! -nargs=* VimFoldH <args>
com! -nargs=* VimFoldl <args>
@ -177,8 +195,8 @@ syn match vimNumber '\%(^\|\A\)\zs#\x\{6}' skipwhite nextgroup=vimGlobal,vimSub
syn case match
" All vimCommands are contained by vimIsCommand. {{{2
syn cluster vimCmdList contains=vimAbb,vimAddress,vimAutoCmd,vimAugroup,vimBehave,vimCall,vimCatch,vimConst,vimDef,vimDelcommand,@vimEcho,vimEnddef,vimEndfunction,vimExecute,vimIsCommand,vimExtCmd,vimFor,vimFunction,vimFuncFold,vimGlobal,vimHighlight,vimLet,vimLoadkeymap,vimMap,vimMark,vimMatch,vimNotFunc,vimNorm,vimSet,vimSleep,vimSyntax,vimThrow,vimUnlet,vimUnmap,vimUserCmd,vimMenu,vimMenutranslate,@vim9CmdList
syn cluster vim9CmdList contains=vim9Const,vim9Final,vim9For,vim9Var
syn cluster vimCmdList contains=vimAbb,vimAddress,vimAutoCmd,vimAugroup,vimBehave,vimCall,vimCatch,vimConst,vimDef,vimDefFold,vimDelcommand,@vimEcho,vimEnddef,vimEndfunction,vimExecute,vimIsCommand,vimExtCmd,vimFor,vimFunction,vimFuncFold,vimGlobal,vimHighlight,vimLet,vimLoadkeymap,vimMap,vimMark,vimMatch,vimNotFunc,vimNorm,vimSet,vimSleep,vimSyntax,vimThrow,vimUnlet,vimUnmap,vimUserCmd,vimMenu,vimMenutranslate,@vim9CmdList
syn cluster vim9CmdList contains=vim9Class,vim9Const,vim9Enum,vim9Export,vim9Final,vim9For,vim9Interface,vim9Type,vim9Var
syn match vimCmdSep "[:|]\+" skipwhite nextgroup=@vimCmdList,vimSubst1
syn match vimIsCommand "\<\%(\h\w*\|[23]mat\%[ch]\)\>" contains=vimCommand
syn match vimBang contained "!"
@ -220,6 +238,12 @@ syn keyword vimThrow th[row] skipwhite nextgroup=@vimExprList
syn keyword vimCatch cat[ch] skipwhite nextgroup=vimCatchPattern
syn region vimCatchPattern contained matchgroup=Delimiter start="\z([!#$%&'()*+,-./:;<=>?@[\]^_`{}~]\)" skip="\\\\\|\\\z1" end="\z1" contains=@vimSubstList oneline
" Export {{{2
" ======
if s:vim9script
syn keyword vim9Export export skipwhite nextgroup=vim9Abstract,vim9ClassBody,vim9Const,vim9Def,vim9EnumBody,vim9Final,vim9InterfaceBody,vim9Type,vim9Var
endif
" Filetypes {{{2
" =========
syn match vimFiletype "\<filet\%[ype]\(\s\+\I\i*\)*" skipwhite contains=vimFTCmd,vimFTOption,vimFTError
@ -264,7 +288,7 @@ endif
syn cluster vimFuncList contains=vimFuncBang,vimFunctionError,vimFuncKey,vimFuncSID,Tag
syn cluster vimDefList contains=vimFuncBang,vimFunctionError,vimDefKey,vimFuncSID,Tag
syn cluster vimFuncBodyCommon contains=@vimCmdList,vimCmplxRepeat,vimContinue,vimCtrlChar,vimDef,vimEnvvar,vimFBVar,vimFunc,vimFunction,vimLetHereDoc,vimNotation,vimNotFunc,vimNumber,vimOper,vimOperParen,vimRegister,vimSearch,vimSpecFile,vimString,vimSubst,vimFuncFold
syn cluster vimFuncBodyCommon contains=@vimCmdList,vimCmplxRepeat,vimContinue,vimCtrlChar,vimDef,vimEnvvar,vimFBVar,vimFunc,vimFunction,vimLetHereDoc,vimNotation,vimNotFunc,vimNumber,vimOper,vimOperParen,vimRegister,vimSearch,vimSpecFile,vimString,vimSubst,vimFuncFold,vimDefFold
syn cluster vimFuncBodyList contains=@vimFuncBodyCommon,vimComment,vimLineComment,vimFuncVar,vimInsert,vimConst,vimLet
syn cluster vimDefBodyList contains=@vimFuncBodyCommon,vim9Comment,vim9LineComment,vim9Const,vim9Final,vim9Var,vim9Null,vim9Boolean,vim9For
@ -273,8 +297,7 @@ syn match vimFunction "\<fu\%[nction]\>" skipwhite nextgroup=vimCmdSep,vimCommen
syn match vimDef "\<def\>" skipwhite nextgroup=vimCmdSep,vimComment,vimFuncPattern contains=vimDefKey
syn match vimFunction "\<fu\%[nction]\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+" contains=@vimFuncList skipwhite nextgroup=vimFuncParams
syn match vimDef "\<def\s\+new\%(\i\|{.\{-1,}}\)\+" contains=@vimDefList nextgroup=vimDefParams
syn match vimDef "\<def\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+" contains=@vimDefList,vimMethodName nextgroup=vimDefParams
syn match vimDef "\<def\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+" contains=@vimDefList nextgroup=vimDefParams
syn match vimFuncComment contained +".*+ skipwhite skipempty nextgroup=vimFuncBody,vimEndfunction
syn match vimDefComment contained "#.*" skipwhite skipempty nextgroup=vimDefBody,vimEnddef
@ -284,7 +307,6 @@ syn match vimFuncSID contained "\c<sid>"
syn match vimFuncSID contained "\<[sg]:"
syn keyword vimFuncKey contained fu[nction]
syn keyword vimDefKey contained def
syn keyword vimMethodName contained empty len string
syn region vimFuncParams contained matchgroup=Delimiter start="(" skip=+\n\s*\\\|\n\s*"\\ + end=")" skipwhite skipempty nextgroup=vimFuncBody,vimFuncComment,vimEndfunction,vimFuncMod,vim9CommentError contains=vimFuncParam,@vimContinue
syn region vimDefParams contained matchgroup=Delimiter start="(" end=")" skipwhite skipempty nextgroup=vimDefBody,vimDefComment,vimEnddef,vimReturnType,vimCommentError contains=vimDefParam,vim9Comment,vimFuncParamEquals
@ -301,9 +323,8 @@ syn match vimEndfunction "\<endf\%[unction]\>" skipwhite nextgroup=vimCmdSep,vim
syn match vimEnddef "\<enddef\>" skipwhite nextgroup=vimCmdSep,vim9Comment,vimCommentError
if exists("g:vimsyn_folding") && g:vimsyn_folding =~# 'f'
syn region vimFuncFold start="\<fu\%[nction]\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+\s*(" end="\<endf\%[unction]\>" contains=vimFunction fold keepend extend transparent
syn region vimFuncFold start="\<def\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\)\+(" end="\<enddef\>" contains=vimDef fold keepend extend transparent
syn region vimFuncFold start="\<def\s\+new\i\+(" end="\<enddef\>" contains=vimDef fold keepend extend transparent
syn region vimFuncFold start="\<fu\%[nction]\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+\s*(" end="\<endf\%[unction]\>" contains=vimFunction fold keepend extend transparent
syn region vimDefFold start="\<def\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\)\+(" end="\<enddef\>" contains=vimDef fold keepend extend transparent
endif
syn match vimFuncVar contained "a:\%(\K\k*\|\d\+\)\>"
@ -324,6 +345,100 @@ syn match vimUserType contained "\<\u\w*\>"
syn cluster vimType contains=vimType,vimCompoundType,vimUserType
" Classes, Enums And Interfaces: {{{2
" =============================
if s:vim9script
" Methods {{{3
syn match vim9MethodDef contained "\<def\>" skipwhite nextgroup=vim9MethodDefName
syn match vim9MethodDefName contained "\<\h\w*\>" nextgroup=vim9MethodDefParams contains=@vim9MethodName
syn region vim9MethodDefParams contained
\ matchgroup=Delimiter start="(" end=")"
\ skipwhite skipnl nextgroup=vim9MethodDefBody,vimDefComment,vimEnddef,vim9MethodDefReturnType,vimCommentError
\ contains=vimDefParam,vim9Comment,vimFuncParamEquals
syn region vim9MethodDefReturnType contained
\ start=":\s" end="$" matchgroup=vim9Comment end="\ze[#"]"
\ skipwhite skipnl nextgroup=vim9MethodDefBody,vimDefComment,vimCommentError
\ contains=vimTypeSep
\ transparent
syn region vim9MethodDefBody contained
\ start="^.\=" matchgroup=vimCommand end="\<enddef\>"
\ skipwhite nextgroup=vimCmdSep,vim9Comment,vimCommentError
\ contains=@vim9MethodDefBodyList
syn cluster vim9MethodDefBodyList contains=@vimDefBodyList,vim9This,vim9Super
if !exists("g:vimsyn_noerror") && !exists("g:vimsyn_novimfunctionerror")
syn match vim9MethodNameError contained "\<[a-z0-9]\i\>"
endif
syn match vim9MethodName contained "\<new\i*\>"
syn keyword vim9MethodName contained empty len string
syn cluster vim9MethodName contains=vim9MethodName,vim9MethodNameError
if exists("g:vimsyn_folding") && g:vimsyn_folding =~# 'f'
syn region vim9MethodDefFold contained start="\%(^\s*\%(:\=static\s\+\)\=\)\@16<=:\=def\s\+\h\i*(" end="^\s*:\=enddef\>" contains=vim9MethodDef fold keepend extend transparent
syn region vim9MethodDefFold contained start="^\s*:\=def\s\+new\i*(" end="^\s*:\=enddef\>" contains=vim9MethodDef fold keepend extend transparent
endif
syn cluster vim9MethodDef contains=vim9MethodDef,vim9MethodDefFold
" Classes {{{3
syn cluster vim9ClassBodyList contains=vim9Abstract,vim9Class,vim9Comment,vim9LineComment,@vim9Continue,@vimExprList,vim9Extends,vim9Implements,@vim9MethodDef,vim9Public,vim9Static,vim9Const,vim9Final,vim9This,vim9Super,vim9Var
syn match vim9Class contained "\<class\>" skipwhite nextgroup=vim9ClassName
syn match vim9ClassName contained "\<\u\w*\>" skipwhite skipnl nextgroup=vim9Extends,vim9Implements
syn match vim9SuperClass contained "\<\u\w*\>" skipwhite skipnl nextgroup=vim9Implements
syn match vim9ImplementedInterface contained "\<\u\w*\>" skipwhite skipnl nextgroup=vim9InterfaceListComma,vim9Extends
syn match vim9InterfaceListComma contained "," skipwhite skipnl nextgroup=vim9ImplementedInterface
syn keyword vim9Abstract abstract skipwhite skipnl nextgroup=vim9ClassBody,vim9AbstractDef
syn keyword vim9Extends contained extends skipwhite skipnl nextgroup=vim9SuperClass
syn keyword vim9Implements contained implements skipwhite skipnl nextgroup=vim9ImplementedInterface
syn keyword vim9Public contained public
syn keyword vim9Static contained static
syn keyword vim9This contained this
syn keyword vim9Super contained super
VimFoldc syn region vim9ClassBody start="\<class\>" matchgroup=vimCommand end="\<endclass\>" contains=@vim9ClassBodyList transparent
" Enums {{{3
syn cluster vim9EnumBodyList contains=vim9Comment,vim9LineComment,@vim9Continue,vim9Enum,vim9Implements,@vim9MethodDef,vim9Const,vim9Final,vim9Var
syn match vim9Enum contained "\<enum\>" skipwhite nextgroup=vim9EnumName
syn match vim9EnumName contained "\<\u\w*\>" skipwhite skipnl nextgroup=vim9Implements
VimFolde syn region vim9EnumBody start="\<enum\>" matchgroup=vimCommand end="\<endenum\>" contains=@vim9EnumBodyList transparent
" Interfaces {{{3
" TODO: limit to decl only - no init values
syn cluster vim9InterfaceBodyList contains=vim9Comment,vim9LineComment,@vim9Continue,vim9Extends,vim9Interface,vim9AbstractDef,vim9Var
syn match vim9Interface contained "\<interface\>" skipwhite nextgroup=vim9InterfaceName
syn match vim9InterfaceName contained "\<\u\w*\>" skipwhite skipnl nextgroup=vim9Extends
syn keyword vim9AbstractDef contained def skipwhite nextgroup=vim9AbstractDefName
syn match vim9AbstractDefName contained "\<\h\w*\>" skipwhite nextgroup=vim9AbstractDefParams contains=@vim9MethodName
syn region vim9AbstractDefParams contained
\ matchgroup=Delimiter start="(" end=")"
\ skipwhite skipnl nextgroup=vimDefComment,vim9AbstractDefReturnType,vimCommentError
\ contains=vimDefParam,vim9Comment,vimFuncParamEquals
syn region vim9AbstractDefReturnType contained
\ start=":\s" end="$" matchgroup=vim9Comment end="\ze[#"]"
\ skipwhite skipnl nextgroup=vimDefComment,vimCommentError
\ contains=vimTypeSep
\ transparent
VimFoldi syn region vim9InterfaceBody start="\<interface\>" matchgroup=vimCommand end="\<endinterface\>" contains=@vim9InterfaceBodyList transparent
" type {{{3
syn match vim9Type "\<ty\%[pe]\>" skipwhite nextgroup=vim9TypeAlias,vim9TypeAliasError
syn match vim9TypeAlias contained "\<\u\w*\>" skipwhite nextgroup=vim9TypeEquals
syn match vim9TypeEquals contained "=" skipwhite nextgroup=@vimType
if !exists("g:vimsyn_noerror") && !exists("g:vimsyn_notypealiaserror")
syn match vim9TypeAliasError contained "\<\U\w*"
endif
endif
" Keymaps: {{{2
" =======
@ -542,7 +657,7 @@ Vim9 syn keyword vim9Const const skipwhite nextgroup=vim9Variable,vim9VariableLi
Vim9 syn keyword vim9Final final skipwhite nextgroup=vim9Variable,vim9VariableList
Vim9 syn keyword vim9Var var skipwhite nextgroup=vim9Variable,vim9VariableList
syn match vim9Variable contained "\<\h\w*\>" skipwhite nextgroup=vimTypeSep,vimLetHereDoc
syn match vim9Variable contained "\<\h\w*\>" skipwhite nextgroup=vimTypeSep,vimLetHereDoc,vimOper
syn region vim9VariableList contained start="\[" end="]" contains=vim9Variable,@vimContinue
" For: {{{2
@ -669,7 +784,7 @@ syn case match
" (following Gautam Iyer's suggestion)
" ==========================
syn match vimFunc "\%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%(\w\+\.\)*\I[a-zA-Z0-9_.]*\)\ze\s*(" contains=vimFuncEcho,vimFuncName,vimUserFunc,vimExecute
syn match vimUserFunc contained "\%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%(\w\+\.\)*\I[a-zA-Z0-9_.]*\)\|\<\u[a-zA-Z0-9.]*\>\|\<if\>" contains=vimNotation,vimMethodName
syn match vimUserFunc contained "\%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%(\w\+\.\)*\I[a-zA-Z0-9_.]*\)\|\<\u[a-zA-Z0-9.]*\>\|\<if\>" contains=vimNotation,vim9MethodName
syn keyword vimFuncEcho contained ec ech echo
syn match vimMap "\<map\%(\s\+(\)\@=" skipwhite nextgroup=vimMapBang,vimMapMod,vimMapLhs
@ -680,10 +795,7 @@ syn match vimUsrCmd '^\s*\zs\u\%(\w*\)\@>\%([(#[]\|\s\+\%([-+*/%]\=\|\.\.\)=\)\@
" Errors And Warnings: {{{2
" ====================
if !exists("g:vimsyn_noerror") && !exists("g:vimsyn_novimfunctionerror")
" TODO: The new-prefix exception should only apply to constructor definitions.
" TODO: The |builtin-object-methods| exception should only apply to method
" definitions.
syn match vimFunctionError "\s\zs\%(empty\|len\|new\|string\)\@![a-z0-9]\i\{-}\ze\s*(" contained contains=vimFuncKey,vimFuncBlank
syn match vimFunctionError "\s\zs[a-z0-9]\i\{-}\ze\s*(" contained contains=vimFuncKey,vimFuncBlank
syn match vimFunctionError "\s\zs\%(<[sS][iI][dD]>\|[sSgGbBwWtTlL]:\)\d\i\{-}\ze\s*(" contained contains=vimFuncKey,vimFuncBlank
syn match vimElseIfErr "\<else\s\+if\>"
syn match vimBufnrWarn /\<bufnr\s*(\s*["']\.['"]\s*)/
@ -890,7 +1002,10 @@ syn match vimShebang "\%^#!.*" display
syn match vimContinue "^\s*\zs\\"
syn match vimContinueComment '^\s*\zs["#]\\ .*'
syn cluster vimContinue contains=vimContinue,vimContinueComment
syn match vim9ContinueComment "^\s*\zs#\\ .*"
syn cluster vimContinue contains=vimContinue,vimContinueComment
syn cluster vim9Continue contains=vimContinue,vim9ContinueComment
syn region vimString start="^\s*\\\z(['"]\)" skip='\\\\\|\\\z1' end="\z1" oneline keepend contains=@vimStringGroup,vimContinue
syn match vimCommentTitleLeader '"\s\+'ms=s+1 contained
syn match vim9CommentTitleLeader '#\s\+'ms=s+1 contained
@ -1149,6 +1264,8 @@ if !exists("skip_vim_syntax_inits")
hi def link vimSynCaseError vimError
hi def link vimSynFoldMethodError vimError
hi def link vimBufnrWarn vimWarn
hi def link vim9TypeAliasError vimError
endif
hi def link vimAbb vimCommand
@ -1259,7 +1376,7 @@ if !exists("skip_vim_syntax_inits")
hi def link vimMenuPriority Number
hi def link vimMenuStatus Special
hi def link vimMenutranslateComment vimComment
hi def link vimMethodName vimFuncName
hi def link vim9MethodName vimFuncName
hi def link vimMtchComment vimComment
hi def link vimNorm vimCommand
hi def link vimNotation Special
@ -1353,19 +1470,36 @@ if !exists("skip_vim_syntax_inits")
hi def link vimVar Identifier
hi def link vimWarn WarningMsg
hi def link vim9Abstract vimCommand
hi def link vim9Boolean Boolean
hi def link vim9Class vimCommand
hi def link vim9Comment Comment
hi def link vim9CommentError vimError
hi def link vim9CommentTitle PreProc
hi def link vim9Const vimCommand
hi def link vim9ContinueComment vimContinueComment
hi def link vim9Enum vimCommand
hi def link vim9Export vimCommand
hi def link vim9Extends Keyword
hi def link vim9Final vimCommand
hi def link vim9For vimCommand
hi def link vim9Implements Keyword
hi def link vim9AbstractDef vimCommand
hi def link vim9Interface vimCommand
hi def link vim9LineComment vimComment
hi def link vim9MethodDef vimCommand
hi def link vim9MethodNameError vimFunctionError
hi def link vim9Null Constant
hi def link vim9Var vimCommand
hi def link vim9Public vimCommand
hi def link vim9Static vimCommand
hi def link vim9Super Identifier
hi def link vim9This Identifier
hi def link vim9Type vimCommand
hi def link vim9TypeEquals vimOper
hi def link vim9Variable vimVar
hi def link vim9Vim9Script vimCommand
hi def link vim9Var vimCommand
hi def link vim9Vim9ScriptArg Special
hi def link vim9Vim9Script vimCommand
hi def link nvimAutoEvent vimAutoEvent
hi def link nvimHLGroup vimHLGroup
@ -1379,9 +1513,12 @@ let b:current_syntax = "vim"
delc Vim9
delc VimL
delc VimFolda
delc VimFoldc
delc VimFolde
delc VimFoldf
delc VimFoldh
delc VimFoldH
delc VimFoldi
delc VimFoldl
delc VimFoldm
delc VimFoldp