-
Notifications
You must be signed in to change notification settings - Fork 11
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
First segment of references and object contents mis-highlighted #79
Comments
Hi @scott-doyland-burrows With default VS Code configuration, the same snippet of code gets highlighted a bit differently to me: That said even in my screenshot it looks like something is still off in that the first address segment is highlighted differently when the address is inside a nested block ( Thank you for the report. |
You are correct, it was set to use the terraform extension. I was actually flicking between the two extensions to see the difference and mistakenly submitted the screenshot when the terraform extension was in use. But as you say, something does seem incorrect with the HCL extension - and I see the same as you when I use the correct extension. In your screenshot, the |
Good catch, yes, that could be considered a bug too, which applies to all references - we can look into both at the same time - i.e. no need to file a separate issue for that. |
I recall some semi-related earlier conversations we had when implementing the highlighting grammar about how this works out together with semantic highlighting which - one may expect - highlights valid references differently to invalid ones (i.e. such that refer to block/attribute that doesn't exist). That is something we need to dig through as part of hashicorp/terraform-ls#1304 but it's mostly affecting Terraform rather than plain HCL. It just happens that we use bulk of the grammar for both HCL and Terraform. I'm not sure if that issue will impact how we (can) fix this, I'm merely sharing some context on what's likely behind the bug. |
I transferred the issue to the repository where we host the grammars which will need fixing. I also did some investigation only to discover that this is a slightly wider problem of how we treat references in general, which may also have something to do with the limitations of TextMate grammars and regex. Lines 374 to 389 in 13b5b4f
^ that is the part of the grammar responsible for detecting references There's a couple of problems with it:
I'm not sure we can fix (2) reliably without going through a lot of pain in crafting complex regular expressions that exclude all the false positives but there should be some way of fixing (1). I tried changing the expression in a few ways but I always ran into false positive matches because once the leading Then there's also something wrong with the way we detect objects, or rather the expressions inside of it ( Lines 248 to 299 in 13b5b4f
^ that is the snippet responsible for detecting object expressions, but I did not dig too deep into it to understand what exactly is wrong with it To summarize, from UX perspective there are three visible issues. I used 2 different themes to visualise it below: |
I fixed issue 3 in #112. 1 & 2 still remain as they are a bit more involved as Radek explained. |
Extension Version
v2.26.20230511
VS Code Version
Version: 1.79.1 (user setup)
Commit: 4cb974a7aed77a74c7813bdccd99ee0d04901215
Date: 2023-06-12T16:14:05.102Z
Electron: 22.5.7
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Windows_NT x64 10.0.19044
Operating System
Windows 10
Steps to Reproduce
Setup files as below - note the colours in the
main.pkr.hcl
file for:Expected Behavior
Colours should be correct.
Actual Behavior
Colours incorrect on lines 12/13/14.
Configuration
file.pkr.hcl
variable.pkr.hcl
The text was updated successfully, but these errors were encountered: