AL icon indicating copy to clipboard operation
AL copied to clipboard

`Case` inside `"Quoted Identifier"` is syntax-highlighted as `case` keyword and start of block. Ditto `begin`, `end`, etc.?

Open dzzzb opened this issue 2 years ago • 8 comments

TSIA really:

image

image

Name: AL Language
Id: ms-dynamics-smb.al
Description: AL development tools for Dynamics 365 Business Central
Version: 9.0.615906
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-dynamics-smb.al

dzzzb avatar May 13 '22 08:05 dzzzb

Try enabling semantic highlighting https://youtu.be/cTc0kYFsAr0?t=312

NKarolak avatar May 13 '22 13:05 NKarolak

It was already enabled: image

dzzzb avatar May 13 '22 13:05 dzzzb

Not sure whether this may make a difference, but set it up for AL Language only (as shown in the video with time stamp). And I am assuming that there is no other setting overriding your user setting?

NKarolak avatar May 13 '22 13:05 NKarolak

Thanks, adding it in an "[AL]" group means I actually get the highlighting, but it doesn't fix the issue with case.

Trying a couple more, it looks like some other keywords are affected by this too, e.g. begin and end. Probably there is just missing code to stop trying to highlight anything specially within identifiers.

image

dzzzb avatar May 16 '22 09:05 dzzzb

I can confirm this issue. I am having the exact same problem with Quted identifiers like "begin", "end", "case" etc.

meilel avatar May 17 '22 08:05 meilel

It is there because with the latest version of VSCode the setting "editor.bracketPairColorization.enabled" is enabled by default. As a mitigation you should disable it in settings.

thpeder avatar May 17 '22 09:05 thpeder

Sure, thanks - but is there a way that al.configuration.json can define what a "quoted identifier" is and then use "notIn" to avoid highlighting such words within identifiers?

dzzzb avatar May 17 '22 09:05 dzzzb

Since my duplicate issue (#7213) got closed, I will ask it here. Is there a plan to fix this issue in the near future?

gntpet avatar Oct 13 '22 10:10 gntpet

Unfortunately, this is a bug in VSCode's bracket colorization feature and AL and we can't fix it on the AL side. VSCode has not considered the case that a bracket keyword may also be a word that is part of a language's syntax.

Begin and end are identified as brackets in al.configuration.json. From what I could figure out the colorization feature considers that only two kinds of code ranges should not have colorization on brackets, comments and strings. AL identifiers inside "" are neither of the two. At the same time, they are defined inside the grammar of the language which is why if you use a keyword inside a quoted identifier it will not appear highlighted.

image

There is no option to define that brackets should not be recognized in other syntax, so we can't override the behavior.

Here's a funny example where I've said that {"codeunit", "report"} is a bracket pair. VSCode is not smart enough to figure out that codeunit by itself is a language keyword and not a bracket: image

Thus there are two options:

  1. Remove begin/end from brackets and thus remove support for bracket colors for these keywords altogether.
  2. Accept this bug can't be fixed on our side and file a bug on VSCode so that they don't highlight syntax elements defined in the language grammar.

Since "begin" and "end" are much more rarely used inside quoted identifier as compared to brackets, I think we can go with option 2 and depend on VSCode to make the feature a bit smarter.

BazookaMusic avatar Nov 23 '22 15:11 BazookaMusic

@BazookaMusic Thanks for the investigation and write-up! Are the AL team going to file the bug with VSC?

dzzzb avatar Nov 23 '22 15:11 dzzzb

I have created the issue here: https://github.com/microsoft/vscode/issues/167062

BazookaMusic avatar Nov 23 '22 15:11 BazookaMusic

Many thanks!

dzzzb avatar Nov 23 '22 15:11 dzzzb