This patch introduces the following configurations to .clangd:
SemanticTokens: DisabledKinds: [ ... ] DisabledModifiers: [ ... ]
Based on the config, clangd would stop producing a certain type of semantic tokens from the source file.
Paths
| Differential D148489
[clangd] Implement configs to stop clangd produce a certain semantic tokens ClosedPublic Authored by daiyousei-qz on Apr 16 2023, 8:18 PM.
Details Summary This patch introduces the following configurations to .clangd: SemanticTokens: DisabledKinds: [ ... ] DisabledModifiers: [ ... ] Based on the config, clangd would stop producing a certain type of semantic tokens from the source file.
Diff Detail
Event Timelinedaiyousei-qz retitled this revision from Implement configs to stop clangd produce a certain semantic tokens to [clangd] Implement configs to stop clangd produce a certain semantic tokens.Apr 16 2023, 8:21 PM Comment Actions Please hold off from reviewing this. I have been figuring out how arc tools work and the unittest of the current version is broken. Comment Actions Fix an issue where the previous change is lost.
Comment Actions Add some comments to the config headers. Resubmit to retrigger build test since I cannot reproduce the failure. Comment Actions before you dive any deeper into the patch, could you give some reasoning about why this is needed/useful? Comment Actions
https://github.com/clangd/clangd/discussions/1598 contains some context/motivation Comment Actions
The discussion is at https://github.com/clangd/clangd/discussions/1598. The original motivation is that in the latest clangd, we start to assign semantic token "operator" to all operators in the source code. Since the semantic tokens take priority over the textmate rules in vscode, now we cannot theme different operators differently anymore. For example, we cannot color "new" in blue while have "+" in white. To address the issue, this patch adds configurable filter to the semantic token to filter out unwanted kinds and modifiers. We should have the following benefits with such filter in place.
Comment Actions Thanks for the patch! I think this is a nice and general solution, which rather than solving just a specific problem (e.g. highlighting of new as an operator vs. a keyword), gives users a broader ability to fine-tune clangd's highlightings to suit their needs. Could I kindly ask you to make a PR that updates https://github.com/llvm/clangd-www/blob/main/config.md to cover the new config keys, as well?
This revision now requires changes to proceed.May 7 2023, 11:59 PM Comment Actions Sorry, I'm a little occupied lately and don't have time to fix the test failure. I'll try to fix that in this week.
Comment Actions Thanks! Let me know if you need me to commit.
This revision is now accepted and ready to land.May 16 2023, 11:29 PM Comment Actions
Oh, okay. Let me address that. Didn't see that. Comment Actions Sorry for the inactivity. I have replace the parameter with const ref. By the way, I also removed the existing IncludeInactiveRegionTokens flag and uses this filter instead. Please help review the change. Thanks! Closed by commit rG6feaa5416bf6: [clangd] Implement configs to stop clangd produce a certain semantic tokens (authored by daiyousei-qz, committed by nridge). · Explain WhyMay 26 2023, 12:25 AM This revision was automatically updated to reflect the committed changes. Comment Actions I went ahead and merged this. When you get a chance, could you update https://github.com/llvm/clangd-www/pull/85 as well so we can merge that too? Comment Actions Thank you! Since the documentation shouldn't be available until LLVM 17, I'm slowly working on it. Let me update the PR in this weekend :)
Revision Contents
Diff 514530 clang-tools-extra/clangd/Config.h
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/ConfigFragment.h
clang-tools-extra/clangd/ConfigYAML.cpp
clang-tools-extra/clangd/SemanticHighlighting.h
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
|
For good measure, let's static_assert(HighlightingModifier::LastModifier < 32)