Monaco-editor: YAML syntax highlighting and red escaped characters

Created on 13 Sep 2018  路  16Comments  路  Source: microsoft/monaco-editor

monaco-editor version: 0.13.1
Browser: Chrome, any
OS: Windows 10

YAML language syntax highlighting applies a red color to all charaters preceded by '\'. Presumably, this is to indicate any escaped character (valid or invalid?) but it's getting applied for all cases in both double quotes (where escaping should apply) and single quotes (where escaping should not apply). This is particularly noticeable in single-quoted file paths where escaping should not apply with the '\' path separator.

Comparing Monaco to VS Code:

VS Code correctly applies different colors to valid (normal dark red string color) and invalid (bright red) only to escaped characters within double quotes:
image

Monaco incorrectly highlights every character following '\' whether in single or double quotes:
image

bug good first issue help wanted monaco-languages

All 16 comments

This would be a good opportunity for a first pull request.

The Monarch tokenizer is implemented here -- https://github.com/Microsoft/monaco-languages/blob/0aea831f058968319b8084421ce948e43fc1e969/src/yaml/yaml.ts#L159-L170 --

@alexandrudima is this issue still available? I would like to work on this

How to run it in my local machine to check the editor?

@arshadkazmi42 , to test your changes you probably need to run Monaco editor as AMD or ESM version as described here with your updated version of monaco-languages package that you can generate and install locally without publishing. Let me know if you still working on this issue else I will pick it up.

@rsemenov Thank you for the documentation. I will be working on it.

@rsemenov I am a bit busy for few days. You can take it up if you want.

@rsemenov : hi, are you working on this issue? If not, I鈥檇 like to fix this.

@nalinbhardwaj, it is in my queue, but you can pick it up.

I have submitted a pull request :)

@grzegorz-wcislo : I think you missed on fixing the part of the issue where in double quoted strings characters like "\m" are highlighted as invalid as well(the comment has a screenshot with an example of it)?

@rsemenov / @alexandrudima : since this issue was already fixed, I'd love to help contribute to the project if you have any other good starter issues in mind. Let me know of any. :)

@nalinbhardwaj Incorrect excapes are recognized as such, but I don't know where is the code resonsible for styling. If you know where it is you can fix it :smile: or message me

has the issue been fixed?

the reason why invalid escape characters have the same foreground color as valid ones is that neither 'string.escape' nor 'string.escape.invalid' are defined in default vscode themes (themes.ts) . And in both cases token theme parser returns default color. With proper schema these will be solved. So I think this issue can be closed now. @grzegorz-wcislo, thanks for the fix.

@alexandrudima , is it worth adding 'string.escape' and 'string.escape.invalid' to the default themes? Looks like multiple languages that use these tokens can benefit from it.

OCR text content:

variables:
  escDoubleQuotes: "path\to\my\solution.sln \t \n \a \x \c \\"
  escSingleQuotes: 'path\to\my\solution.sln \t \n \a \x \c \\'

This has actually been fixed in the meantime:

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Raathigesh picture Raathigesh  路  41Comments

lidermanrony picture lidermanrony  路  19Comments

fzafiroski picture fzafiroski  路  21Comments

NikGovorov picture NikGovorov  路  92Comments

gynet picture gynet  路  22Comments