vim-patch:35e6f4ca27c8 (#27973)

runtime(vim): Update base-syntax, improve function definition highlighting (vim/vim#14203)

Improve function definition highlighting.

- Match bang and function modifiers - abort etc.
- Only match valid scope modifiers.
- Match listing commands.
- Don't match ex commands in function names.
- Split function syntax groups into :func and :def subgroups.
- Match Vim9-script parameter and return types.
- Limit legacy-script and Vim9-script comments to :func and :def
  definitions, respectively.

35e6f4ca27

Omit the vimFunctionError change as it's a whitespace-only change and
will likely be superseded by later patches.

Co-authored-by: dkearns <dougkearns@gmail.com>
This commit is contained in:
zeertzjq 2024-03-22 07:31:43 +08:00 committed by GitHub
parent 50b2499306
commit 15c6909bb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -155,7 +155,7 @@ syn match vimNumber '\%(^\|\A\)\zs#\x\{6}' skipwhite nextgroup=vimGlobal,vimSub
syn case match syn case match
" All vimCommands are contained by vimIsCommand. {{{2 " All vimCommands are contained by vimIsCommand. {{{2
syn cluster vimCmdList contains=vimAbb,vimAddress,vimAutoCmd,vimAugroup,vimBehave,@vimEcho,vimExecute,vimIsCommand,vimExtCmd,vimFunction,vimGlobal,vimHighlight,vimLet,vimMap,vimMark,vimNotFunc,vimNorm,vimSet,vimSyntax,vimUnlet,vimUnmap,vimUserCmd,vimMenu,vimMenutranslate syn cluster vimCmdList contains=vimAbb,vimAddress,vimAutoCmd,vimAugroup,vimBehave,vimDef,@vimEcho,vimEnddef,vimEndfunction,vimExecute,vimIsCommand,vimExtCmd,vimFor,vimFunction,vimGlobal,vimHighlight,vimLet,vimMap,vimMark,vimNotFunc,vimNorm,vimSet,vimSyntax,vimUnlet,vimUnmap,vimUserCmd,vimMenu,vimMenutranslate
syn match vimCmdSep "[:|]\+" skipwhite nextgroup=@vimCmdList,vimSubst1 syn match vimCmdSep "[:|]\+" skipwhite nextgroup=@vimCmdList,vimSubst1
syn match vimIsCommand "\<\%(\h\w*\|[23]mat\%[ch]\)\>" contains=vimCommand syn match vimIsCommand "\<\%(\h\w*\|[23]mat\%[ch]\)\>" contains=vimCommand
syn match vimVar contained "\<\h[a-zA-Z0-9#_]*\>" syn match vimVar contained "\<\h[a-zA-Z0-9#_]*\>"
@ -215,7 +215,7 @@ syn keyword vimAugroupKey contained aug[roup] skipwhite nextgroup=vimAugroupBan
" Operators: {{{2 " Operators: {{{2
" ========= " =========
syn cluster vimOperGroup contains=vimEnvvar,vimFunc,vimFuncVar,vimOper,vimOperParen,vimNumber,vimString,vimType,vimRegister,@vimContinue,vim9Comment,vimVar syn cluster vimOperGroup contains=vimEnvvar,vimFunc,vimFuncVar,vimOper,vimOperParen,vimNumber,vimString,vimRegister,@vimContinue,vim9Comment,vimVar
syn match vimOper "||\|&&\|[-+*/%.!]" skipwhite nextgroup=vimString,vimSpecFile syn match vimOper "||\|&&\|[-+*/%.!]" skipwhite nextgroup=vimString,vimSpecFile
syn match vimOper "\%#=1\(==\|!=\|>=\|<=\|=\~\|!\~\|>\|<\|=\|!\~#\)[?#]\{0,2}" skipwhite nextgroup=vimString,vimSpecFile syn match vimOper "\%#=1\(==\|!=\|>=\|<=\|=\~\|!\~\|>\|<\|=\|!\~#\)[?#]\{0,2}" skipwhite nextgroup=vimString,vimSpecFile
syn match vimOper "\(\<is\|\<isnot\)[?#]\{0,2}\>" skipwhite nextgroup=vimString,vimSpecFile syn match vimOper "\(\<is\|\<isnot\)[?#]\{0,2}\>" skipwhite nextgroup=vimString,vimSpecFile
@ -227,25 +227,67 @@ endif
" Functions : Tag is provided for those who wish to highlight tagged functions {{{2 " Functions : Tag is provided for those who wish to highlight tagged functions {{{2
" ========= " =========
syn cluster vimFuncList contains=vimCommand,vimFunctionError,vimFuncKey,Tag,vimFuncSID syn cluster vimFuncList contains=vimFuncBang,vimFunctionError,vimFuncKey,vimFuncSID,Tag
syn cluster vimFuncBodyList contains=@vimCmdList,vimCmplxRepeat,vimComment,vim9Comment,vimContinue,vimCtrlChar,vimEnvvar,vimFBVar,vimFunc,vimFunction,vimFuncVar,vimLetHereDoc,vimLineComment,vimNotation,vimNotFunc,vimNumber,vimOper,vimOperParen,vimRegion,vimRegister,vimSearch,vimSpecFile,vimString,vimSubst syn cluster vimDefList contains=vimFuncBang,vimFunctionError,vimDefKey,vimFuncSID,Tag
syn match vimFunction "\<\(fu\%[nction]\)!\=\s\+\%(<[sS][iI][dD]>\|[sSgGbBwWtTlL]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)*\ze\s*(" contains=@vimFuncList nextgroup=vimFuncBody syn cluster vimFuncBodyList contains=@vimCmdList,vimCmplxRepeat,vimComment,vimContinue,vimCtrlChar,vimDef,vimEnvvar,vimFBVar,vimFunc,vimFunction,vimFuncVar,vimLetHereDoc,vimLineComment,vimNotation,vimNotFunc,vimNumber,vimOper,vimOperParen,vimRegion,vimRegister,vimSearch,vimSpecFile,vimString,vimSubst
syn match vimFunction "\<def!\=\ze\s*(" contains=@vimFuncList nextgroup=vimFuncBody syn cluster vimDefBodyList contains=@vimCmdList,vimCmplxRepeat,vim9Comment,vimContinue,vimCtrlChar,vimDef,vimEnvvar,vimFBVar,vimFunc,vimFunction,vimLetHereDoc,vim9LineComment,vimNotation,vimNotFunc,vimNumber,vimOper,vimOperParen,vimRegion,vimRegister,vimSearch,vimSpecFile,vimString,vimSubst
syn region vimFuncPattern contained matchgroup=vimOper start="/" end="$" contains=@vimSubstList
syn match vimFunction "\<fu\%[nction]\>" skipwhite nextgroup=vimCmdSep,vimComment,vimFuncPattern contains=vimFuncKey
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 nextgroup=vimDefParams
syn match vimFuncComment contained +".*+ skipwhite skipnl nextgroup=vimFuncBody,vimEndfunction
syn match vimDefComment contained "#.*" skipwhite skipnl nextgroup=vimDefBody,vimEnddef
syn match vimFuncBang contained "!"
syn match vimFuncSID contained "\c<sid>"
syn match vimFuncSID contained "\<[sg]:"
syn keyword vimFuncKey contained fu[nction]
syn keyword vimDefKey contained def
syn region vimFuncParams contained matchgroup=Delimiter start="(" skip=+\n\s*\\\|\n\s*"\\ + end=")" skipwhite skipnl nextgroup=vimFuncBody,vimFuncComment,vimEndfunction,vimFuncMod contains=vimFuncParam,@vimContinue
syn region vimDefParams contained matchgroup=Delimiter start="(" end=")" skipwhite skipnl nextgroup=vimDefBody,vimDefComment,vimEnddef,vimReturnType contains=vimDefParam,vim9Comment
syn match vimFuncParam contained "\<\h\w*\>\|\.\.\." skipwhite nextgroup=vimFuncParamEquals
syn match vimDefParam contained "\<\h\w*\>" skipwhite nextgroup=vimParamType,vimFuncParamEquals
syn match vimFuncParamEquals contained "=" skipwhite nextgroup=@vimExprList
syn match vimFuncMod contained "\<\%(abort\|closure\|dict\|range\)\>" skipwhite skipnl nextgroup=vimFuncBody,vimFuncComment,vimEndfunction,vimFuncMod
syn region vimFuncBody contained start="^" matchgroup=vimCommand end="\<endfu\%[nction]\>" contains=@vimFuncBodyList
syn region vimDefBody contained start="^" matchgroup=vimCommand end="\<enddef\>" contains=@vimDefBodyList
syn match vimEndfunction "\<endf\%[unction]\>"
syn match vimEnddef "\<enddef\>"
if exists("g:vimsyn_folding") && g:vimsyn_folding =~# 'f' if exists("g:vimsyn_folding") && g:vimsyn_folding =~# 'f'
syn region vimFuncBody contained fold start="\ze\s*(" matchgroup=vimCommand end="\<\(endf\>\|endfu\%[nction]\>\|enddef\>\)" contains=@vimFuncBodyList syn region vimFuncFold start="\<fu\%[nction]\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+\s*(" end="\<endf\%[unction]\>" contains=vimFunction fold keepend transparent
else syn region vimFuncFold start="\<def\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+(" end="\<enddef\>" contains=vimDef fold keepend transparent
syn region vimFuncBody contained start="\ze\s*(" matchgroup=vimCommand end="\<\(endf\>\|endfu\%[nction]\>\|enddef\>\)" contains=@vimFuncBodyList syn region vimFuncFold start="\<def\s\+new\%(\i\|{.\{-1,}}\)\+(" end="\<enddef\>" contains=vimDef fold keepend transparent
endif endif
syn match vimFuncVar contained "a:\(\K\k*\|\d\+\)"
syn match vimFuncSID contained "\c<sid>\|\<s:" syn match vimFuncVar contained "a:\%(\K\k*\|\d\+\)\>"
syn keyword vimFuncKey contained fu[nction]
syn match vimFuncBlank contained "\s\+" syn match vimFuncBlank contained "\s\+"
syn keyword vimPattern contained start skip end syn keyword vimPattern contained start skip end
" Types: {{{2
" =====
" vimTypes : new for vim9 " vimTypes : new for vim9
syn match vimType ":\s*\zs\<\(bool\|number\|float\|string\|blob\|list<\|dict<\|job\|channel\|func\)\>" syn region vimReturnType contained start=":\s" end="$" matchgroup=vim9Comment end="\ze#" skipwhite skipnl nextgroup=vimDefBody,vimDefComment,vimEnddef contains=vimTypeSep transparent
syn match vimParamType contained ":\s\+\a" skipwhite skipnl nextgroup=vimFuncParamEquals contains=vimTypeSep,@vimType
syn match vimTypeSep contained ":\s\@=" skipwhite nextgroup=@vimType
syn keyword vimType contained any blob bool channel float job number string void
syn match vimType contained "\<func\>"
syn region vimCompoundType contained matchgroup=vimType start="\<func(" end=")" nextgroup=vimTypeSep contains=@vimType oneline transparent
syn region vimCompoundType contained matchgroup=vimType start="\<\%(list\|dict\)<" end=">" contains=@vimType oneline transparent
syn match vimUserType contained "\<\u\w*\>"
syn cluster vimType contains=vimType,vimCompoundType,vimUserType
" Keymaps: (Vim Project Addition) {{{2 " Keymaps: (Vim Project Addition) {{{2
" ======= " =======
@ -454,7 +496,7 @@ syn case ignore
syn keyword vimEchohlNone contained none syn keyword vimEchohlNone contained none
syn case match syn case match
syn cluster vimEcho contains=vimEcho.* syn cluster vimEcho contains=vimEcho,vimEchohl
syn region vimExecute matchgroup=vimCommand start="\<exe\%[cute]\>" skip=+\\|\|\n\s*\\\|\n\s*"\\ + matchgroup=vimCmdSep end="|" excludenl end="$" contains=@vimContinue,@vimExprList transparent syn region vimExecute matchgroup=vimCommand start="\<exe\%[cute]\>" skip=+\\|\|\n\s*\\\|\n\s*"\\ + matchgroup=vimCmdSep end="|" excludenl end="$" contains=@vimContinue,@vimExprList transparent
@ -977,11 +1019,16 @@ if !exists("skip_vim_syntax_inits")
hi def link vimContinue Special hi def link vimContinue Special
hi def link vimContinueComment vimComment hi def link vimContinueComment vimComment
hi def link vimCtrlChar SpecialChar hi def link vimCtrlChar SpecialChar
hi def link vimDefComment vimComment
hi def link vimDefKey vimCommand
hi def link vimDefParam vimVar
hi def link vimEcho vimCommand hi def link vimEcho vimCommand
hi def link vimEchohlNone vimGroup hi def link vimEchohlNone vimGroup
hi def link vimEchohl vimCommand hi def link vimEchohl vimCommand
hi def link vimElseIfErr Error hi def link vimElseIfErr Error
hi def link vimElseif vimCondHL hi def link vimElseif vimCondHL
hi def link vimEndfunction vimCommand
hi def link vimEnddef vimCommand
hi def link vimEnvvar PreProc hi def link vimEnvvar PreProc
hi def link vimError Error hi def link vimError Error
hi def link vimEscape Special hi def link vimEscape Special
@ -992,8 +1039,13 @@ if !exists("skip_vim_syntax_inits")
hi def link vimFor vimCommand hi def link vimFor vimCommand
hi def link vimFTCmd vimCommand hi def link vimFTCmd vimCommand
hi def link vimFTOption vimSynType hi def link vimFTOption vimSynType
hi def link vimFuncBang vimBang
hi def link vimFuncComment vimComment
hi def link vimFuncKey vimCommand hi def link vimFuncKey vimCommand
hi def link vimFuncName Function hi def link vimFuncName Function
hi def link vimFuncMod Special
hi def link vimFuncParam vimVar
hi def link vimFuncParamEquals vimOper
hi def link vimFuncSID Special hi def link vimFuncSID Special
hi def link vimFuncVar Identifier hi def link vimFuncVar Identifier
hi def link vimGroupAdd vimSynOption hi def link vimGroupAdd vimSynOption