-
Notifications
You must be signed in to change notification settings - Fork 135
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
internal/lsp: report dependent modifiers as defaultLibrary
#817
Conversation
defaultLibrary
Can we contribute this inside the extension as shown in https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#custom-textmate-scope-mappings? |
Yep, I suppose we could! That's a good idea. |
Although bold is better than nothing. In my opinion, it would be even better if the user can define the font attribute directly. A possible example of this kind of color syntax is possible with Intelli-J. See screenshot in this issue vscode-terraform, 710, Color syntax: add scope for resource_type and resource_name In the case of VSCode, I can edit "editor.tokenColorCustomizations": {
"textMateRules": [
{
// Terraform keywords
"scope": [
"entity.name.type.terraform",
],
"settings": {
"foreground": "#8040FF", "fontStyle": ""
}
},
{
// name of nested block within a resource block
"scope": [
"entity.name.label.terraform",
],
"settings": {
"foreground": "#007CCC", "fontStyle": ""
}
},
]
} Base on the example above, may be you can add some additional scopes to correspond to Terraform's resource-type and resource-id? I don't think it is necessary to worry about the custom themes. For themes which are not aware about Terraform specific scopes, they would just theme the resource-type and resource-id as string. For those which can or for users who are willing to edit their |
The bold was just an example. As you can see from the attached code in the PR - it does not set any particular style, just "meaning". The main point here is exactly to allow users to define any styling they want, as shown in the snippet of config above - which just used bold. I (mostly blindly) assumed that custom themes can simply assign their own styles to token types and modifiers but regardless we can certainly map these semantic tokens to some TextMate grammar scopes to make that possible or easier. We will keep This PR here merely enables the mapping, nothing more (yet).
I'm afraid we are at the mercy of LSP here as we can only work with these language-agnostic types and modifiers here terraform-ls/internal/lsp/token_types.go Lines 64 to 98 in bff4e90
The protocol doesn't seem to allow just arbitrary custom token types at this point and we struggled to find the right mapping to HCL constructs. However I'm assuming that you could work with Did you want to style |
Actually there is this https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#custom-token-types-and-modifiers which suggests that custom token types are allowed, but it's unclear to me what implications does that have on the server. Unlike with TM scopes there's only one token type that we can assign to the same range, so this would suggest that any client that doesn't support that custom token type is just out of luck? 🤔 |
@tringuyen-yw I believe we have a plan forward with regards to supporting custom themes via custom token types and modifiers, see hashicorp/vscode-terraform#958 with more details. In the meantime though I'd still like to go through with this PR. The only difference after hashicorp/vscode-terraform#958 is implemented fully (on LS side) is that cc @hashicorp/tf-editor-experience for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
This functionality has been released in v0.26.0 of the language server. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Closes #710
The (LSP) modifier
defaultLibrary
better represents the meaning of dependent labels or attributes, as opposed tomodification
which was chosen mostly arbitrarily as part of the initial implementation in #331Highlighting dependent labels was already possible prior to this patch but the change of the modifier here reflects the commitment to support custom themes in a more sensible (and hopefully stable) way.
Default VSCode themes do not assign meaning to any modifiers but it is possible to take advantage of this in a custom theme or simply by modifying the VSCode settings such as
Before
(assuming customized settings as above & default theme)
After
(assuming customized settings as above & default theme)
cc @tringuyen-yw
variable
name getting also reported as dependent is not intended, but I opened a separate issue for that problem: hashicorp/terraform-schema#96