From 22f6b9d11fbe19c1ac2125d83e220ac40831ddbc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 29 Sep 2025 09:14:19 +0800 Subject: [PATCH] vim-patch:72473ce: runtime(vim): Update base syntax, match generic functions Match Vim9 generic functions, added in vim/vim#17313. closes: vim/vim#17722 https://github.com/vim/vim/commit/72473ce9f8e111072360a7589e2c5bee079305da Co-authored-by: Doug Kearns --- runtime/syntax/vim.vim | 68 ++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim index ec4c644bb8..33133f4335 100644 --- a/runtime/syntax/vim.vim +++ b/runtime/syntax/vim.vim @@ -257,6 +257,8 @@ syn match vimVimVar "\\|[bwglstav]:\)\=\%([[:alnum:]_#.]\+\|{.\{-1,}}\)\+" - \ nextgroup=vimDefParams,vimCmdSep,vimComment,vim9Comment + \ nextgroup=vimDefTypeParams,vimDefParams,vimCmdSep,vimComment,vim9Comment \ contains=vimFunctionError,vimFunctionScope,vimFunctionSID,Tag syn match vimFunction "\" skipwhite nextgroup=vimFunctionBang,vimFunctionName,vimFunctionPattern,vimCmdSep,vimComment @@ -492,8 +494,15 @@ syn region vimDefParams contained \ end=")" \ skipwhite skipempty nextgroup=vimDefBody,vimDefComment,vimEnddef,vimReturnType,vimCommentError \ contains=vimDefParam,vim9Comment,vimFunctionParamEquals,vimOperParen +syn region vimDefTypeParams contained + \ matchgroup=Delimiter + \ start="<" + \ end=">" + \ nextgroup=vimDefParams + \ contains=vim9DefTypeParam syn match vimFunctionParam contained "\<\h\w*\>\|\.\.\." skipwhite nextgroup=vimFunctionParamEquals syn match vimDefParam contained "\<\h\w*\>" skipwhite nextgroup=vimParamType,vimFunctionParamEquals +syn match vim9DefTypeParam contained "\<\u\w*\>" syn match vimFunctionParamEquals contained "=" skipwhite nextgroup=@vimExprList syn match vimFunctionMod contained "\<\%(abort\|closure\|dict\|range\)\>" skipwhite skipempty nextgroup=vimFunctionBody,vimFunctionComment,vimEndfunction,vimFunctionMod,vim9CommentError @@ -525,7 +534,7 @@ if exists("g:vimsyn_folding") && g:vimsyn_folding =~# 'f' syn region vimDefFold \ start="\" skipwhite nextgroup=vim9MethodDefName,vim9ConstructorDefName - syn match vim9MethodDefName contained "\<\h\w*\>" nextgroup=vim9MethodDefParams contains=@vim9MethodName + syn match vim9MethodDefName contained "\<\h\w*\>" nextgroup=vim9MethodDefParams,vim9MethodDefTypeParams contains=@vim9MethodName syn region vim9MethodDefParams contained \ matchgroup=Delimiter start="(" end=")" \ skipwhite skipnl nextgroup=vim9MethodDefBody,vim9MethodDefComment,vimEnddef,vim9MethodDefReturnType,vimCommentError \ contains=vimDefParam,vim9Comment,vimFunctionParamEquals + syn region vim9MethodDefTypeParams contained + \ matchgroup=Delimiter + \ start="<" + \ end=">" + \ nextgroup=vim9MethodDefParams + \ contains=vim9DefTypeParam syn match vim9ConstructorDefName contained "\<_\=new\w*\>" - \ nextgroup=vim9ConstructorDefParams + \ nextgroup=vim9ConstructorDefParams,vim9ConstuctorDefTypeParams \ contains=@vim9MethodName syn match vim9ConstructorDefParam contained "\<\%(this\.\)\=\h\w*\>" \ skipwhite nextgroup=vimParamType,vimFunctionParamEquals @@ -583,6 +598,12 @@ if s:vim9script \ matchgroup=Delimiter start="(" end=")" \ skipwhite skipnl nextgroup=vim9MethodDefBody,vim9MethodDefComment,vimEnddef,vimCommentError \ contains=vim9ConstructorDefParam,vim9Comment,vimFunctionParamEquals + syn region vim9ConstuctorDefTypeParams contained + \ matchgroup=Delimiter + \ start="<" + \ end=">" + \ nextgroup=vim9ConstructorDefParams + \ contains=vim9DefTypeParam syn region vim9MethodDefReturnType contained \ start=":\%(\s\|\n\)\@=" @@ -616,8 +637,11 @@ if s:vim9script 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 + syn region vim9MethodDefFold contained + \ start="\%(^\s*\%(:\=static\s\+\)\=\)\@16<=:\=def\s\+\h\w*[<(]" + \ end="^\s*:\=enddef\>" + \ contains=vim9MethodDef + \ fold keepend extend transparent endif syn cluster vim9MethodDef contains=vim9MethodDef,vim9MethodDefFold @@ -697,7 +721,7 @@ if s:vim9script 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 match vim9AbstractDefName contained "\<\h\w*\>" skipwhite nextgroup=vim9AbstractDefParams,vim9AbstractDefTypeParams contains=@vim9MethodName syn region vim9AbstractDefParams contained \ matchgroup=Delimiter start="(" end=")" \ skipwhite skipnl nextgroup=vimDefComment,vim9AbstractDefReturnType,vimCommentError @@ -707,6 +731,12 @@ if s:vim9script \ skipwhite skipnl nextgroup=vimDefComment,vimCommentError \ contains=vimTypeSep \ transparent + syn region vim9AbstractDefTypeParams contained + \ matchgroup=Delimiter + \ start="<" + \ end=">" + \ nextgroup=vim9AbstractDefParams + \ contains=vim9DefTypeParam VimFoldi syn region vim9InterfaceBody start="\" matchgroup=vimCommand end="\" contains=@vim9InterfaceBodyList transparent @@ -1444,7 +1474,7 @@ syn match vimBracket contained "[\\<>]" syn case match " User Command Highlighting: {{{2 -syn match vimUsrCmd '^\s*\zs\u\%(\w*\)\@>\%([.(#[]\|\s\+\%([-+*/%]\=\|\.\.\)=\)\@!' +syn match vimUsrCmd '^\s*\zs\u\%(\w*\)\@>\%([<.(#[]\|\s\+\%([-+*/%]\=\|\.\.\)=\)\@!' " Vim user commands @@ -2115,18 +2145,26 @@ unlet s:interfaces " Function Call Highlighting: {{{2 " (following Gautam Iyer's suggestion) " ========================== -syn match vimFunc contained "\<\l\w*\ze\s*(" skipwhite nextgroup=vimOperParen contains=vimFuncName -syn match vimUserFunc contained "\.\@1<=\l\w*\ze\s*(" skipwhite nextgroup=vimOperParen -syn match vimUserFunc contained "\<\%([[:upper:]_]\|\%(\h\w*\.\)\+\h\)\w*\ze\s*(" skipwhite nextgroup=vimOperParen contains=vim9MethodName,vim9Super,vim9This -syn match vimUserFunc contained "\<\%(g:\)\=\%(\h\w*#\)\+\h\w*\ze\s*(" skipwhite nextgroup=vimOperParen contains=vimVarScope -syn match vimUserFunc contained "\%(\<[sgbwtlav]:\|<[sS][iI][dD]>\)\%(\h\w*\.\)*\h\w*\ze\s*(" skipwhite nextgroup=vimOperParen contains=vimVarScope,vimNotation +syn match vimFunc contained "\<\l\w*\ze\s*(" skipwhite nextgroup=vimOperParen contains=vimFuncName +syn match vimUserFunc contained "\.\@1<=\l\w*\ze\%(\s*(\|<.*>(\)" skipwhite nextgroup=vimOperParen,vim9TypeArgs +syn match vimUserFunc contained "\<\%([[:upper:]_]\|\%(\h\w*\.\)\+\h\)\w*\ze\%(\s*(\|<.*>(\)" skipwhite nextgroup=vimOperParen,vim9TypeArgs contains=vim9MethodName,vim9Super,vim9This +syn match vimUserFunc contained "\<\%(g:\)\=\%(\h\w*#\)\+\h\w*\ze\%(\s*(\|<.*>(\)" skipwhite nextgroup=vimOperParen contains=vimVarScope +syn match vimUserFunc contained "\%(\<[sgbwtlav]:\|<[sS][iI][dD]>\)\%(\h\w*\.\)*\h\w*\ze\%(\s*(\|<.*>(\)" skipwhite nextgroup=vimOperParen,vim9TypeArgs contains=vimVarScope,vimNotation -Vim9 syn match vim9UserFunc "^\s*\zs\%([sgbwtv]:\|<[sS][iI][dD]>\)\=\%(\h\w*[.#]\)*\h\w*\ze(" skipwhite nextgroup=vimOperParen contains=vimVarScope,vimNotation,vim9MethodName,vim9Super,vim9This -Vim9 syn match vim9Func "^\s*\zs\l\w*\ze(" skipwhite nextgroup=vimOperParen contains=vimFuncName +Vim9 syn match vim9UserFunc "^\s*\zs\%([sgbwtv]:\|<[sS][iI][dD]>\)\=\%(\h\w*[.#]\)*\h\w*\ze[<(]" skipwhite nextgroup=vimOperParen,vim9TypeArgs contains=vimVarScope,vimNotation,vim9MethodName,vim9Super,vim9This +Vim9 syn match vim9Func "^\s*\zs\l\w*\ze(" skipwhite nextgroup=vimOperParen contains=vimFuncName syn cluster vimFunc contains=vimFunc,vimUserFunc syn cluster vim9Func contains=vim9Func,vim9UserFunc +syn region vim9TypeArgs contained + \ matchgroup=Delimiter + \ start="<\ze\a" + \ end=">" + \ nextgroup=vimOperParen + \ contains=@vimType + \ oneline + " Beginners - Patterns that involve ^ {{{2 " ========= Vim9 syn region vim9LineComment start=+^[ \t:]*\zs#.*$+ skip=+\n\s*\\\|\n\s*#\\ + end="$" contains=@vimCommentGroup,vimCommentString,vim9CommentTitle extend