Skip to content

Add Vim9Script support#205

Open
sideshowbarker wants to merge 1 commit intovim-jp:masterfrom
sideshowbarker:vim9script-support
Open

Add Vim9Script support#205
sideshowbarker wants to merge 1 commit intovim-jp:masterfrom
sideshowbarker:vim9script-support

Conversation

@sideshowbarker
Copy link

@sideshowbarker sideshowbarker commented Feb 12, 2026

Summary

  • Parse core Vim9Script constructs into proper AST nodes instead of routing them through parse_cmd_common, so downstream tools can analyze Vim9Script code without errors
  • Add # comment support when vim9script mode is active
  • Fix JS transpiler compile_let heuristic that incorrectly added var prefix to subscript assignments like named[pname] = 1

Motivation

Tools that depend on vim-vimlparser — such as vint and vim-language-server (which vendors the JS output directly) — report unexpected errors on valid Vim9Script code because the parser doesn't recognize constructs like def, typed parameters, or # comments. This adds structured parsing for the core Vim9Script syntax so these tools can handle Vim9Script files correctly.

Details

  • New node types: NODE_VIM9SCRIPT, NODE_DEF, NODE_ENDDEF, NODE_VAR, NODE_FINAL, NODE_EXPORT, NODE_IMPORT.

  • vim9script — sets a mode flag that enables # comments throughout the parser (in parse_one_cmd, parse_command, parse_comment, parse_trail, ends_excmds, separate_nextcmd).

  • def/enddef — parses typed parameters (name: type), default values (name: type = expr), variadic params (...name: type), and return type annotations (: returntype). Reads parameter names directly from the reader rather than using ExprTokenizer, since : is a valid name character in VimL identifiers and would cause x: to be tokenized as a single identifier.

  • var/final — parses variable declarations with optional type annotations. Same direct-reader approach to avoid the : tokenization issue.

  • export — wraps the inner command (def, var, etc.) by delegating to find_command + _parse_command, then moving the resulting nodes into the export node's body.

  • import — captures the import specification as a string.

Fixes #194

Parse core Vim9Script constructs into proper AST nodes so that
downstream tools can analyze Vim9Script code without errors.

New node types: NODE_VIM9SCRIPT, NODE_DEF, NODE_ENDDEF, NODE_VAR,
NODE_FINAL, NODE_EXPORT, NODE_IMPORT.

Parsers for vim9script, def/enddef (with typed parameters, return
types, default values, variadics), var/final (with type annotations),
export (wrapping inner commands), and import.

The # comment syntax is supported when vim9script mode is active.

Also fix JS transpiler heuristic for subscript assignments in
compile_let to check for [ in addition to . when deciding whether
to add var prefix.

Fixes vim-jp#194
@sideshowbarker
Copy link
Author

I started on this before seeing #204. The approach in that PR is clearly a much better solution than this. (I hadn’t even known yet about https://github.com/vim-jp/vim-vim9parser.) But I figured I’d go ahead and raise this anyway — in case it happens to be of any interest, or might be a possible interim solution until #204 gets merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vim9 script support?

1 participant