[clang-tools-extra] d1fd91d - [clangd] Do not treat line as inactive if skipped range ends at character position 0

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 26 00:43:04 PST 2020


Author: Nathan Ridge
Date: 2020-11-26T03:42:42-05:00
New Revision: d1fd91ddaf9de95428a25d001606c23703e14b31

URL: https://github.com/llvm/llvm-project/commit/d1fd91ddaf9de95428a25d001606c23703e14b31
DIFF: https://github.com/llvm/llvm-project/commit/d1fd91ddaf9de95428a25d001606c23703e14b31.diff

LOG: [clangd] Do not treat line as inactive if skipped range ends at character position 0

Fixes https://github.com/clangd/clangd/issues/602

Differential Revision: https://reviews.llvm.org/D92148

Added: 
    

Modified: 
    clang-tools-extra/clangd/SemanticHighlighting.cpp
    clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 44d74f387dd1..5397d328b086 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -234,6 +234,10 @@ class HighlightingsBuilder {
       // with line-based 
diff ing.
       assert(R.start.line <= R.end.line);
       for (int Line = R.start.line; Line <= R.end.line; ++Line) {
+        // If the end of the inactive range is at the beginning
+        // of a line, that line is not inactive.
+        if (Line == R.end.line && R.end.character == 0)
+          continue;
         // Copy tokens before the inactive line
         for (; It != NonConflicting.end() && It->R.start.line < Line; ++It)
           WithInactiveLines.push_back(std::move(*It));

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 232be6a78380..79f3af264c0f 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -623,18 +623,23 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
       // Code after the preamble.
       // Code inside inactive blocks does not get regular highlightings
       // because it's not part of the AST.
-$InactiveCode[[#ifdef test]]
+      #define $Macro[[test2]]
+$InactiveCode[[#if defined(test)]]
 $InactiveCode[[int Inactive2;]]
+$InactiveCode[[#elif defined(test2)]]
+      int $Variable[[Active1]];
+$InactiveCode[[#else]]
+$InactiveCode[[int Inactive3;]]
 $InactiveCode[[#endif]]
 
       #ifndef $Macro[[test]]
-      int $Variable[[Active1]];
+      int $Variable[[Active2]];
       #endif
 
 $InactiveCode[[#ifdef test]]
-$InactiveCode[[int Inactive3;]]
+$InactiveCode[[int Inactive4;]]
 $InactiveCode[[#else]]
-      int $Variable[[Active2]];
+      int $Variable[[Active3]];
       #endif
     )cpp",
       // Argument to 'sizeof...'


        


More information about the cfe-commits mailing list