summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clangd')
-rw-r--r--clang-tools-extra/clangd/ClangdLSPServer.cpp8
-rw-r--r--clang-tools-extra/clangd/ClangdServer.cpp10
-rw-r--r--clang-tools-extra/clangd/ClangdServer.h2
-rw-r--r--clang-tools-extra/clangd/CodeComplete.cpp13
-rw-r--r--clang-tools-extra/clangd/CodeComplete.h4
5 files changed, 26 insertions, 11 deletions
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 7e708a29665..77a0bb1c01d 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -320,11 +320,15 @@ void ClangdLSPServer::onCodeAction(CodeActionParams &Params) {
void ClangdLSPServer::onCompletion(TextDocumentPositionParams &Params) {
Server.codeComplete(Params.textDocument.uri.file(), Params.position, CCOpts,
- [](llvm::Expected<CompletionList> List) {
+ [this](llvm::Expected<CodeCompleteResult> List) {
if (!List)
return replyError(ErrorCode::InvalidParams,
llvm::toString(List.takeError()));
- reply(*List);
+ CompletionList LSPList;
+ LSPList.isIncomplete = List->HasMore;
+ for (const auto &R : List->Completions)
+ LSPList.items.push_back(R.render(CCOpts));
+ reply(std::move(LSPList));
});
}
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 65cbfed56d1..947b34fd600 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -146,7 +146,7 @@ void ClangdServer::removeDocument(PathRef File) {
void ClangdServer::codeComplete(PathRef File, Position Pos,
const clangd::CodeCompleteOptions &Opts,
- Callback<CompletionList> CB) {
+ Callback<CodeCompleteResult> CB) {
// Copy completion options for passing them to async task handler.
auto CodeCompleteOpts = Opts;
if (!CodeCompleteOpts.Index) // Respect overridden index.
@@ -156,7 +156,7 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
std::shared_ptr<PCHContainerOperations> PCHs = this->PCHs;
auto FS = FSProvider.getFileSystem();
auto Task = [PCHs, Pos, FS,
- CodeCompleteOpts](Path File, Callback<CompletionList> CB,
+ CodeCompleteOpts](Path File, Callback<CodeCompleteResult> CB,
llvm::Expected<InputsAndPreamble> IP) {
if (!IP)
return CB(IP.takeError());
@@ -169,11 +169,7 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
File, IP->Command, PreambleData ? &PreambleData->Preamble : nullptr,
PreambleData ? PreambleData->Inclusions : std::vector<Inclusion>(),
IP->Contents, Pos, FS, PCHs, CodeCompleteOpts);
- CompletionList LSPResult;
- LSPResult.isIncomplete = Result.HasMore;
- for (const auto &Completion : Result.Completions)
- LSPResult.items.push_back(Completion.render(CodeCompleteOpts));
- CB(std::move(LSPResult));
+ CB(std::move(Result));
};
WorkScheduler.runWithPreamble("CodeComplete", File,
diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h
index 2da8518ea52..7550c28db44 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -141,7 +141,7 @@ public:
/// when codeComplete results become available.
void codeComplete(PathRef File, Position Pos,
const clangd::CodeCompleteOptions &Opts,
- Callback<CompletionList> CB);
+ Callback<CodeCompleteResult> CB);
/// Provide signature help for \p File at \p Pos. This method should only be
/// called for tracked files.
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 01cc4445003..03bef8eaa3a 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -1248,5 +1248,18 @@ CompletionItem CodeCompletion::render(const CodeCompleteOptions &Opts) const {
return LSP;
}
+raw_ostream &operator<<(raw_ostream &OS, const CodeCompletion &C) {
+ // For now just lean on CompletionItem.
+ return OS << C.render(CodeCompleteOptions());
+}
+
+raw_ostream &operator<<(raw_ostream &OS, const CodeCompleteResult &R) {
+ OS << "CodeCompleteResult: " << R.Completions.size() << (R.HasMore ? "+" : "")
+ << " items:\n";
+ for (const auto &C : R.Completions)
+ OS << C << "\n";
+ return OS;
+}
+
} // namespace clangd
} // namespace clang
diff --git a/clang-tools-extra/clangd/CodeComplete.h b/clang-tools-extra/clangd/CodeComplete.h
index 78a78b82047..3e37bf418be 100644
--- a/clang-tools-extra/clangd/CodeComplete.h
+++ b/clang-tools-extra/clangd/CodeComplete.h
@@ -102,7 +102,7 @@ struct CodeCompletion {
// - ReturnType may be empty
// - Documentation may be from one symbol, or a combination of several
// Other fields should apply equally to all bundled completions.
- unsigned BundleSize;
+ unsigned BundleSize = 1;
// The header through which this symbol could be included.
// Quoted string as expected by an #include directive, e.g. "<memory>".
// Empty for non-symbol completions, or when not known.
@@ -136,10 +136,12 @@ struct CodeCompletion {
// Serialize this to an LSP completion item. This is a lossy operation.
CompletionItem render(const CodeCompleteOptions &) const;
};
+raw_ostream &operator<<(raw_ostream &, const CodeCompletion &);
struct CodeCompleteResult {
std::vector<CodeCompletion> Completions;
bool HasMore = false;
};
+raw_ostream &operator<<(raw_ostream &, const CodeCompleteResult &);
/// Get code completions at a specified \p Pos in \p FileName.
CodeCompleteResult codeComplete(
OpenPOWER on IntegriCloud