[PATCH] D87669: Rainbow Semantic Highlighting

2020-09-14 Thread Alex Zielenski via Phabricator via cfe-commits
alexzielenski created this revision.
alexzielenski added reviewers: MaskRay, ilya-biryukov, sammccall.
alexzielenski created this object with visibility "All Users".
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
alexzielenski requested review of this revision.

This patch adds support for rainbow semantic highlighting seem in ccls and 
cquery into clangd's implementation of SemanticTokensProvider. The method of 
implementation is to create new modifiers "0, 1, 2, 4", which are pinned to the 
hash of a SymbolID, to be used by the user in the creation of their theme for 
rainbow highlighting.

This patch has a few flaws as well as minor improvements to clangd's 
classification of symbols and takes you 80% of the way. I mainly created it for 
my own purposes since I cannot read code without this feature. Hopefully you 
can merge something like this upstream so I don't have to keep maintaining my 
local checkout.

I attached an example of what this looks like, and below is the configuration I 
used in my VSCode settings so you can try for yourself:
F12954809: Screen Shot 2020-09-14 at 9.38.54 PM.png 


  json
  "editor.semanticTokenColorCustomizations": {
  "enabled": true,
  "rules": {
  "variable:cpp": "#92d7f2",
  "variable.1:cpp": "#78a8d5",
  "variable.2:cpp": "#9be0e6",
  "variable.3:cpp": "#9cc2f7",
  "variable.4:cpp": "#5ba9b8",
  "variable.local:cpp": "#99bfcb",
  "variable.local.1:cpp": "#c2e9f5",
  "variable.local.2:cpp": "#add4e0",
  "variable.local.3:cpp": "#99bfcb",
  "variable.local.4:cpp": "#81afc5",
  "variable.member:cpp": "#4fbbbc",
  "variable.member.1:cpp": "#3ba7e5",
  "variable.member.2:cpp": "#33d4d1",
  "variable.member.3:cpp": "#4eb4f3",
  "variable.member.4:cpp": "#6ed7d8",
  "variable.static.member:cpp": "#66d4f6",
  "variable.static.member.1:cpp": "#2f8fa5",
  "variable.static.member.2:cpp": "#4ee2f4",
  "variable.static.member.3:cpp": "#88aee1",
  "variable.static.member.4:cpp": "#4ab9ce",
  "parameter:cpp": "#a4beb8",
  "parameter.1:cpp": "#7fd6c5",
  "parameter.2:cpp": "#b8d3cd",
  "parameter.3:cpp": "#9fcaac",
  "parameter.4:cpp": "#a8dfd4",
  "function:cpp": "#61cca5",
  "function.1:cpp": "#1fe1fb",
  "function.2:cpp": "#43c88b",
  "function.3:cpp": "#3edbd8",
  "function.4:cpp": "#63e5a6",
  "function.member:cpp": "#4bd6fd",
  "function.member.1:cpp": "#28e6cc",
  "function.member.2:cpp": "#4eb4f3",
  "function.member.3:cpp": "#4cccb7",
  "function.member.4:cpp": "#4abfe8",
  "function.static:cpp": "#9fa8e1",
  "function.static.1:cpp": "#20d8fd",
  "function.static.2:cpp": "#9ca6f4",
  "function.static.3:cpp": "#5bcdf6",
  "function.static.4:cpp": "#b4bcf7",
  "type:cpp": "#edc158",
  "type.1:cpp": "#f67b3e",
  "type.2:cpp": "#ecc02b",
  "type.3:cpp": "#e59668",
  "type.4:cpp": "#e6a01e",
  "enum:cpp": "#d55bc0",
  "enum.1:cpp": "#ee4d69",
  "enum.2:cpp": "#f570d9",
  "enum.3:cpp": "#f7457c",
  "enum.4:cpp": "#e44cc0",
  "enumConstant:cpp": "#f53d8b",
  "enumConstant.1:cpp": "#f53d8b",
  "enumConstant.2:cpp": "#ef489e",
  "enumConstant.3:cpp": "#d452a8",
  "enumConstant.4:cpp": "#d452a8",
  "macro:cpp": "#a85e16",
  "macro.1:cpp": "#d29e3b",
  "macro.2:cpp": "#8d630a",
  "macro.3:cpp": "#dc803d",
  "macro.4:cpp": "#dd9549",
  "namespace:cpp": "#c6a94d",
  "namespace.1:cpp": "#8c6a25",
  "namespace.2:cpp": "#daca74",
  "namespace.3:cpp": "#ab722f",
  "namespace.4:cpp": "#a19435"
  }
  }




Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87669

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h

Index: clang-tools-extra/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -70,6 +70,7 @@
 struct HighlightingToken {
   HighlightingKind Kind;
   Range R;
+  unsigned char Index = 0;
 };
 
 bool operator==(const HighlightingToken &L, const HighlightingToken &R);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp

[PATCH] D87669: [clangd] Rainbow Semantic Highlighting

2020-09-18 Thread Alex Zielenski via Phabricator via cfe-commits
alexzielenski added a comment.

Hey Sam, Thanks for checking this out!

I really like your idea about encoding the variants with binary - as you say it 
removes the need for any assumption on the server's part for the limit of 
colors. However, I'd be wary of the fact that most users and theme creators 
don't know or understand binary and probably also don't want to learn binary. 
Indeed - I dont think users would easily accept (or obey) being limited to a 
power of 2 for their rainbow variants - and be subject to ambiguous behavior 
that arises when variable.1.2 is requested to be highlighted by a theme with 
only variable.1 and variable.2 entries.

Additionally, having creating a theme myself, I've come to understand that 
anyone would be hard pressed to find 256 visually distinct colors that are 
still similar enough to recognize as the same semantic type. I had a hard 
enough time finding 5 good ones even with the help of automated tools.

So I think for the server to have a small imposed limit would be okay - the 
only practical drawback I can think of with my current solution is you are 
forced to have 5 colors: If `variable.4` is requested to be highlighted and you 
only have `variable.1`;`variable.2`;`variable.3` defined by a theme, my current 
system with just highlight this with the unmodified `variable`. The 
binary-encoded system you propose would not have this issue and would properly 
"modulo" for the defined bits. Of course this could be a configuration option, 
but I don't like that either.

My intent for this patch is to get the ball rolling - I'm not really 
interesting in bringing it through the review process since I get enough of 
that at my day job 😅 (I also adjusted the visibility to users only to try to 
stay discrete) but I am happy to help influence discussion for this patch. I've 
been following clangd for a few years and have been happy that since around 
clangd-10/11 it seems to have gotten usable for my day-to-day use. Tools like 
these 10x developer productivity so good work!




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:606
+  Out.tokenModifiers |= 1 << 7;
+}
 

This method of managing the modifiers is pretty obviously bad.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87669/new/

https://reviews.llvm.org/D87669

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits