[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:41 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE343221: Tell whether file/folder for include completions. (authored by kadircet, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D52547?vs=167320&id=167321#toc
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D52547
Files:
clangd/CodeComplete.cpp
clangd/Protocol.h
unittests/clangd/CodeCompleteTests.cpp
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()));
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52547.167321.patch
Type: text/x-patch
Size: 2160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180927/a40e7061/attachment.bin>
More information about the cfe-commits
mailing list