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/AST.cpp2
-rw-r--r--clang-tools-extra/clangd/AST.h2
-rw-r--r--clang-tools-extra/clangd/ClangdLSPServer.cpp38
-rw-r--r--clang-tools-extra/clangd/ClangdServer.cpp4
-rw-r--r--clang-tools-extra/clangd/CodeComplete.cpp69
-rw-r--r--clang-tools-extra/clangd/CodeCompletionStrings.cpp9
-rw-r--r--clang-tools-extra/clangd/Diagnostics.cpp6
-rw-r--r--clang-tools-extra/clangd/FSProvider.cpp3
-rw-r--r--clang-tools-extra/clangd/FileDistance.h6
-rw-r--r--clang-tools-extra/clangd/FindSymbols.cpp2
-rw-r--r--clang-tools-extra/clangd/Protocol.cpp33
-rw-r--r--clang-tools-extra/clangd/TUScheduler.cpp13
-rw-r--r--clang-tools-extra/clangd/TUScheduler.h13
-rw-r--r--clang-tools-extra/clangd/Trace.cpp4
-rw-r--r--clang-tools-extra/clangd/URI.cpp2
-rw-r--r--clang-tools-extra/clangd/XRefs.cpp6
16 files changed, 103 insertions, 109 deletions
diff --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp
index dea45671e55..7c270ee0d86 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -44,7 +44,7 @@ bool isSpelledInSourceCode(const Decl *D) {
bool isImplementationDetail(const Decl *D) { return !isSpelledInSourceCode(D); }
-SourceLocation findNameLoc(const clang::Decl* D) {
+SourceLocation findNameLoc(const clang::Decl *D) {
const auto &SM = D->getASTContext().getSourceManager();
if (!isSpelledInSourceCode(D))
// Use the expansion location as spelling location is not interesting.
diff --git a/clang-tools-extra/clangd/AST.h b/clang-tools-extra/clangd/AST.h
index aa787acee70..85eb47c417b 100644
--- a/clang-tools-extra/clangd/AST.h
+++ b/clang-tools-extra/clangd/AST.h
@@ -14,9 +14,9 @@
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_AST_H_
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_AST_H_
+#include "index/Index.h"
#include "clang/AST/Decl.h"
#include "clang/Basic/SourceLocation.h"
-#include "index/Index.h"
namespace clang {
class SourceManager;
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 012302d132f..c2b09943184 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -163,9 +163,9 @@ private:
Server(Other.Server), TraceArgs(Other.TraceArgs) {
Other.Server = nullptr;
}
- ReplyOnce& operator=(ReplyOnce&&) = delete;
+ ReplyOnce &operator=(ReplyOnce &&) = delete;
ReplyOnce(const ReplyOnce &) = delete;
- ReplyOnce& operator=(const ReplyOnce&) = delete;
+ ReplyOnce &operator=(const ReplyOnce &) = delete;
~ReplyOnce() {
if (Server && !Replied) {
@@ -614,23 +614,23 @@ void ClangdLSPServer::onCodeAction(const CodeActionParams &Params,
void ClangdLSPServer::onCompletion(const TextDocumentPositionParams &Params,
Callback<CompletionList> Reply) {
- Server->codeComplete(Params.textDocument.uri.file(), Params.position, CCOpts,
- Bind(
- [this](decltype(Reply) Reply,
- Expected<CodeCompleteResult> List) {
- if (!List)
- return Reply(List.takeError());
- CompletionList LSPList;
- LSPList.isIncomplete = List->HasMore;
- for (const auto &R : List->Completions) {
- CompletionItem C = R.render(CCOpts);
- C.kind = adjustKindToCapability(
- C.kind, SupportedCompletionItemKinds);
- LSPList.items.push_back(std::move(C));
- }
- return Reply(std::move(LSPList));
- },
- std::move(Reply)));
+ Server->codeComplete(
+ Params.textDocument.uri.file(), Params.position, CCOpts,
+ Bind(
+ [this](decltype(Reply) Reply, Expected<CodeCompleteResult> List) {
+ if (!List)
+ return Reply(List.takeError());
+ CompletionList LSPList;
+ LSPList.isIncomplete = List->HasMore;
+ for (const auto &R : List->Completions) {
+ CompletionItem C = R.render(CCOpts);
+ C.kind =
+ adjustKindToCapability(C.kind, SupportedCompletionItemKinds);
+ LSPList.items.push_back(std::move(C));
+ }
+ return Reply(std::move(LSPList));
+ },
+ std::move(Reply)));
}
void ClangdLSPServer::onSignatureHelp(const TextDocumentPositionParams &Params,
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index da491ee4fbe..e554ade874d 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -159,9 +159,7 @@ void ClangdServer::addDocument(PathRef File, StringRef Contents,
WantDiags);
}
-void ClangdServer::removeDocument(PathRef File) {
- WorkScheduler.remove(File);
-}
+void ClangdServer::removeDocument(PathRef File) { WorkScheduler.remove(File); }
void ClangdServer::codeComplete(PathRef File, Position Pos,
const clangd::CodeCompleteOptions &Opts,
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 74b90bcf7f8..3a1c4ab5aec 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -879,38 +879,37 @@ public:
IndexRequest.IDs.size(), FetchedDocs.size());
}
- llvm::sort(
- ScoredSignatures,
- [](const ScoredSignature &L, const ScoredSignature &R) {
- // Ordering follows:
- // - Less number of parameters is better.
- // - Function is better than FunctionType which is better than
- // Function Template.
- // - High score is better.
- // - Shorter signature is better.
- // - Alphebatically smaller is better.
- if (L.Quality.NumberOfParameters != R.Quality.NumberOfParameters)
- return L.Quality.NumberOfParameters < R.Quality.NumberOfParameters;
- if (L.Quality.NumberOfOptionalParameters !=
- R.Quality.NumberOfOptionalParameters)
- return L.Quality.NumberOfOptionalParameters <
- R.Quality.NumberOfOptionalParameters;
- if (L.Quality.Kind != R.Quality.Kind) {
- using OC = CodeCompleteConsumer::OverloadCandidate;
- switch (L.Quality.Kind) {
- case OC::CK_Function:
- return true;
- case OC::CK_FunctionType:
- return R.Quality.Kind != OC::CK_Function;
- case OC::CK_FunctionTemplate:
- return false;
- }
- llvm_unreachable("Unknown overload candidate type.");
- }
- if (L.Signature.label.size() != R.Signature.label.size())
- return L.Signature.label.size() < R.Signature.label.size();
- return L.Signature.label < R.Signature.label;
- });
+ llvm::sort(ScoredSignatures, [](const ScoredSignature &L,
+ const ScoredSignature &R) {
+ // Ordering follows:
+ // - Less number of parameters is better.
+ // - Function is better than FunctionType which is better than
+ // Function Template.
+ // - High score is better.
+ // - Shorter signature is better.
+ // - Alphebatically smaller is better.
+ if (L.Quality.NumberOfParameters != R.Quality.NumberOfParameters)
+ return L.Quality.NumberOfParameters < R.Quality.NumberOfParameters;
+ if (L.Quality.NumberOfOptionalParameters !=
+ R.Quality.NumberOfOptionalParameters)
+ return L.Quality.NumberOfOptionalParameters <
+ R.Quality.NumberOfOptionalParameters;
+ if (L.Quality.Kind != R.Quality.Kind) {
+ using OC = CodeCompleteConsumer::OverloadCandidate;
+ switch (L.Quality.Kind) {
+ case OC::CK_Function:
+ return true;
+ case OC::CK_FunctionType:
+ return R.Quality.Kind != OC::CK_Function;
+ case OC::CK_FunctionTemplate:
+ return false;
+ }
+ llvm_unreachable("Unknown overload candidate type.");
+ }
+ if (L.Signature.label.size() != R.Signature.label.size())
+ return L.Signature.label.size() < R.Signature.label.size();
+ return L.Signature.label < R.Signature.label;
+ });
for (auto &SS : ScoredSignatures) {
auto IndexDocIt =
@@ -1224,15 +1223,15 @@ SmallVector<StringRef, 1> getRankedIncludes(const Symbol &Sym) {
// - TopN determines the results with the best score.
class CodeCompleteFlow {
PathRef FileName;
- IncludeStructure Includes; // Complete once the compiler runs.
+ IncludeStructure Includes; // Complete once the compiler runs.
SpeculativeFuzzyFind *SpecFuzzyFind; // Can be nullptr.
const CodeCompleteOptions &Opts;
// Sema takes ownership of Recorder. Recorder is valid until Sema cleanup.
CompletionRecorder *Recorder = nullptr;
int NSema = 0, NIndex = 0, NBoth = 0; // Counters for logging.
- bool Incomplete = false; // Would more be available with a higher limit?
- Optional<FuzzyMatcher> Filter; // Initialized once Sema runs.
+ bool Incomplete = false; // Would more be available with a higher limit?
+ Optional<FuzzyMatcher> Filter; // Initialized once Sema runs.
std::vector<std::string> QueryScopes; // Initialized once Sema runs.
// Initialized once QueryScopes is initialized, if there are scopes.
Optional<ScopeDistance> ScopeProximity;
diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.cpp b/clang-tools-extra/clangd/CodeCompletionStrings.cpp
index f7e31619dfa..eeec99cafe9 100644
--- a/clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ b/clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -69,7 +69,8 @@ std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &Decl) {
// Sanity check that the comment does not come from the PCH. We choose to not
// write them into PCH, because they are racy and slow to load.
assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
- std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
+ std::string Doc =
+ RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
return looksLikeDocComment(Doc) ? Doc : "";
}
@@ -96,12 +97,12 @@ void getSignature(const CodeCompletionString &CCS, std::string *Signature,
// treat them carefully. For Objective-C methods, all typed-text chunks
// will end in ':' (unless there are no arguments, in which case we
// can safely treat them as C++).
- if (!StringRef(Chunk.Text).endswith(":")) { // Treat as C++.
+ if (!StringRef(Chunk.Text).endswith(":")) { // Treat as C++.
if (RequiredQualifiers)
*RequiredQualifiers = std::move(*Signature);
Signature->clear();
Snippet->clear();
- } else { // Objective-C method with args.
+ } else { // Objective-C method with args.
// If this is the first TypedText to the Objective-C method, discard any
// text that we've previously seen (such as previous parameter selector,
// which will be marked as Informative text).
@@ -111,7 +112,7 @@ void getSignature(const CodeCompletionString &CCS, std::string *Signature,
if (!HadObjCArguments) {
HadObjCArguments = true;
Signature->clear();
- } else { // Subsequent argument, considered part of snippet/signature.
+ } else { // Subsequent argument, considered part of snippet/signature.
*Signature += Chunk.Text;
*Snippet += Chunk.Text;
}
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp
index a8bfa29eec2..ca43be8410c 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -240,9 +240,9 @@ CodeAction toCodeAction(const Fix &F, const URIForFile &File) {
return Action;
}
-void toLSPDiags(
- const Diag &D, const URIForFile &File, const ClangdDiagnosticOptions &Opts,
- function_ref<void(clangd::Diagnostic, ArrayRef<Fix>)> OutFn) {
+void toLSPDiags(const Diag &D, const URIForFile &File,
+ const ClangdDiagnosticOptions &Opts,
+ function_ref<void(clangd::Diagnostic, ArrayRef<Fix>)> OutFn) {
auto FillBasicFields = [](const DiagBase &D) -> clangd::Diagnostic {
clangd::Diagnostic Res;
Res.range = D.Range;
diff --git a/clang-tools-extra/clangd/FSProvider.cpp b/clang-tools-extra/clangd/FSProvider.cpp
index ccb64c561f5..99e7596e83a 100644
--- a/clang-tools-extra/clangd/FSProvider.cpp
+++ b/clang-tools-extra/clangd/FSProvider.cpp
@@ -41,8 +41,7 @@ public:
StringRef FileName = llvm::sys::path::filename(Path);
if (FileName.startswith("preamble-") && FileName.endswith(".pch"))
return File;
- return std::unique_ptr<VolatileFile>(
- new VolatileFile(std::move(*File)));
+ return std::unique_ptr<VolatileFile>(new VolatileFile(std::move(*File)));
}
private:
diff --git a/clang-tools-extra/clangd/FileDistance.h b/clang-tools-extra/clangd/FileDistance.h
index d60afa28ce3..2623ce7663f 100644
--- a/clang-tools-extra/clangd/FileDistance.h
+++ b/clang-tools-extra/clangd/FileDistance.h
@@ -54,9 +54,9 @@ namespace clang {
namespace clangd {
struct FileDistanceOptions {
- unsigned UpCost = 2; // |foo/bar.h -> foo|
- unsigned DownCost = 1; // |foo -> foo/bar.h|
- unsigned IncludeCost = 2; // |foo.cc -> included_header.h|
+ unsigned UpCost = 2; // |foo/bar.h -> foo|
+ unsigned DownCost = 1; // |foo -> foo/bar.h|
+ unsigned IncludeCost = 2; // |foo.cc -> included_header.h|
bool AllowDownTraversalFromRoot = true; // | / -> /a |
};
diff --git a/clang-tools-extra/clangd/FindSymbols.cpp b/clang-tools-extra/clangd/FindSymbols.cpp
index aca17f9e5f5..92769bb317b 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -190,7 +190,7 @@ llvm::Optional<DocumentSymbol> declToSym(ASTContext &Ctx, const NamedDecl &ND) {
// sourceLocToPosition won't switch files, so we call getSpellingLoc on top of
// that to make sure it does not switch files.
// FIXME: sourceLocToPosition should not switch files!
- SourceLocation BeginLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getBeginLoc()));
+ SourceLocation BeginLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getBeginLoc()));
SourceLocation EndLoc = SM.getSpellingLoc(SM.getFileLoc(ND.getEndLoc()));
if (NameLoc.isInvalid() || BeginLoc.isInvalid() || EndLoc.isInvalid())
return llvm::None;
diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp
index 3c1fc7f0050..972ba25fbe1 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -386,21 +386,21 @@ bool fromJSON(const json::Value &Params, CodeActionContext &R) {
raw_ostream &operator<<(raw_ostream &OS, const Diagnostic &D) {
OS << D.range << " [";
switch (D.severity) {
- case 1:
- OS << "error";
- break;
- case 2:
- OS << "warning";
- break;
- case 3:
- OS << "note";
- break;
- case 4:
- OS << "remark";
- break;
- default:
- OS << "diagnostic";
- break;
+ case 1:
+ OS << "error";
+ break;
+ case 2:
+ OS << "warning";
+ break;
+ case 3:
+ OS << "note";
+ break;
+ case 4:
+ OS << "remark";
+ break;
+ default:
+ OS << "diagnostic";
+ break;
}
return OS << '(' << D.severity << "): " << D.message << "]";
}
@@ -718,7 +718,8 @@ json::Value toJSON(const DocumentHighlight &DH) {
llvm::json::Value toJSON(const FileStatus &FStatus) {
return json::Object{
- {"uri", FStatus.uri}, {"state", FStatus.state},
+ {"uri", FStatus.uri},
+ {"state", FStatus.state},
};
}
diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp
index a6260f95676..b7f79436104 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -18,8 +18,8 @@
// preamble. However, unlike AST, the same preamble can be read concurrently, so
// we run each of async preamble reads on its own thread.
//
-// To limit the concurrent load that clangd produces we maintain a semaphore that
-// keeps more than a fixed number of threads from running concurrently.
+// To limit the concurrent load that clangd produces we maintain a semaphore
+// that keeps more than a fixed number of threads from running concurrently.
//
// Rationale for cancelling updates.
// LSP clients can send updates to clangd on each keystroke. Some files take
@@ -334,8 +334,9 @@ ASTWorker::ASTWorker(PathRef FileName, TUScheduler::ASTCache &LRUCache,
bool StorePreamblesInMemory, ParsingCallbacks &Callbacks)
: IdleASTs(LRUCache), RunSync(RunSync), UpdateDebounce(UpdateDebounce),
FileName(FileName), StorePreambleInMemory(StorePreamblesInMemory),
- Callbacks(Callbacks), PCHs(std::move(PCHs)),
- Status{TUAction(TUAction::Idle, ""), TUStatus::BuildDetails()},
+ Callbacks(Callbacks),
+ PCHs(std::move(PCHs)), Status{TUAction(TUAction::Idle, ""),
+ TUStatus::BuildDetails()},
Barrier(Barrier), Done(false) {}
ASTWorker::~ASTWorker() {
@@ -537,9 +538,7 @@ void ASTWorker::getCurrentPreamble(
RequestsCV.notify_all();
}
-void ASTWorker::waitForFirstPreamble() const {
- PreambleWasBuilt.wait();
-}
+void ASTWorker::waitForFirstPreamble() const { PreambleWasBuilt.wait(); }
std::size_t ASTWorker::getUsedBytes() const {
// Note that we don't report the size of ASTs currently used for processing
diff --git a/clang-tools-extra/clangd/TUScheduler.h b/clang-tools-extra/clangd/TUScheduler.h
index 7aaaa08201d..5ab66d802eb 100644
--- a/clang-tools-extra/clangd/TUScheduler.h
+++ b/clang-tools-extra/clangd/TUScheduler.h
@@ -226,12 +226,13 @@ private:
/// propagated.
template <typename T>
std::future<T> runAsync(llvm::unique_function<T()> Action) {
- return std::async(std::launch::async,
- [](llvm::unique_function<T()> &&Action, Context Ctx) {
- WithContext WithCtx(std::move(Ctx));
- return Action();
- },
- std::move(Action), Context::current().clone());
+ return std::async(
+ std::launch::async,
+ [](llvm::unique_function<T()> &&Action, Context Ctx) {
+ WithContext WithCtx(std::move(Ctx));
+ return Action();
+ },
+ std::move(Action), Context::current().clone());
}
} // namespace clangd
diff --git a/clang-tools-extra/clangd/Trace.cpp b/clang-tools-extra/clangd/Trace.cpp
index 8fb19cc8847..4d73dabcf04 100644
--- a/clang-tools-extra/clangd/Trace.cpp
+++ b/clang-tools-extra/clangd/Trace.cpp
@@ -124,9 +124,7 @@ private:
}
// May be called by any thread.
- void markEnded() {
- EndTime = Tracer->timestamp();
- }
+ void markEnded() { EndTime = Tracer->timestamp(); }
private:
static int64_t nextID() {
diff --git a/clang-tools-extra/clangd/URI.cpp b/clang-tools-extra/clangd/URI.cpp
index 2a83862495d..64540c66798 100644
--- a/clang-tools-extra/clangd/URI.cpp
+++ b/clang-tools-extra/clangd/URI.cpp
@@ -229,7 +229,7 @@ Expected<std::string> URI::resolvePath(StringRef AbsPath, StringRef HintPath) {
if (!sys::path::is_absolute(AbsPath))
llvm_unreachable(("Not a valid absolute path: " + AbsPath).str().c_str());
for (auto &Entry : URISchemeRegistry::entries()) {
- auto S = Entry.instantiate();
+ auto S = Entry.instantiate();
auto U = S->uriFromAbsolutePath(AbsPath);
// For some paths, conversion to different URI schemes is impossible. These
// should be just skipped.
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index e4441370167..37df307cb59 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -46,8 +46,7 @@ void logIfOverflow(const SymbolLocation &Loc) {
// TUPath is used to resolve the path of URI.
// FIXME: figure out a good home for it, and share the implementation with
// FindSymbols.
-Optional<Location> toLSPLocation(const SymbolLocation &Loc,
- StringRef TUPath) {
+Optional<Location> toLSPLocation(const SymbolLocation &Loc, StringRef TUPath) {
if (!Loc)
return None;
auto Uri = URI::parse(Loc.FileURI);
@@ -336,8 +335,7 @@ std::vector<Location> findDefinitions(ParsedAST &AST, Position Pos,
for (auto It : CandidatesIndex)
QueryRequest.IDs.insert(It.first);
std::string TUPath;
- const FileEntry *FE =
- SM.getFileEntryForID(SM.getMainFileID());
+ const FileEntry *FE = SM.getFileEntryForID(SM.getMainFileID());
if (auto Path = getCanonicalPath(FE, SM))
TUPath = *Path;
// Query the index and populate the empty slot.
OpenPOWER on IntegriCloud