vim-patch:3dca512: runtime(vim): Update base-syntax and generator, only match valid predefined variables

- Only match valid predefined and option variables.
- Match scope dictionaries.
- Highlight scope prefixed variables as a scope dictionary accessor. The
  vimVarScope syntax group can be linked to vimVar to disable this.
- Include support for Neovim-only predefined and option variables.

Temporary collateral damage - scope dictionaries match instead of keys
in dictionary literals.

closes: vim/vim#16727

3dca512939

Co-authored-by: Doug Kearns <dougkearns@gmail.com>
This commit is contained in:
zeertzjq
2025-04-18 14:09:22 +08:00
parent 118759aa6b
commit 8e5ef60540
2 changed files with 64 additions and 21 deletions

View File

@@ -8,15 +8,23 @@
" ############################################################################# " #############################################################################
" ############################################################################# " #############################################################################
" Quit when a syntax file was already loaded {{{2 " Quit when a syntax file was already loaded {{{1
if exists("b:current_syntax") if exists("b:current_syntax")
finish finish
endif endif
let s:keepcpo = &cpo let s:keepcpo = &cpo
set cpo&vim set cpo&vim
" Feature testing {{{1
let s:vim9script = "\n" .. getline(1, 32)->join("\n") =~# '\n\s*vim9\%[script]\>' let s:vim9script = "\n" .. getline(1, 32)->join("\n") =~# '\n\s*vim9\%[script]\>'
function s:has(feature)
return has(a:feature) || index(get(g:, "vimsyn_vim_features", []), a:feature) != -1
endfunction
" Automatically generated keyword lists: {{{1
" vimTodo: contains common special-notices for comments {{{2 " vimTodo: contains common special-notices for comments {{{2
" Use the vimCommentGroup cluster to add your own. " Use the vimCommentGroup cluster to add your own.
syn keyword vimTodo contained COMBAK FIXME TODO XXX syn keyword vimTodo contained COMBAK FIXME TODO XXX
@@ -29,10 +37,8 @@ syn keyword vimStdPlugin contained Arguments Asm Break Cfilter Clear Continue Di
" Vim-specific options {{{2 " Vim-specific options {{{2
syn keyword vimOnlyOption contained biosk bioskey cp compatible consk conskey cm cryptmethod edcompatible guipty key macatsui mzq mzquantum osfiletype oft renderoptions rop st shelltype sn shortname tenc termencoding ta textauto tx textmode tf ttyfast ttym ttymouse tbi ttybuiltin wiv weirdinvert syn keyword vimOnlyOption contained biosk bioskey cp compatible consk conskey cm cryptmethod edcompatible guipty key macatsui mzq mzquantum osfiletype oft renderoptions rop st shelltype sn shortname tenc termencoding ta textauto tx textmode tf ttyfast ttym ttymouse tbi ttybuiltin wiv weirdinvert
" Turn-off setting variants " Turn-off setting variants
syn keyword vimOnlyOption contained nobiosk nobioskey noconsk noconskey nocp nocompatible noguipty nomacatsui nosn noshortname nota notextauto notx notextmode notf nottyfast notbi nottybuiltin nowiv noweirdinvert syn keyword vimOnlyOption contained nobiosk nobioskey noconsk noconskey nocp nocompatible noguipty nomacatsui nosn noshortname nota notextauto notx notextmode notf nottyfast notbi nottybuiltin nowiv noweirdinvert
" Invertible setting variants " Invertible setting variants
syn keyword vimOnlyOption contained invbiosk invbioskey invconsk invconskey invcp invcompatible invguipty invmacatsui invsn invshortname invta invtextauto invtx invtextmode invtf invttyfast invtbi invttybuiltin invwiv invweirdinvert syn keyword vimOnlyOption contained invbiosk invbioskey invconsk invconskey invcp invcompatible invguipty invmacatsui invsn invshortname invta invtextauto invtx invtextmode invtf invttyfast invtbi invttybuiltin invwiv invweirdinvert
" termcap codes (which can also be set) {{{2 " termcap codes (which can also be set) {{{2
@@ -49,6 +55,19 @@ syn match vimTermOption contained "t_&8"
syn match vimTermOption contained "t_%i" syn match vimTermOption contained "t_%i"
syn match vimTermOption contained "t_k;" syn match vimTermOption contained "t_k;"
" vimOptions: These are the variable names {{{2
" GEN_SYN_VIM: vimOption term output code variable, START_STR='syn keyword vimOptionVarName contained', END_STR=''
syn keyword vimOptionVarName contained t_AB t_AF t_AU t_AL t_al t_bc t_BE t_BD t_cd t_ce t_Ce t_CF t_cl t_cm t_Co t_CS t_Cs t_cs t_CV t_da t_db t_DL t_dl t_ds t_Ds t_EC t_EI t_fs t_fd t_fe t_GP t_IE t_IS t_ke t_ks t_le t_mb t_md t_me t_mr t_ms t_nd t_op t_RF t_RB t_RC t_RI t_Ri t_RK t_RS t_RT t_RV t_Sb t_SC t_se t_Sf t_SH t_SI t_Si t_so t_SR t_sr t_ST t_Te t_te t_TE t_ti t_TI t_Ts t_ts t_u7 t_ue t_us t_Us t_ut t_vb t_ve t_vi t_VS t_vs t_WP t_WS t_XM t_xn t_xs t_ZH t_ZR t_8f t_8b t_8u t_xo
syn keyword vimOptionVarName contained t_F1 t_F2 t_F3 t_F4 t_F5 t_F6 t_F7 t_F8 t_F9 t_k1 t_K1 t_k2 t_k3 t_K3 t_k4 t_K4 t_k5 t_K5 t_k6 t_K6 t_k7 t_K7 t_k8 t_K8 t_k9 t_K9 t_KA t_kb t_kB t_KB t_KC t_kd t_kD t_KD t_KE t_KF t_KG t_kh t_KH t_kI t_KI t_KJ t_KK t_kl t_KL t_kN t_kP t_kr t_ku
syn match vimOptionVarName contained "t_%1"
syn match vimOptionVarName contained "t_#2"
syn match vimOptionVarName contained "t_#4"
syn match vimOptionVarName contained "t_@7"
syn match vimOptionVarName contained "t_*7"
syn match vimOptionVarName contained "t_&8"
syn match vimOptionVarName contained "t_%i"
syn match vimOptionVarName contained "t_k;"
" unsupported settings: these are supported by vi but don't do anything in vim {{{2 " unsupported settings: these are supported by vi but don't do anything in vim {{{2
" GEN_SYN_VIM: Missing vimOption, START_STR='syn keyword vimErrSetting contained', END_STR='' " GEN_SYN_VIM: Missing vimOption, START_STR='syn keyword vimErrSetting contained', END_STR=''
syn keyword vimErrSetting contained akm altkeymap anti antialias ap autoprint bf beautify biosk bioskey consk conskey fk fkmap fl flash gr graphic ht hardtabs macatsui mesg novice open opt optimize oft osfiletype redraw slow slowopen sourceany w1200 w300 w9600 syn keyword vimErrSetting contained akm altkeymap anti antialias ap autoprint bf beautify biosk bioskey consk conskey fk fkmap fl flash gr graphic ht hardtabs macatsui mesg novice open opt optimize oft osfiletype redraw slow slowopen sourceany w1200 w300 w9600
@@ -206,14 +225,17 @@ syn match vimBang contained "!"
syn region vimSubscript contained matchgroup=vimSubscriptBracket start="\[" end="]" nextgroup=vimSubscript contains=@vimExprList syn region vimSubscript contained matchgroup=vimSubscriptBracket start="\[" end="]" nextgroup=vimSubscript contains=@vimExprList
syn match vimVar contained "\<\h[a-zA-Z0-9#_]*\>" nextgroup=vimSubscript contains=vim9Super,vim9This syn match vimVar contained "\<\h[a-zA-Z0-9#_]*\>" nextgroup=vimSubscript contains=vim9Super,vim9This
syn match vimVar "\<[bwglstav]:\h[a-zA-Z0-9#_]*\>" nextgroup=vimSubscript syn match vimVar "\<[bwglstav]:\h[a-zA-Z0-9#_]*\>" nextgroup=vimSubscript contains=vimVarScope
syn match vimVar "\<a:\%(000\|\d\+\)\>" nextgroup=vimSubscript syn match vimVar "\<a:\%(000\|1\=[0-9]\|20\)\>" nextgroup=vimSubscript contains=vimVarScope
syn match vimFBVar contained "\<[bwglsta]:\h[a-zA-Z0-9#_]*\>" nextgroup=vimSubscript syn match vimFBVar contained "\<[bwglsta]:\h[a-zA-Z0-9#_]*\>" nextgroup=vimSubscript contains=vimVarScope
syn match vimVimVar "\<v:\h\w*\>" nextgroup=vimSubscript " match the scope prefix independently of the retrofitted scope dictionary
syn match vimOptionVar "&\%([lg]:\)\=\a\+\>" nextgroup=vimSubscript syn match vimVarScope contained "\<[bwglstav]:"
syn match vimOptionVar "&t_\S[a-zA-Z0-9]\>" nextgroup=vimSubscript syn match vimVimVar contained "\<[bwglstav]:\%(\h\|\d\)\@!" nextgroup=vimSubscript
syn match vimOptionVar "&t_k;" nextgroup=vimSubscript
syn match vimVarNameError contained "\<\h\w*\>"
syn match vimVimVar "\<v:" nextgroup=vimSubscript,vimVimVarName,vimVarNameError
syn match vimOptionVar "&\%([lg]:\)\=" nextgroup=vimSubscript,vimOptionVarName,vimVarNameError
syn cluster vimSpecialVar contains=vimEnvvar,vimLetRegister,vimOptionVar,vimVimVar syn cluster vimSpecialVar contains=vimEnvvar,vimLetRegister,vimOptionVar,vimVimVar
Vim9 syn match vim9LhsVariable "\s\=\h[a-zA-Z0-9#_]*\ze\s\+[-+/*%]\==" Vim9 syn match vim9LhsVariable "\s\=\h[a-zA-Z0-9#_]*\ze\s\+[-+/*%]\=="
@@ -734,7 +756,7 @@ syn match vimUnletBang contained "\a\@1<=!" skipwhite nextgroup=vimUnletVars
syn region vimUnletVars contained syn region vimUnletVars contained
\ start="$\I\|\h" skip=+\n\s*\\\|\n\s*"\\ \|^\s*"\\ + end="$" end="\ze[|"]" \ start="$\I\|\h" skip=+\n\s*\\\|\n\s*"\\ \|^\s*"\\ + end="$" end="\ze[|"]"
\ nextgroup=vimCmdSep,vimComment \ nextgroup=vimCmdSep,vimComment
\ contains=@vimContinue,vimEnvvar,vimVar \ contains=@vimContinue,vimEnvvar,vimVar,vimVimVar
VimFoldh syn region vimLetHereDoc matchgroup=vimLetHereDocStart start='\%(^\z(\s*\)\S.*\)\@<==<<\s*trim\%(\s\+\)\@>\z(\L\S*\)' matchgroup=vimLetHereDocStop end='^\z1\=\z2$' extend VimFoldh syn region vimLetHereDoc matchgroup=vimLetHereDocStart start='\%(^\z(\s*\)\S.*\)\@<==<<\s*trim\%(\s\+\)\@>\z(\L\S*\)' matchgroup=vimLetHereDocStop end='^\z1\=\z2$' extend
VimFoldh syn region vimLetHereDoc matchgroup=vimLetHereDocStart start='=<<\%(\s*\)\@>\z(\L\S*\)' matchgroup=vimLetHereDocStop end='^\z1$' extend VimFoldh syn region vimLetHereDoc matchgroup=vimLetHereDocStart start='=<<\%(\s*\)\@>\z(\L\S*\)' matchgroup=vimLetHereDocStop end='^\z1$' extend
@@ -1457,7 +1479,7 @@ if !exists("skip_vim_syntax_inits")
hi def link vimFuncMod Special hi def link vimFuncMod Special
hi def link vimFuncParam vimVar hi def link vimFuncParam vimVar
hi def link vimFuncParamEquals vimOper hi def link vimFuncParamEquals vimOper
hi def link vimFuncScope vimVar hi def link vimFuncScope vimVarScope
hi def link vimFuncSID vimNotation hi def link vimFuncSID vimNotation
hi def link vimGroupAdd vimSynOption hi def link vimGroupAdd vimSynOption
hi def link vimGroupName vimGroup hi def link vimGroupName vimGroup
@@ -1528,7 +1550,7 @@ if !exists("skip_vim_syntax_inits")
hi def link vimOperContinueComment vimContinueComment hi def link vimOperContinueComment vimContinueComment
hi def link vimOption PreProc hi def link vimOption PreProc
hi def link vimOptionVar Identifier hi def link vimOptionVar Identifier
hi def link vimVimVar Identifier hi def link vimOptionVarName Identifier
hi def link vimParenSep Delimiter hi def link vimParenSep Delimiter
hi def link vimPatSepErr vimError hi def link vimPatSepErr vimError
hi def link vimPatSepR vimPatSep hi def link vimPatSepR vimPatSep
@@ -1612,6 +1634,9 @@ if !exists("skip_vim_syntax_inits")
hi def link vimUserCmdKey vimCommand hi def link vimUserCmdKey vimCommand
hi def link vimUserFunc Normal hi def link vimUserFunc Normal
hi def link vimVar Normal hi def link vimVar Normal
hi def link vimVarScope Identifier
hi def link vimVimVar Identifier
hi def link vimVimVarName Identifier
hi def link vimWarn WarningMsg hi def link vimWarn WarningMsg
hi def link vim9Abstract vimCommand hi def link vim9Abstract vimCommand

View File

@@ -4,7 +4,7 @@ local syntax_file = arg[1]
local funcs_file = arg[2] local funcs_file = arg[2]
local lld = {} local lld = {}
local syn_fd = io.open(syntax_file, 'w') local syn_fd = assert(io.open(syntax_file, 'w'))
lld.line_length = 0 lld.line_length = 0
local function w(s) local function w(s)
syn_fd:write(s) syn_fd:write(s)
@@ -18,6 +18,7 @@ end
local options = require('nvim.options') local options = require('nvim.options')
local auevents = require('nvim.auevents') local auevents = require('nvim.auevents')
local ex_cmds = require('nvim.ex_cmds') local ex_cmds = require('nvim.ex_cmds')
local vvars = require('nvim.vvars')
local function cmd_kw(prev_cmd, cmd) local function cmd_kw(prev_cmd, cmd)
if not prev_cmd then if not prev_cmd then
@@ -54,7 +55,6 @@ end
local vimcmd_start = 'syn keyword vimCommand contained ' local vimcmd_start = 'syn keyword vimCommand contained '
local vimcmd_end = ' nextgroup=vimBang' local vimcmd_end = ' nextgroup=vimBang'
w(vimcmd_start) w(vimcmd_start)
local prev_cmd = nil local prev_cmd = nil
for _, cmd_desc in ipairs(ex_cmds.cmds) do for _, cmd_desc in ipairs(ex_cmds.cmds) do
if lld.line_length > 850 then if lld.line_length > 850 then
@@ -80,13 +80,11 @@ for _, cmd_desc in ipairs(ex_cmds.cmds) do
end end
prev_cmd = cmd prev_cmd = cmd
end end
w(vimcmd_end .. '\n') w(vimcmd_end .. '\n')
local vimopt_start = 'syn keyword vimOption contained ' local vimopt_start = 'syn keyword vimOption contained '
local vimopt_end = ' skipwhite nextgroup=vimSetEqual,vimSetMod' local vimopt_end = ' skipwhite nextgroup=vimSetEqual,vimSetMod'
w('\n' .. vimopt_start) w('\n' .. vimopt_start)
for _, opt_desc in ipairs(options.options) do for _, opt_desc in ipairs(options.options) do
if not opt_desc.immutable then if not opt_desc.immutable then
if lld.line_length > 850 then if lld.line_length > 850 then
@@ -106,13 +104,25 @@ for _, opt_desc in ipairs(options.options) do
end end
end end
end end
w(vimopt_end .. '\n') w(vimopt_end .. '\n')
w('\nsyn case ignore') local vimoptvar_start = 'syn keyword vimOptionVarName contained '
w('\n' .. vimoptvar_start)
for _, opt_desc in ipairs(options.options) do
if not opt_desc.immutable then
if lld.line_length > 850 then
w('\n' .. vimoptvar_start)
end
w(' ' .. opt_desc.full_name)
if opt_desc.abbreviation then
w(' ' .. opt_desc.abbreviation)
end
end
end
w('\n\nsyn case ignore')
local vimau_start = 'syn keyword vimAutoEvent contained ' local vimau_start = 'syn keyword vimAutoEvent contained '
w('\n\n' .. vimau_start) w('\n\n' .. vimau_start)
for au, _ in vim.spairs(vim.tbl_extend('error', auevents.events, auevents.aliases)) do for au, _ in vim.spairs(vim.tbl_extend('error', auevents.events, auevents.aliases)) do
if not auevents.nvim_specific[au] then if not auevents.nvim_specific[au] then
if lld.line_length > 850 then if lld.line_length > 850 then
@@ -124,7 +134,6 @@ end
local nvimau_start = 'syn keyword nvimAutoEvent contained ' local nvimau_start = 'syn keyword nvimAutoEvent contained '
w('\n\n' .. nvimau_start) w('\n\n' .. nvimau_start)
for au, _ in vim.spairs(auevents.nvim_specific) do for au, _ in vim.spairs(auevents.nvim_specific) do
if lld.line_length > 850 then if lld.line_length > 850 then
w('\n' .. nvimau_start) w('\n' .. nvimau_start)
@@ -145,5 +154,14 @@ for _, name in ipairs(funcs) do
end end
end end
local vimvvar_start = 'syn keyword vimVimVarName contained '
w('\n\n' .. vimvvar_start)
for name, _ in vim.spairs(vvars.vars) do
if lld.line_length > 850 then
w('\n' .. vimvvar_start)
end
w(' ' .. name)
end
w('\n') w('\n')
syn_fd:close() syn_fd:close()