[PATCH] D52547: Tell whether file/folder for include completions.

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 27 07:22:07 PDT 2018


kadircet updated this revision to Diff 167320.
kadircet marked 2 inline comments as done.
kadircet added a comment.

Preparing the patch to respect client capabilities.

- Add other itemkinds as well.
- Address comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52547

Files:
  clangd/CodeComplete.cpp
  clangd/Protocol.h
  unittests/clangd/CodeCompleteTests.cpp


Index: unittests/clangd/CodeCompleteTests.cpp
===================================================================
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -2073,6 +2073,27 @@
   }
 }
 
+TEST(CompletionTest, IncludedCompletionKinds) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  std::string Subdir = testPath("sub");
+  std::string SearchDirArg = (llvm::Twine("-I") + Subdir).str();
+  CDB.ExtraClangFlags = {SearchDirArg.c_str()};
+  std::string BarHeader = testPath("sub/bar.h");
+  FS.Files[BarHeader] = "";
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+  auto Results = completions(Server,
+      R"cpp(
+        #include "^"
+      )cpp"
+      );
+  EXPECT_THAT(Results.Completions,
+              AllOf(Has("sub/", CompletionItemKind::Folder),
+                    Has("bar.h\"", CompletionItemKind::File)));
+}
+
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/Protocol.h
===================================================================
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -704,6 +704,13 @@
   Color = 16,
   File = 17,
   Reference = 18,
+  Folder = 19,
+  EnumMember = 20,
+  Constant = 21,
+  Struct = 22,
+  Event = 23,
+  Operator = 24,
+  TypeParameter = 25,
 };
 
 /// Defines whether the insert text in a completion item should be interpreted
Index: clangd/CodeComplete.cpp
===================================================================
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -349,6 +349,11 @@
       }
       Completion.Kind = toCompletionItemKind(
           C.SemaResult->Kind, C.SemaResult->Declaration, ContextKind);
+      // Sema could provide more info on whether the completion was a file or
+      // folder.
+      if (Completion.Kind == CompletionItemKind::File &&
+          Completion.Name.back() == '/')
+        Completion.Kind = CompletionItemKind::Folder;
       for (const auto &FixIt : C.SemaResult->FixIts) {
         Completion.FixIts.push_back(
             toTextEdit(FixIt, ASTCtx.getSourceManager(), ASTCtx.getLangOpts()));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52547.167320.patch
Type: text/x-patch
Size: 2160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180927/f44df795/attachment.bin>


More information about the cfe-commits mailing list