Skip to content

fix: Syntax highlighting broken for variable declarations with type annotations#234

Merged
fdncred merged 1 commit into
nushell:mainfrom
mst-mkt:main
Jul 5, 2026
Merged

fix: Syntax highlighting broken for variable declarations with type annotations#234
fdncred merged 1 commit into
nushell:mainfrom
mst-mkt:main

Conversation

@mst-mkt

@mst-mkt mst-mkt commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Issue

resolve #233

Summary

This PR fixes an issue where adding a type annotation to a variable declaration (let name: type = ...) caused the variable name and the type to be highlighted as bare strings.
The repository.define-variable rule in syntaxes/nushell.tmLanguage.json now accepts an optional type annotation and delegates the type part to the existing #types repository.

Background Information

  • The previous match only covered declarations without a type annotation. When one was present, the rule failed to match and the line fell through to the command rule (let/mut/const are builtins), where name: and type were picked up by the string-bare fallback — hence the string color.
  • The type part (capture 4) is delegated to the existing #types repository, the same way #function-parameter and #function-inout already handle type annotations. This keeps list<...>, record<...> etc. consistent between variable declarations and function signatures.
  • The type capture [^=]+? is lazy and cannot cross the =, so right-hand sides containing : or == (e.g. let flag: bool = 1 == 2, let f = {|x: int| $x}) are not affected.
  • The : (capture 3) is scoped as punctuation.separator.nushell, which this grammar already uses for the , separators in tables and in-out signatures.

Verification

I verified the change by loading the extension in the VS Code Extension Development Host and confirming that typed declarations are now highlighted the same way as untyped ones and as type annotations in function signatures:

Image

@fdncred

fdncred commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

ya, makes sense. thanks!

@fdncred fdncred merged commit 36b1019 into nushell:main Jul 5, 2026
1 check passed
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.

Syntax highlighting broken for variable declarations with type annotations

2 participants