This is an archive of the discontinued LLVM Phabricator instance.

[clangd] [WIP] Semantic highlighting prototype for the vscode extension.
AbandonedPublic

Authored by jvikstrom on Aug 2 2019, 1:46 AM.

Details

Summary

Contains all the functionality for the highlighting, is going to get cleaned up a lot though. Might end up wanting to create a color theme as well, none of the default ones are that great with this...

Event Timeline

jvikstrom created this revision.Aug 2 2019, 1:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2019, 1:46 AM
jvikstrom updated this revision to Diff 213011.Aug 2 2019, 4:12 AM

Readded guard against rules without scopes that somehow disappeared.

jvikstrom updated this revision to Diff 213013.Aug 2 2019, 4:21 AM

Fixed bug that made it impossible to find colors that were a perfect match to the scope we are looking for (ex: fixes function being color as functions and not as entity.name)

Explanation for the bug: When adding the function highlighting definition the fully qualified name "entity.name.function" was added to a separate list that we did not try to match partial scope matches to.

jvikstrom marked an inline comment as done.Aug 2 2019, 4:28 AM
jvikstrom added inline comments.
clang-tools-extra/clangd/clients/clangd-vscode/src/TextMate.ts
20

I'm pretty sure this matching logic is wrong. An example of the scopes for variables in the Light+ theme:

variable.css
variable.scss
variable.other.less
variable.language.wildcard.java
variable.language
storage.type.variable.cs
variable
meta.definition.variable.name
support.variable
entity.name.variable

With this kind of matching we have now this means that variable.other.less will match variable.other and variable.other.less.
As there is no perfect match for variable.other.field it will try to match variable.other and find the color for less.

What should probably be done is remove the divided map. The query function should still be the same but query on this.colors instead of this.divided.

jvikstrom updated this revision to Diff 213015.Aug 2 2019, 4:29 AM

Fix matching logic on TM scopes.

hokein added inline comments.Aug 2 2019, 5:26 AM
clang-tools-extra/clangd/clients/clangd-vscode/src/TextMate.ts
20

The suffix of textmate indicates the language it belongs to (e.g. java), I think we can ignore non-C++ textmates, and merely find the longest-prefix match in all c++ textmates?

jvikstrom marked an inline comment as done.Aug 2 2019, 6:15 AM
jvikstrom added inline comments.
clang-tools-extra/clangd/clients/clangd-vscode/src/TextMate.ts
20

But we have no real way of knowing if a suffix is a language or a more "precise" scope.
I don't think it's really possible to differentiate between variable.other and variable.css and say that variable.css is not relevant to c++ while variable.other is. (other than having an exhaustive list of language suffixes, which isn't feasible)

The implementation I changed to just saves the full scopes and than when we try to find the color of a scope we try to find it in the map, otherwise remove a suffix and try to find that scope (over and over)

Ex: Find scope for variable.other.field.cpp ->

First check for `variable.other.field.cpp` (finds nothing)
Check `variable.other.field` (finds nothing)
Check `variable.other` (still finds nothing
Check `variable` (finds the variable scope and returns that color)

This seems to work, but maybe there's some case I miss. Anyway, there is probably a defined order on how you are supposed to find these scopes, I think I read a blog post on how VSCode actually does this matching internally. I'll try to dig that up and make sure our implementation matches before it's time to put up the actual CLs for this.

nridge added a subscriber: nridge.Aug 2 2019, 7:00 PM
nridge added a comment.EditedAug 3 2019, 6:01 PM

Do you plan to support text decoration options other than color, e.g. bold / underline / italic?

Are users going to be able to change the color (and other decoration options) for specific highlightings in the VSCode Settings?

hokein added a comment.Aug 5 2019, 1:30 AM

Do you plan to support text decoration options other than color, e.g. bold / underline / italic?

I think we'd just support color, and we don't have further plan to support richer renderings at the moment -- ideally, vscode should have built-in support for semantic highlighting if the proposal is accepted in LSP, this means this part of extension code will be removed in the end.

Are users going to be able to change the color (and other decoration options) for specific highlightings in the VSCode Settings?

vscode seems to provide a mechanism to override the theme settings, like

"editor.tokenColorCustomizations": {
        "[Visual Studio Dark]": {
            "textMateRules": [
                {
                    "scope": "entity.name.type",
                    "settings": {
                        "foreground": "#FF0000",
                    }
                }
            ]    
        }

I think our extension should respect it.

jvikstrom abandoned this revision.Aug 26 2019, 9:44 AM