vim-patch:80aabaa: runtime(vim): Distinguish Vim9 builtin object methods from namesake builtin functions (vim/vim#14348)

Currently, the overriding object method definitions are
matched as vimFunctionError (:help builtin-object-methods,
v9.1.0148).

For example:
------------------------------------------------------------
vim9script

class Test
	def string(): string
		return "Test"
	enddef
endclass

echo string(Test.new()) == Test.new().string()
------------------------------------------------------------

Instead, let's introduce a new syntax group vimMethodName
and make these methods its members.  In order to emphasise
the link between the overriding methods and the overridden
functions for highlighting, vimMethodName is linked by
default to vimFuncName.

80aabaab66

Co-authored-by: Aliaksei Budavei <32549825+zzzyxwvut@users.noreply.github.com>
This commit is contained in:
zeertzjq 2024-11-10 09:56:04 +08:00
parent f25ffc43a7
commit e9dc9be469

View File

@ -274,7 +274,7 @@ syn match vimDef "\<def\>" skipwhite nextgroup=vimCmdSep,vimComment,vimFuncPatt
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 vimDef "\<def\>!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+" contains=@vimDefList,vimMethodName nextgroup=vimDefParams
syn match vimFuncComment contained +".*+ skipwhite skipempty nextgroup=vimFuncBody,vimEndfunction
syn match vimDefComment contained "#.*" skipwhite skipempty nextgroup=vimDefBody,vimEnddef
@ -284,6 +284,7 @@ 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
@ -668,7 +669,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
syn match vimUserFunc contained "\%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%(\w\+\.\)*\I[a-zA-Z0-9_.]*\)\|\<\u[a-zA-Z0-9.]*\>\|\<if\>" contains=vimNotation,vimMethodName
syn keyword vimFuncEcho contained ec ech echo
syn match vimMap "\<map\%(\s\+(\)\@=" skipwhite nextgroup=vimMapBang,vimMapMod,vimMapLhs
@ -680,7 +681,9 @@ syn match vimUsrCmd '^\s*\zs\u\%(\w*\)\@>\%([(#[]\|\s\+\%([-+*/%]\=\|\.\.\)=\)\@
" ====================
if !exists("g:vimsyn_noerror") && !exists("g:vimsyn_novimfunctionerror")
" TODO: The new-prefix exception should only apply to constructor definitions.
syn match vimFunctionError "\s\zs\%(new\)\@![a-z0-9]\i\{-}\ze\s*(" contained contains=vimFuncKey,vimFuncBlank
" 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\%(<[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*)/
@ -1256,6 +1259,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 vimMtchComment vimComment
hi def link vimNorm vimCommand
hi def link vimNotation Special