hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118322

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/SelectionTests.cpp


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -523,6 +523,10 @@
           auto l = [^[[foo = bar]]] { };
         })cpp",
        "VarDecl"},
+      {R"cpp(
+        /*error-ok*/
+        void func() [[{^]])cpp",
+       "CompoundStmt"},
   };
 
   for (const Case &C : Cases) {
Index: clang-tools-extra/clangd/Selection.cpp
===================================================================
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -306,6 +306,12 @@
       return SelectionTree::Unselected;
     }
 
+    // The eof token is used as a sentinel.
+    // In general, source range from an AST node should not claim the eof 
token,
+    // but it could occur for unmatched-bracket cases.
+    if (ExpandedTokens.back().kind() == tok::eof)
+      ExpandedTokens = ExpandedTokens.drop_back();
+
     SelectionTree::Selection Result = NoTokens;
     while (!ExpandedTokens.empty()) {
       // Take consecutive tokens from the same context together for efficiency.


Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -523,6 +523,10 @@
           auto l = [^[[foo = bar]]] { };
         })cpp",
        "VarDecl"},
+      {R"cpp(
+        /*error-ok*/
+        void func() [[{^]])cpp",
+       "CompoundStmt"},
   };
 
   for (const Case &C : Cases) {
Index: clang-tools-extra/clangd/Selection.cpp
===================================================================
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -306,6 +306,12 @@
       return SelectionTree::Unselected;
     }
 
+    // The eof token is used as a sentinel.
+    // In general, source range from an AST node should not claim the eof token,
+    // but it could occur for unmatched-bracket cases.
+    if (ExpandedTokens.back().kind() == tok::eof)
+      ExpandedTokens = ExpandedTokens.drop_back();
+
     SelectionTree::Selection Result = NoTokens;
     while (!ExpandedTokens.empty()) {
       // Take consecutive tokens from the same context together for efficiency.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to