Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax highlighting for block scalars incorrectly highlights invalid strings #26

Open
Tracked by #1
heaths opened this issue Jul 13, 2018 · 10 comments
Open
Tracked by #1

Comments

@heaths
Copy link

heaths commented Jul 13, 2018

According to http://yaml.org/spec/1.2/spec.html#id2795688, any string therein should be literal and cannot be escaped; however, VSCode shows all strings having errors or otherwise incorrect. These cannot be quoted, or the quotes will - as spec'd - end up in the VSTS tasks (see screenshot).

image

This is generated from the following YAML (which GitHub highlights correctly):

testAssemblyVer2: |
  **\$(BuildConfiguration)\*mocks*.dll
  **\$(BuildConfiguration)\*test*.dll
  **\$(BuildConfiguration)\Win32\*test*.dll
  !**\obj\**

Folded blocks have a similar problem:

packagesToPush: >
  $(Build.SourcesDirectory)\**\*.nupkg;
  !**\*.symbols.nupkg;
  !**\packages\**\*.nupkg;

...yields:

image

Seems any text within literal or folded blocks should be treated as plain strings,

Copied from original VSCode issue 54219.

@heaths
Copy link
Author

heaths commented Jul 13, 2018

Using the TM inspector in VSCode, it seems the problem is the end matching immediately, leaving the remaining lines to be detected as variables and metas - which would be invalid as unquoted. I just started exploring the TM grammar and it seems a way to solve this requires knowing how much space begin the entire block and ending when exactly that much space before non-whitespace is matched again. Such a regex would be the new end. Is this possible? Perhaps by using named capture groups?

@infininight
Copy link
Member

I have tracked down the cause of this but it is not currently possible to fix due to a limitation in the grammar parser. We are investigating if/how this can be addressed in the parser.

@Tronic
Copy link

Tronic commented Aug 20, 2019

It is possible to use captured groups in while/end regex: (tested in VSCode)

"begin": "^(\\s*)(\\w*): |$",
"while": "^\\1\\s+",

I see that TextMate and Github highlighter already have a working version for YAML but VSCode doesn't. This might also be of interest to anyone else wishing to implement string literals by indentation...

@heaths
Copy link
Author

heaths commented Aug 20, 2019

@aeschli, would it be possible (I could even do it if you like) to use this workaround rather than wait for TextMate to otherwise fix this? Any way to denote that the generated files require a tweak or two like this?

@aeschli
Copy link

aeschli commented Aug 21, 2019

@heaths As a first step I suggest to make a PR against this repo.

@Tronic
Copy link

Tronic commented Aug 21, 2019

This is already fixed in TextMate (tested in version 2.0-rc.23). Github uses https://github.com/atom/language-yaml/blob/master/grammars/yaml.cson which also works. I don't know if VSCode supports the CSON format but it should be trivially convertible to VSCode-compatible JSON.

@heaths
Copy link
Author

heaths commented Aug 21, 2019

@aeschli, that being the case (this is already fixed in TextMate as @Tronic said), you pulling and transforming source should work now for VSCode, correct?

@aeschli
Copy link

aeschli commented Aug 22, 2019

Please create an issue in the vscode repo so we can find out why this works in TextMate but not in VSCode and whether VSCode should switch to a different grammar.

@heaths
Copy link
Author

heaths commented Aug 22, 2019

Will do, but I don't think anyone is saying this wouldn't work in VSCode - only that someone found a workaround and that this was fixed in TextMate recentlyish.

@dfenerski
Copy link

uhhh seems still open? "unexpected scalar at node end yaml vscode" led me to this issue

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

No branches or pull requests

5 participants