Replies: 1 comment
-
That line in the docs is about which style is used from the theme for a scope set by a language's highlight queries or looked up for the UI. For another example, rulers are highlighted with Instead what you're looking for is how these keys are specified by a language's highlight queries. In (binding
attrpath: (attrpath attr: (identifier)) @variable.other.member) This only matches unquoted tokens ( (binding
attrpath: (attrpath attr: [(identifier) (string_expression)] @variable.other.member)) And you would need to move this pattern: [
(string_expression)
(indented_string_expression)
] @string below the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As stated in the documentation, the rule for which theme key takes precedence is:
However, what if you have two keys of equal precedence?
My specific example
I'm attempting to write a theme that works well for the Nix language. My goal is for all strings to be given the same color, even those in an attribute's key. So, in this example:
I want to ensure
"bar"
and"two"
are both highlighted the same color. Settingstring.fg
to some color accomplishes this.However, what if I want to highlight non-string keys? In this case,
foo
andbar
should receive a certain styling, while the"two"
in quotes should not receive this color. I can change the color of these keys by settingvariable.fg
.But, now we reach the problem.
variable.fg
seems to be overridingstring.fg
, meaning it's setting all variables, even those that should be highlighted as a string. I'm guessing this is because the test for "longest matching theme key" just matches the character length of the key, andvariable
is longer thanstring
. There doesn't exist a longer string scope that will touch Nix strings, so I'm stuck.How to fix this
Of course, in my specific case, adding a longer key for strings would fix this. In the documentation on strings, it mentions a TODO list:
TODO: string.quoted.{single, double}, string.raw/.unquoted)?
. Addingstring.quoted
would be longer thanvariable
, so it'd override it. However, this is only a fix for my specific scenario. I think a better fix would be the ability to specify precedence, so you didn't have to rely on the length of the key.A relatively simple implementation of this to implement would be a boolean key alongside
fg
,bg
,underline
, andmodifiers
, where you could specify whether a key should be set above other keys, even those of the same length. If this key was ever set to true, it would be weighted to the top when choosing which style is applied, even over keys of a longer length. If multiple different keys had this value applied, it would then revert to choosing the longest one.As an alternative, slightly more in-depth approach, I think using a numerical value might work better than a simple boolean. The number would specify how much precedence that key would receive, with a higher number corresponding to a higher precedence. This would work better with multiple keys specifying a high precedence.
I'm not that picky about the actual method for specifying precedence - I just think there should be some way to do it. Simply choosing precedence based on string length works in a hypothetical world where you can always choose a longer key, but if you've already gone as deep as you can, I don't see a clear workaround other than adding manual precedence.
Beta Was this translation helpful? Give feedback.
All reactions