[PATCH] D66335: [clangd] Added special HighlightingKind for function parameters.

2019-08-19 Thread Johan Vikström via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369238: [clangd] Added special HighlightingKind for function 
parameters. (authored by jvikstrom, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66335?vs=215548=215827#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66335

Files:
  clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
  clang-tools-extra/trunk/clangd/SemanticHighlighting.h
  clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
  clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
===
--- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
+++ clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
@@ -8,6 +8,9 @@
 # CHECK-NEXT:"variable.other.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
+# CHECK-NEXT:"variable.parameter.cpp"
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  [
 # CHECK-NEXT:"entity.name.function.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
@@ -43,7 +46,7 @@
 # CHECK-NEXT:"lines": [
 # CHECK-NEXT:  {
 # CHECK-NEXT:"line": 0,
-# CHECK-NEXT:"tokens": "AAADAAkEAAEAAA=="
+# CHECK-NEXT:"tokens": "AAADAAoEAAEAAA=="
 # CHECK-NEXT:  }
 # CHECK-NEXT:],
 # CHECK-NEXT:"textDocument": {
@@ -58,11 +61,11 @@
 # CHECK-NEXT:"lines": [
 # CHECK-NEXT:  {
 # CHECK-NEXT:"line": 0,
-# CHECK-NEXT:"tokens": "AAADAAkEAAEAAA=="
+# CHECK-NEXT:"tokens": "AAADAAoEAAEAAA=="
 # CHECK-NEXT:  }
 # CHECK-NEXT:  {
 # CHECK-NEXT:"line": 1,
-# CHECK-NEXT:"tokens": "AAADAAkEAAEAAA=="
+# CHECK-NEXT:"tokens": "AAADAAoEAAEAAA=="
 # CHECK-NEXT:  }
 # CHECK-NEXT:],
 # CHECK-NEXT:"textDocument": {
@@ -77,7 +80,7 @@
 # CHECK-NEXT:"lines": [
 # CHECK-NEXT:  {
 # CHECK-NEXT:"line": 1,
-# CHECK-NEXT:"tokens": "AAADAAkEAAEAAA=="
+# CHECK-NEXT:"tokens": "AAADAAoEAAEAAA=="
 # CHECK-NEXT:  }
 # CHECK-NEXT:   ],
 # CHECK-NEXT:"textDocument": {
Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
@@ -11,6 +11,7 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include 
@@ -200,6 +201,10 @@
   addToken(Loc, HighlightingKind::EnumConstant);
   return;
 }
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::Parameter);
+  return;
+}
 if (isa(D)) {
   addToken(Loc, HighlightingKind::Variable);
   return;
@@ -406,6 +411,8 @@
 return "entity.name.function.method.cpp";
   case HighlightingKind::Variable:
 return "variable.other.cpp";
+  case HighlightingKind::Parameter:
+return "variable.parameter.cpp";
   case HighlightingKind::Field:
 return "variable.other.field.cpp";
   case HighlightingKind::Class:
Index: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
@@ -16,6 +16,10 @@
 
 namespace clang {
 namespace clangd {
+  void PrintTo(const HighlightingToken , ::std::ostream *OS) {
+  *OS << "(" << T.R.start.line << ", " << T.R.start.character << ") -> (" << T.R.end.line << ", " << T.R.end.character << "): " << (int)T.Kind;
+}
+
 namespace {
 
 std::vector
@@ -32,6 +36,7 @@
 std::vector getExpectedTokens(Annotations ) {
   static const std::map KindToString{
   {HighlightingKind::Variable, "Variable"},
+  {HighlightingKind::Parameter, "Parameter"},
   {HighlightingKind::Function, "Function"},
   {HighlightingKind::Class, "Class"},
   {HighlightingKind::Enum, "Enum"},
@@ -104,11 +109,11 @@
   };
   struct {
   } $Variable[[S]];
-  $Primitive[[void]] $Function[[foo]]($Primitive[[int]] $Variable[[A]], $Class[[AS]] $Variable[[As]]) {
+  $Primitive[[void]] $Function[[foo]]($Primitive[[int]] $Parameter[[A]], $Class[[AS]] $Parameter[[As]]) {
 $Primitive[[auto]] $Variable[[VeryLongVariableName]] = 12312;
 $Class[[AS]] $Variable[[AA]];
-$Primitive[[auto]] $Variable[[L]] = $Variable[[AA]].$Field[[SomeMember]] + $Variable[[A]];
-auto $Variable[[FN]] = [ 

[PATCH] D66335: [clangd] Added special HighlightingKind for function parameters.

2019-08-16 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66335



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


[PATCH] D66335: [clangd] Added special HighlightingKind for function parameters.

2019-08-16 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom created this revision.
jvikstrom added reviewers: hokein, ilya-biryukov.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

This means that function parameters are no longer highlighted as 
variable.other.cpp but instead as variable.parameter.cpp which is the more 
"correct" TextMate scope for them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66335

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/test/semantic-highlighting.test
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -32,6 +32,7 @@
 std::vector getExpectedTokens(Annotations ) {
   static const std::map KindToString{
   {HighlightingKind::Variable, "Variable"},
+  {HighlightingKind::Parameter, "Parameter"},
   {HighlightingKind::Function, "Function"},
   {HighlightingKind::Class, "Class"},
   {HighlightingKind::Enum, "Enum"},
@@ -104,11 +105,11 @@
   };
   struct {
   } $Variable[[S]];
-  $Primitive[[void]] $Function[[foo]]($Primitive[[int]] $Variable[[A]], $Class[[AS]] $Variable[[As]]) {
+  $Primitive[[void]] $Function[[foo]]($Primitive[[int]] $Parameter[[A]], $Class[[AS]] $Parameter[[As]]) {
 $Primitive[[auto]] $Variable[[VeryLongVariableName]] = 12312;
 $Class[[AS]] $Variable[[AA]];
-$Primitive[[auto]] $Variable[[L]] = $Variable[[AA]].$Field[[SomeMember]] + $Variable[[A]];
-auto $Variable[[FN]] = [ $Variable[[AA]]]($Primitive[[int]] $Variable[[A]]) -> $Primitive[[void]] {};
+$Primitive[[auto]] $Variable[[L]] = $Variable[[AA]].$Field[[SomeMember]] + $Parameter[[A]];
+auto $Variable[[FN]] = [ $Variable[[AA]]]($Primitive[[int]] $Parameter[[A]]) -> $Primitive[[void]] {};
 $Variable[[FN]](12312);
   }
 )cpp",
@@ -287,10 +288,10 @@
   struct $Class[[B]] {};
   struct $Class[[A]] {
 $Class[[B]] $Field[[BB]];
-$Class[[A]] =($Class[[A]] &&$Variable[[O]]);
+$Class[[A]] =($Class[[A]] &&$Parameter[[O]]);
   };
 
-  $Class[[A]] &$Class[[A]]::operator=($Class[[A]] &&$Variable[[O]]) = default;
+  $Class[[A]] &$Class[[A]]::operator=($Class[[A]] &&$Parameter[[O]]) = default;
 )cpp",
 R"cpp(
   enum $Enum[[En]] {
@@ -301,9 +302,9 @@
 $Class[[Foo]] $Field[[Fo]];
 $Enum[[En]] $Field[[E]];
 $Primitive[[int]] $Field[[I]];
-$Class[[Bar]] ($Class[[Foo]] $Variable[[F]],
-$Enum[[En]] $Variable[[E]])
-: $Field[[Fo]] ($Variable[[F]]), $Field[[E]] ($Variable[[E]]),
+$Class[[Bar]] ($Class[[Foo]] $Parameter[[F]],
+$Enum[[En]] $Parameter[[E]])
+: $Field[[Fo]] ($Parameter[[F]]), $Field[[E]] ($Parameter[[E]]),
   $Field[[I]] (123) {}
   };
   class $Class[[Bar2]] : public $Class[[Bar]] {
@@ -385,7 +386,7 @@
   std::vector ActualResults =
   toSemanticHighlightingInformation(Tokens);
   std::vector ExpectedResults = {
-  {3, "CAAEAAAEAAMAAQ=="}, {1, "AQAEAAA="}};
+  {3, "CAAEAAAEAAMAAg=="}, {1, "AQAEAAA="}};
   EXPECT_EQ(ActualResults, ExpectedResults);
 }
 
Index: clang-tools-extra/clangd/test/semantic-highlighting.test
===
--- clang-tools-extra/clangd/test/semantic-highlighting.test
+++ clang-tools-extra/clangd/test/semantic-highlighting.test
@@ -8,6 +8,9 @@
 # CHECK-NEXT:"variable.other.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
+# CHECK-NEXT:"variable.parameter.cpp"
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  [
 # CHECK-NEXT:"entity.name.function.cpp"
 # CHECK-NEXT:  ],
 # CHECK-NEXT:  [
@@ -43,7 +46,7 @@
 # CHECK-NEXT:"lines": [
 # CHECK-NEXT:  {
 # CHECK-NEXT:"line": 0,
-# CHECK-NEXT:"tokens": "AAADAAkEAAEAAA=="
+# CHECK-NEXT:"tokens": "AAADAAoEAAEAAA=="
 # CHECK-NEXT:  }
 # CHECK-NEXT:],
 # CHECK-NEXT:"textDocument": {
@@ -58,11 +61,11 @@
 # CHECK-NEXT:"lines": [
 # CHECK-NEXT:  {
 # CHECK-NEXT:"line": 0,
-# CHECK-NEXT:"tokens": "AAADAAkEAAEAAA=="
+# CHECK-NEXT:"tokens": "AAADAAoEAAEAAA=="
 # CHECK-NEXT:  }
 # CHECK-NEXT:  {
 # CHECK-NEXT:"line": 1,
-# CHECK-NEXT:"tokens": "AAADAAkEAAEAAA=="
+# CHECK-NEXT:"tokens": "AAADAAoEAAEAAA=="
 # CHECK-NEXT:  }
 # CHECK-NEXT:],
 # CHECK-NEXT:"textDocument": {
@@ -77,7 +80,7 @@
 # CHECK-NEXT:"lines": [
 # CHECK-NEXT:  {
 # CHECK-NEXT:"line": 1,
-#