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

LSP changes color scheme -- option to disable this behavior #1762

Closed
1 task
seanturner026 opened this issue Jul 12, 2024 · 3 comments
Closed
1 task

LSP changes color scheme -- option to disable this behavior #1762

seanturner026 opened this issue Jul 12, 2024 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@seanturner026
Copy link

seanturner026 commented Jul 12, 2024

Description

For some reason enabling terraformls changes the color scheme of my IDE. When I open a file my theme will be correct and then after .5 seconds or so it changes. I've noticed this in vscode (for years) and now neovim.

Is there a way to disable this behavior? I skimmed the docs and issues and did not see anything.

If there is no way to disable this behavior can a toggle be added?

Additionally, I have confirmed this. Disabling my terraformls in neovim causes my theme to be preserved.

No LSP:

Screenshot 2024-07-11 at 10 53 32 PM

With LSP:

Screenshot 2024-07-11 at 10 53 54 PM

Links

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@seanturner026 seanturner026 added the documentation Improvements or additions to documentation label Jul 12, 2024
@jpogran
Copy link
Contributor

jpogran commented Jul 12, 2024

Hey @seanturner026, thanks for reporting this, I'm sorry you've been seeing this for years and thought you had to accept it. The good news is that we are not changing the color scheme/theme and the behavior is user configurable.

Syntax highlighting in VS Code and other LSP aware editors like neovim apply highlighting to tokens in two passes. The first pass comes from a TextMate grammar (a complicated set of regular expressions) that applies almost instantaneously, and is the highlighting you see in the first screenshot. The second pass comes from Semantic Tokens, which is delivered by the language server when it's built enough context to provide more specific highlighting, which is what you see in the second screenshot.

Why do we do this? We do this to provide more detailed information than what regex can provide. For example, with regex it's hard to determine if a token is valid or not depending on which version of Terraform is currently being used. We could highlight it red in versions that are not supported, and leave it unmodified in versions that are.

Note that what actual colors are used are not decided by the extension/LSP, we just tell the editor that this range at this location is this kind of token. Your color theme determines what actual colors are used. If you are using one of the built in themes, they all should have colors defined for these tokens. If you are using a color theme from the gallery, you'll have to inspect that theme to see what color they set for each token. If you're using your own color theme, then you can follow the Color Theme guide to see what to implement.

Now to explain the part that is user configurable. This will probably be different in neovim so you will have to look that up. In VS Code you can either turn it off entirely and lose the more specific information, or you can customize what color is used for each token.

You can turn off semantic highlighting entirely:

"editor.semanticHighlighting.enabled": false

To customize the colors used (I picked random colors just to enumerate the different options):

"editor.semanticTokenColorCustomizations": {
    "enabled": true,
    "rules": {
      "type": "#569cd6",
      "parameter": "#9cdcfe",
      "variable": "#9cdcfe",
      "property": "#9cdcfe",
      "function": "#dcdcaa",
      "method": "#dcdcaa",
      "operator": "#d4d4d4",
      "keyword": "#569cd6",
      "string": "#ce9178",
      "number": "#b5cea8",
      "comment": "#6a9955",
      "punctuation": "#d4d4d4",
      "tag": "#569cd6",
      "attribute": "#9cdcfe",
      "boolean": "#569cd6",
      "null": "#569cd6",
      "enum": "#b5cea8",
      "namespace": "#4ec9b0"
    }
  }
}

@seanturner026
Copy link
Author

Fantastic, I was able to sort this out!! Thank you very much for the thorough response!

Here was the fix for neovim (disabling client.server_capabilities.semanticTokensProvider for terraformls specifically).

seanturner026/kickstart.nvim@58eaaae

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 Aug 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants