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

Wrong highlighting for identifiers with dash #927

Closed
orgads opened this issue Feb 9, 2022 · 4 comments · Fixed by #933
Closed

Wrong highlighting for identifiers with dash #927

orgads opened this issue Feb 9, 2022 · 4 comments · Fixed by #933
Assignees
Labels
bug Something isn't working syntax

Comments

@orgads
Copy link

orgads commented Feb 9, 2022

Server Version

0.25.2

Terraform Version

Terraform v1.1.5

Client Version

VS Code 1.64.0
Terraform extension v2.19.0

Terraform Configuration Files

foo/all.tf:

variable "foo" {}
output "result-val" { value = var.foo }

test.tf:

variable "some-var" {
  default = "value"
}

module "foo-mod" {
  source = "./foo"
  foo = var.some-var
}

module "bar" {
  source = "./foo"
  foo = module.foo-mod.result-val
}

Log Output

https://gist.github.com/orgads/ac0993b63aaca5601affd4dd7431e233

Expected Behavior

The identifiers that contain dash should be highlighted as identifiers.

Actual Behavior

They are only highlighted up to the dash, and the rest is white. Also the words "var" and "module" are not highlighted in this case.

image

After I run terraform init and reopen the file, highlighting is fixed. But if I reload the window, it is broken again until I reopen the file a few times.

In my project, the case is even worse. I can't get it to work, even after terraform init and reopening.

Steps to Reproduce

  1. Create the 2 files in the description above.
  2. Open the folder in VS Code
  3. Open file test.tf from that folder
  4. Trigger autocompletion on line 7, column 9 (1-indexed)
  5. Trigger autocompletion on line 12, column 9 (1-indexed)
@radeksimko radeksimko transferred this issue from hashicorp/terraform-ls Feb 9, 2022
@radeksimko radeksimko added bug Something isn't working syntax labels Feb 9, 2022
@dbanck dbanck self-assigned this Feb 10, 2022
@dbanck
Copy link
Member

dbanck commented Feb 10, 2022

Thanks a lot for the report and the excellent write-up. I can reproduce the issue.

We rely on TextMate grammars and semantic highlighting for syntax highlighting. TextMate grammars work on a single file as input and break it up based on lexical rules expressed in regular expressions. Highlighting based on semantic tokens is considered an addition to the TextMate-based syntax highlighting and goes on top of syntax highlighting. As language servers can take a while to load and analyze a project, semantic token highlighting may appear after a short delay.

We have improved the refresh of semantic tokens in hashicorp/terraform-ls#630, so we should highlight tokens faster now. And I'll raise a PR to address the bug in the grammar file soon.

dbanck added a commit that referenced this issue Feb 10, 2022
dbanck added a commit that referenced this issue Feb 11, 2022
* Add a base snapshot test for issue #927 
* Fix syntax highlighting for attribute access with dashes

The dash hasn't been a part of the attribute access end capture.
Furthermore, we didn't correctly detect splat and indices on
attribute access notation.

* add comments to attribute access section
@dbanck
Copy link
Member

dbanck commented Feb 11, 2022

We've just merged #933 to address this issue.

This change will be released in the preview extension later this day if you would like to try this out. Furthermore, we will be releasing this to stable in the near future.

@orgads
Copy link
Author

orgads commented Feb 11, 2022

Thank you very much!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working syntax
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants