fix: Syntax highlighting broken for variable declarations with type annotations#234
Merged
Conversation
Contributor
|
ya, makes sense. thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-variablerule insyntaxes/nushell.tmLanguage.jsonnow accepts an optional type annotation and delegates the type part to the existing#typesrepository.Background Information
matchonly covered declarations without a type annotation. When one was present, the rule failed to match and the line fell through to thecommandrule (let/mut/constare builtins), wherename:andtypewere picked up by thestring-barefallback — hence the string color.#typesrepository, the same way#function-parameterand#function-inoutalready handle type annotations. This keepslist<...>,record<...>etc. consistent between variable declarations and function signatures.[^=]+?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.:(capture 3) is scoped aspunctuation.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: