forked from OSchip/llvm-project
Tell whether file/folder for include completions.
Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D52547 llvm-svn: 343221
This commit is contained in:
parent
4ed966f90f
commit
0ed5d29b44
|
@ -349,6 +349,11 @@ struct CodeCompletionBuilder {
|
|||
}
|
||||
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()));
|
||||
|
|
|
@ -704,6 +704,13 @@ enum class CompletionItemKind {
|
|||
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
|
||||
|
|
|
@ -2073,6 +2073,27 @@ TEST(SignatureHelpTest, ConstructorInitializeFields) {
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue