2017-05-16 17:38:59 +08:00
|
|
|
//===--- ClangdServer.cpp - Main clangd server code --------------*- C++-*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ClangdServer.h"
|
2017-12-20 01:06:07 +08:00
|
|
|
#include "CodeComplete.h"
|
2018-02-16 22:15:55 +08:00
|
|
|
#include "Headers.h"
|
2017-12-19 20:23:48 +08:00
|
|
|
#include "SourceCode.h"
|
2017-12-20 01:06:07 +08:00
|
|
|
#include "XRefs.h"
|
2018-01-15 20:33:00 +08:00
|
|
|
#include "index/Merge.h"
|
2017-05-16 22:40:30 +08:00
|
|
|
#include "clang/Format/Format.h"
|
2017-05-16 17:38:59 +08:00
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
|
|
|
#include "clang/Frontend/CompilerInvocation.h"
|
|
|
|
#include "clang/Tooling/CompilationDatabase.h"
|
2017-11-16 02:04:56 +08:00
|
|
|
#include "clang/Tooling/Refactoring/RefactoringResultConsumer.h"
|
|
|
|
#include "clang/Tooling/Refactoring/Rename/RenamingAction.h"
|
2017-05-16 22:40:30 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2018-01-26 01:01:39 +08:00
|
|
|
#include "llvm/ADT/ScopeExit.h"
|
2017-10-26 20:28:13 +08:00
|
|
|
#include "llvm/Support/Errc.h"
|
2017-05-16 17:38:59 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2017-09-27 23:31:17 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2017-05-23 21:42:59 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <future>
|
2017-05-16 17:38:59 +08:00
|
|
|
|
2017-05-16 18:06:20 +08:00
|
|
|
using namespace clang;
|
2017-05-16 17:38:59 +08:00
|
|
|
using namespace clang::clangd;
|
|
|
|
|
2017-05-16 22:40:30 +08:00
|
|
|
namespace {
|
|
|
|
|
2018-01-31 16:51:16 +08:00
|
|
|
void ignoreError(llvm::Error Err) {
|
|
|
|
handleAllErrors(std::move(Err), [](const llvm::ErrorInfoBase &) {});
|
|
|
|
}
|
|
|
|
|
2017-06-28 18:34:50 +08:00
|
|
|
std::string getStandardResourceDir() {
|
|
|
|
static int Dummy; // Just an address in this process.
|
|
|
|
return CompilerInvocation::GetResourcesPath("clangd", (void *)&Dummy);
|
|
|
|
}
|
|
|
|
|
2017-11-09 19:30:04 +08:00
|
|
|
class RefactoringResultCollector final
|
|
|
|
: public tooling::RefactoringResultConsumer {
|
|
|
|
public:
|
|
|
|
void handleError(llvm::Error Err) override {
|
|
|
|
assert(!Result.hasValue());
|
|
|
|
// FIXME: figure out a way to return better message for DiagnosticError.
|
|
|
|
// clangd uses llvm::toString to convert the Err to string, however, for
|
|
|
|
// DiagnosticError, only "clang diagnostic" will be generated.
|
|
|
|
Result = std::move(Err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Using the handle(SymbolOccurrences) from parent class.
|
|
|
|
using tooling::RefactoringResultConsumer::handle;
|
|
|
|
|
|
|
|
void handle(tooling::AtomicChanges SourceReplacements) override {
|
|
|
|
assert(!Result.hasValue());
|
|
|
|
Result = std::move(SourceReplacements);
|
|
|
|
}
|
|
|
|
|
|
|
|
Optional<Expected<tooling::AtomicChanges>> Result;
|
|
|
|
};
|
|
|
|
|
2017-05-16 22:40:30 +08:00
|
|
|
} // namespace
|
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
IntrusiveRefCntPtr<vfs::FileSystem> RealFileSystemProvider::getFileSystem() {
|
|
|
|
return vfs::getRealFileSystem();
|
2017-05-26 20:26:51 +08:00
|
|
|
}
|
|
|
|
|
2018-03-06 01:28:54 +08:00
|
|
|
ClangdServer::Options ClangdServer::optsForTest() {
|
|
|
|
ClangdServer::Options Opts;
|
|
|
|
Opts.UpdateDebounce = std::chrono::steady_clock::duration::zero(); // Faster!
|
|
|
|
Opts.StorePreamblesInMemory = true;
|
|
|
|
Opts.AsyncThreadsCount = 4; // Consistent!
|
|
|
|
return Opts;
|
|
|
|
}
|
|
|
|
|
2017-11-24 00:58:22 +08:00
|
|
|
ClangdServer::ClangdServer(GlobalCompilationDatabase &CDB,
|
|
|
|
FileSystemProvider &FSProvider,
|
2018-03-06 01:28:54 +08:00
|
|
|
DiagnosticsConsumer &DiagConsumer,
|
|
|
|
const Options &Opts)
|
|
|
|
: CompileArgs(CDB, Opts.ResourceDir ? Opts.ResourceDir->str()
|
|
|
|
: getStandardResourceDir()),
|
2018-01-25 22:19:21 +08:00
|
|
|
DiagConsumer(DiagConsumer), FSProvider(FSProvider),
|
2018-03-06 01:28:54 +08:00
|
|
|
FileIdx(Opts.BuildDynamicSymbolIndex ? new FileIndex() : nullptr),
|
2018-01-31 16:51:16 +08:00
|
|
|
PCHs(std::make_shared<PCHContainerOperations>()),
|
|
|
|
// Pass a callback into `WorkScheduler` to extract symbols from a newly
|
|
|
|
// parsed file and rebuild the file index synchronously each time an AST
|
|
|
|
// is parsed.
|
2017-12-20 02:00:37 +08:00
|
|
|
// FIXME(ioeric): this can be slow and we may be able to index on less
|
|
|
|
// critical paths.
|
2018-03-06 01:28:54 +08:00
|
|
|
WorkScheduler(Opts.AsyncThreadsCount, Opts.StorePreamblesInMemory,
|
[clangd] Pass Context implicitly using TLS.
Summary:
Instead of passing Context explicitly around, we now have a thread-local
Context object `Context::current()` which is an implicit argument to
every function.
Most manipulation of this should use the WithContextValue helper, which
augments the current Context to add a single KV pair, and restores the
old context on destruction.
Advantages are:
- less boilerplate in functions that just propagate contexts
- reading most code doesn't require understanding context at all, and
using context as values in fewer places still
- fewer options to pass the "wrong" context when it changes within a
scope (e.g. when using Span)
- contexts pass through interfaces we can't modify, such as VFS
- propagating contexts across threads was slightly tricky (e.g.
copy vs move, no move-init in lambdas), and is now encapsulated in
the threadpool
Disadvantages are all the usual TLS stuff - hidden magic, and
potential for higher memory usage on threads that don't use the
context. (In practice, it's just one pointer)
Reviewers: ilya-biryukov
Subscribers: klimek, jkorous-apple, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D42517
llvm-svn: 323872
2018-01-31 21:40:48 +08:00
|
|
|
FileIdx
|
|
|
|
? [this](PathRef Path,
|
|
|
|
ParsedAST *AST) { FileIdx->update(Path, AST); }
|
2018-03-02 16:56:37 +08:00
|
|
|
: ASTParsedCallback(),
|
2018-03-06 01:28:54 +08:00
|
|
|
Opts.UpdateDebounce) {
|
|
|
|
if (FileIdx && Opts.StaticIndex) {
|
|
|
|
MergedIndex = mergeIndex(FileIdx.get(), Opts.StaticIndex);
|
2018-01-15 20:33:00 +08:00
|
|
|
Index = MergedIndex.get();
|
|
|
|
} else if (FileIdx)
|
|
|
|
Index = FileIdx.get();
|
2018-03-06 01:28:54 +08:00
|
|
|
else if (Opts.StaticIndex)
|
|
|
|
Index = Opts.StaticIndex;
|
2018-01-15 20:33:00 +08:00
|
|
|
else
|
|
|
|
Index = nullptr;
|
|
|
|
}
|
2017-05-16 17:38:59 +08:00
|
|
|
|
2017-09-27 23:31:17 +08:00
|
|
|
void ClangdServer::setRootPath(PathRef RootPath) {
|
|
|
|
std::string NewRootPath = llvm::sys::path::convert_to_slash(
|
|
|
|
RootPath, llvm::sys::path::Style::posix);
|
|
|
|
if (llvm::sys::fs::is_directory(NewRootPath))
|
|
|
|
this->RootPath = NewRootPath;
|
|
|
|
}
|
|
|
|
|
2018-02-22 21:11:12 +08:00
|
|
|
void ClangdServer::addDocument(PathRef File, StringRef Contents,
|
|
|
|
WantDiagnostics WantDiags) {
|
2017-05-23 21:42:59 +08:00
|
|
|
DocVersion Version = DraftMgr.updateDraft(File, Contents);
|
2018-02-13 16:59:23 +08:00
|
|
|
scheduleReparseAndDiags(File, VersionedDraft{Version, Contents.str()},
|
2018-03-13 07:22:35 +08:00
|
|
|
WantDiags, FSProvider.getFileSystem());
|
2017-05-16 17:38:59 +08:00
|
|
|
}
|
|
|
|
|
2018-02-08 15:37:35 +08:00
|
|
|
void ClangdServer::removeDocument(PathRef File) {
|
2017-08-14 16:17:24 +08:00
|
|
|
DraftMgr.removeDraft(File);
|
2018-01-25 22:19:21 +08:00
|
|
|
CompileArgs.invalidate(File);
|
2018-02-08 15:37:35 +08:00
|
|
|
WorkScheduler.remove(File);
|
2017-05-16 17:38:59 +08:00
|
|
|
}
|
|
|
|
|
2018-02-13 16:59:23 +08:00
|
|
|
void ClangdServer::forceReparse(PathRef File) {
|
2017-08-14 16:37:32 +08:00
|
|
|
auto FileContents = DraftMgr.getDraft(File);
|
|
|
|
assert(FileContents.Draft &&
|
|
|
|
"forceReparse() was called for non-added document");
|
|
|
|
|
2018-01-25 22:19:21 +08:00
|
|
|
// forceReparse promises to request new compilation flags from CDB, so we
|
|
|
|
// remove any cahced flags.
|
|
|
|
CompileArgs.invalidate(File);
|
|
|
|
|
2018-02-22 21:11:12 +08:00
|
|
|
scheduleReparseAndDiags(File, std::move(FileContents), WantDiagnostics::Yes,
|
2018-03-13 07:22:35 +08:00
|
|
|
FSProvider.getFileSystem());
|
2017-05-26 20:26:51 +08:00
|
|
|
}
|
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
void ClangdServer::codeComplete(PathRef File, Position Pos,
|
|
|
|
const clangd::CodeCompleteOptions &Opts,
|
|
|
|
Callback<CompletionList> CB) {
|
2017-12-05 18:42:57 +08:00
|
|
|
// Copy completion options for passing them to async task handler.
|
|
|
|
auto CodeCompleteOpts = Opts;
|
2018-01-15 20:33:00 +08:00
|
|
|
if (!CodeCompleteOpts.Index) // Respect overridden index.
|
|
|
|
CodeCompleteOpts.Index = Index;
|
2018-01-09 22:39:27 +08:00
|
|
|
|
2018-02-28 01:15:50 +08:00
|
|
|
VersionedDraft Latest = DraftMgr.getDraft(File);
|
2018-03-13 07:22:35 +08:00
|
|
|
if (!Latest.Draft)
|
|
|
|
return CB(llvm::make_error<llvm::StringError>(
|
|
|
|
"codeComplete called for non-added document",
|
|
|
|
llvm::errc::invalid_argument));
|
2018-01-31 16:51:16 +08:00
|
|
|
|
2018-01-09 22:39:27 +08:00
|
|
|
// Copy PCHs to avoid accessing this->PCHs concurrently
|
|
|
|
std::shared_ptr<PCHContainerOperations> PCHs = this->PCHs;
|
2018-03-13 07:22:35 +08:00
|
|
|
auto FS = FSProvider.getFileSystem();
|
|
|
|
auto Task = [PCHs, Pos, FS, CodeCompleteOpts](
|
|
|
|
std::string Contents, Path File, Callback<CompletionList> CB,
|
[clangd] Pass Context implicitly using TLS.
Summary:
Instead of passing Context explicitly around, we now have a thread-local
Context object `Context::current()` which is an implicit argument to
every function.
Most manipulation of this should use the WithContextValue helper, which
augments the current Context to add a single KV pair, and restores the
old context on destruction.
Advantages are:
- less boilerplate in functions that just propagate contexts
- reading most code doesn't require understanding context at all, and
using context as values in fewer places still
- fewer options to pass the "wrong" context when it changes within a
scope (e.g. when using Span)
- contexts pass through interfaces we can't modify, such as VFS
- propagating contexts across threads was slightly tricky (e.g.
copy vs move, no move-init in lambdas), and is now encapsulated in
the threadpool
Disadvantages are all the usual TLS stuff - hidden magic, and
potential for higher memory usage on threads that don't use the
context. (In practice, it's just one pointer)
Reviewers: ilya-biryukov
Subscribers: klimek, jkorous-apple, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D42517
llvm-svn: 323872
2018-01-31 21:40:48 +08:00
|
|
|
llvm::Expected<InputsAndPreamble> IP) {
|
2018-01-31 16:51:16 +08:00
|
|
|
assert(IP && "error when trying to read preamble for codeComplete");
|
|
|
|
auto PreambleData = IP->Preamble;
|
|
|
|
auto &Command = IP->Inputs.CompileCommand;
|
|
|
|
|
|
|
|
// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
|
|
|
|
// both the old and the new version in case only one of them matches.
|
|
|
|
CompletionList Result = clangd::codeComplete(
|
[clangd] Pass Context implicitly using TLS.
Summary:
Instead of passing Context explicitly around, we now have a thread-local
Context object `Context::current()` which is an implicit argument to
every function.
Most manipulation of this should use the WithContextValue helper, which
augments the current Context to add a single KV pair, and restores the
old context on destruction.
Advantages are:
- less boilerplate in functions that just propagate contexts
- reading most code doesn't require understanding context at all, and
using context as values in fewer places still
- fewer options to pass the "wrong" context when it changes within a
scope (e.g. when using Span)
- contexts pass through interfaces we can't modify, such as VFS
- propagating contexts across threads was slightly tricky (e.g.
copy vs move, no move-init in lambdas), and is now encapsulated in
the threadpool
Disadvantages are all the usual TLS stuff - hidden magic, and
potential for higher memory usage on threads that don't use the
context. (In practice, it's just one pointer)
Reviewers: ilya-biryukov
Subscribers: klimek, jkorous-apple, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D42517
llvm-svn: 323872
2018-01-31 21:40:48 +08:00
|
|
|
File, Command, PreambleData ? &PreambleData->Preamble : nullptr,
|
2018-03-13 07:22:35 +08:00
|
|
|
Contents, Pos, FS, PCHs, CodeCompleteOpts);
|
|
|
|
CB(std::move(Result));
|
2018-01-31 16:51:16 +08:00
|
|
|
};
|
|
|
|
|
2018-02-23 15:54:17 +08:00
|
|
|
WorkScheduler.runWithPreamble(
|
|
|
|
"CodeComplete", File,
|
2018-03-13 07:22:35 +08:00
|
|
|
Bind(Task, std::move(*Latest.Draft), File.str(), std::move(CB)));
|
2017-05-16 17:38:59 +08:00
|
|
|
}
|
2017-05-23 21:42:59 +08:00
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
void ClangdServer::signatureHelp(PathRef File, Position Pos,
|
|
|
|
Callback<SignatureHelp> CB) {
|
2018-02-28 01:15:50 +08:00
|
|
|
VersionedDraft Latest = DraftMgr.getDraft(File);
|
|
|
|
if (!Latest.Draft)
|
2018-03-13 07:22:35 +08:00
|
|
|
return CB(llvm::make_error<llvm::StringError>(
|
2018-02-28 01:15:50 +08:00
|
|
|
"signatureHelp is called for non-added document",
|
|
|
|
llvm::errc::invalid_argument));
|
2017-10-06 19:54:17 +08:00
|
|
|
|
2018-02-15 21:15:47 +08:00
|
|
|
auto PCHs = this->PCHs;
|
2018-03-13 07:22:35 +08:00
|
|
|
auto FS = FSProvider.getFileSystem();
|
|
|
|
auto Action = [Pos, FS, PCHs](std::string Contents, Path File,
|
|
|
|
Callback<SignatureHelp> CB,
|
|
|
|
llvm::Expected<InputsAndPreamble> IP) {
|
2018-01-31 16:51:16 +08:00
|
|
|
if (!IP)
|
2018-03-13 07:22:35 +08:00
|
|
|
return CB(IP.takeError());
|
2018-02-15 21:15:47 +08:00
|
|
|
|
2018-01-31 16:51:16 +08:00
|
|
|
auto PreambleData = IP->Preamble;
|
|
|
|
auto &Command = IP->Inputs.CompileCommand;
|
2018-03-13 07:22:35 +08:00
|
|
|
CB(clangd::signatureHelp(File, Command,
|
|
|
|
PreambleData ? &PreambleData->Preamble : nullptr,
|
|
|
|
Contents, Pos, FS, PCHs));
|
2018-01-31 16:51:16 +08:00
|
|
|
};
|
2018-02-15 21:15:47 +08:00
|
|
|
|
2018-02-28 01:15:50 +08:00
|
|
|
WorkScheduler.runWithPreamble(
|
|
|
|
"SignatureHelp", File,
|
2018-03-13 07:22:35 +08:00
|
|
|
Bind(Action, std::move(*Latest.Draft), File.str(), std::move(CB)));
|
2017-10-06 19:54:17 +08:00
|
|
|
}
|
|
|
|
|
2017-12-13 04:25:06 +08:00
|
|
|
llvm::Expected<tooling::Replacements>
|
|
|
|
ClangdServer::formatRange(StringRef Code, PathRef File, Range Rng) {
|
2017-05-16 22:40:30 +08:00
|
|
|
size_t Begin = positionToOffset(Code, Rng.start);
|
|
|
|
size_t Len = positionToOffset(Code, Rng.end) - Begin;
|
|
|
|
return formatCode(Code, File, {tooling::Range(Begin, Len)});
|
|
|
|
}
|
|
|
|
|
2017-12-13 04:25:06 +08:00
|
|
|
llvm::Expected<tooling::Replacements> ClangdServer::formatFile(StringRef Code,
|
|
|
|
PathRef File) {
|
2017-05-16 22:40:30 +08:00
|
|
|
// Format everything.
|
|
|
|
return formatCode(Code, File, {tooling::Range(0, Code.size())});
|
|
|
|
}
|
|
|
|
|
2017-12-13 04:25:06 +08:00
|
|
|
llvm::Expected<tooling::Replacements>
|
|
|
|
ClangdServer::formatOnType(StringRef Code, PathRef File, Position Pos) {
|
2017-05-16 22:40:30 +08:00
|
|
|
// Look for the previous opening brace from the character position and
|
|
|
|
// format starting from there.
|
|
|
|
size_t CursorPos = positionToOffset(Code, Pos);
|
|
|
|
size_t PreviousLBracePos = StringRef(Code).find_last_of('{', CursorPos);
|
|
|
|
if (PreviousLBracePos == StringRef::npos)
|
|
|
|
PreviousLBracePos = CursorPos;
|
2017-12-19 20:23:48 +08:00
|
|
|
size_t Len = CursorPos - PreviousLBracePos;
|
2017-05-16 22:40:30 +08:00
|
|
|
|
|
|
|
return formatCode(Code, File, {tooling::Range(PreviousLBracePos, Len)});
|
|
|
|
}
|
2017-05-16 17:38:59 +08:00
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
|
|
|
|
Callback<std::vector<tooling::Replacement>> CB) {
|
2018-02-15 21:15:47 +08:00
|
|
|
auto Action = [Pos](Path File, std::string NewName,
|
2018-03-13 07:22:35 +08:00
|
|
|
Callback<std::vector<tooling::Replacement>> CB,
|
2018-02-15 21:15:47 +08:00
|
|
|
Expected<InputsAndAST> InpAST) {
|
2018-01-31 16:51:16 +08:00
|
|
|
if (!InpAST)
|
2018-03-13 07:22:35 +08:00
|
|
|
return CB(InpAST.takeError());
|
2018-01-31 16:51:16 +08:00
|
|
|
auto &AST = InpAST->AST;
|
|
|
|
|
|
|
|
RefactoringResultCollector ResultCollector;
|
|
|
|
const SourceManager &SourceMgr = AST.getASTContext().getSourceManager();
|
2017-11-09 19:30:04 +08:00
|
|
|
const FileEntry *FE =
|
|
|
|
SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
|
|
|
|
if (!FE)
|
2018-03-13 07:22:35 +08:00
|
|
|
return CB(llvm::make_error<llvm::StringError>(
|
2018-02-15 21:15:47 +08:00
|
|
|
"rename called for non-added document",
|
|
|
|
llvm::errc::invalid_argument));
|
2017-11-09 19:30:04 +08:00
|
|
|
SourceLocation SourceLocationBeg =
|
2018-01-31 16:51:16 +08:00
|
|
|
clangd::getBeginningOfIdentifier(AST, Pos, FE);
|
2017-11-09 19:30:04 +08:00
|
|
|
tooling::RefactoringRuleContext Context(
|
2018-01-31 16:51:16 +08:00
|
|
|
AST.getASTContext().getSourceManager());
|
|
|
|
Context.setASTContext(AST.getASTContext());
|
2017-11-09 19:30:04 +08:00
|
|
|
auto Rename = clang::tooling::RenameOccurrences::initiate(
|
2018-02-15 21:15:47 +08:00
|
|
|
Context, SourceRange(SourceLocationBeg), NewName);
|
2018-01-31 16:51:16 +08:00
|
|
|
if (!Rename)
|
2018-03-13 07:22:35 +08:00
|
|
|
return CB(Rename.takeError());
|
2018-01-31 16:51:16 +08:00
|
|
|
|
2017-11-09 19:30:04 +08:00
|
|
|
Rename->invoke(ResultCollector, Context);
|
2018-01-31 16:51:16 +08:00
|
|
|
|
|
|
|
assert(ResultCollector.Result.hasValue());
|
|
|
|
if (!ResultCollector.Result.getValue())
|
2018-03-13 07:22:35 +08:00
|
|
|
return CB(ResultCollector.Result->takeError());
|
2018-01-31 16:51:16 +08:00
|
|
|
|
|
|
|
std::vector<tooling::Replacement> Replacements;
|
|
|
|
for (const tooling::AtomicChange &Change : ResultCollector.Result->get()) {
|
|
|
|
tooling::Replacements ChangeReps = Change.getReplacements();
|
|
|
|
for (const auto &Rep : ChangeReps) {
|
|
|
|
// FIXME: Right now we only support renaming the main file, so we
|
|
|
|
// drop replacements not for the main file. In the future, we might
|
|
|
|
// consider to support:
|
|
|
|
// * rename in any included header
|
|
|
|
// * rename only in the "main" header
|
|
|
|
// * provide an error if there are symbols we won't rename (e.g.
|
|
|
|
// std::vector)
|
|
|
|
// * rename globally in project
|
|
|
|
// * rename in open files
|
|
|
|
if (Rep.getFilePath() == File)
|
|
|
|
Replacements.push_back(Rep);
|
|
|
|
}
|
2017-11-09 19:30:04 +08:00
|
|
|
}
|
2018-03-13 07:22:35 +08:00
|
|
|
return CB(std::move(Replacements));
|
2018-01-31 16:51:16 +08:00
|
|
|
};
|
2018-02-15 21:15:47 +08:00
|
|
|
|
|
|
|
WorkScheduler.runWithAST(
|
2018-03-13 07:22:35 +08:00
|
|
|
"Rename", File, Bind(Action, File.str(), NewName.str(), std::move(CB)));
|
2017-11-09 19:30:04 +08:00
|
|
|
}
|
|
|
|
|
2018-02-26 16:32:13 +08:00
|
|
|
/// Creates a `HeaderFile` from \p Header which can be either a URI or a literal
|
|
|
|
/// include.
|
|
|
|
static llvm::Expected<HeaderFile> toHeaderFile(StringRef Header,
|
|
|
|
llvm::StringRef HintPath) {
|
|
|
|
if (isLiteralInclude(Header))
|
|
|
|
return HeaderFile{Header.str(), /*Verbatim=*/true};
|
|
|
|
auto U = URI::parse(Header);
|
|
|
|
if (!U)
|
|
|
|
return U.takeError();
|
|
|
|
auto Resolved = URI::resolve(*U, HintPath);
|
|
|
|
if (!Resolved)
|
|
|
|
return Resolved.takeError();
|
|
|
|
return HeaderFile{std::move(*Resolved), /*Verbatim=*/false};
|
2018-03-06 20:56:18 +08:00
|
|
|
}
|
2018-02-26 16:32:13 +08:00
|
|
|
|
2018-02-16 22:15:55 +08:00
|
|
|
Expected<tooling::Replacements>
|
|
|
|
ClangdServer::insertInclude(PathRef File, StringRef Code,
|
2018-02-26 16:32:13 +08:00
|
|
|
StringRef DeclaringHeader,
|
|
|
|
StringRef InsertedHeader) {
|
|
|
|
assert(!DeclaringHeader.empty() && !InsertedHeader.empty());
|
2018-02-16 22:15:55 +08:00
|
|
|
std::string ToInclude;
|
2018-02-26 16:32:13 +08:00
|
|
|
auto ResolvedOrginal = toHeaderFile(DeclaringHeader, File);
|
|
|
|
if (!ResolvedOrginal)
|
|
|
|
return ResolvedOrginal.takeError();
|
|
|
|
auto ResolvedPreferred = toHeaderFile(InsertedHeader, File);
|
|
|
|
if (!ResolvedPreferred)
|
|
|
|
return ResolvedPreferred.takeError();
|
|
|
|
tooling::CompileCommand CompileCommand = CompileArgs.getCompileCommand(File);
|
2018-03-13 07:22:35 +08:00
|
|
|
auto Include =
|
|
|
|
calculateIncludePath(File, Code, *ResolvedOrginal, *ResolvedPreferred,
|
|
|
|
CompileCommand, FSProvider.getFileSystem());
|
2018-02-26 16:32:13 +08:00
|
|
|
if (!Include)
|
|
|
|
return Include.takeError();
|
|
|
|
if (Include->empty())
|
|
|
|
return tooling::Replacements();
|
|
|
|
ToInclude = std::move(*Include);
|
2018-02-16 22:15:55 +08:00
|
|
|
|
|
|
|
auto Style = format::getStyle("file", File, "llvm");
|
|
|
|
if (!Style) {
|
|
|
|
llvm::consumeError(Style.takeError());
|
|
|
|
// FIXME(ioeric): needs more consistent style support in clangd server.
|
|
|
|
Style = format::getLLVMStyle();
|
|
|
|
}
|
|
|
|
// Replacement with offset UINT_MAX and length 0 will be treated as include
|
|
|
|
// insertion.
|
|
|
|
tooling::Replacement R(File, /*Offset=*/UINT_MAX, 0, "#include " + ToInclude);
|
2018-03-06 18:42:50 +08:00
|
|
|
auto Replaces = format::cleanupAroundReplacements(
|
|
|
|
Code, tooling::Replacements(R), *Style);
|
|
|
|
if (!Replaces)
|
|
|
|
return Replaces;
|
|
|
|
return formatReplacements(Code, *Replaces, *Style);
|
2018-02-16 22:15:55 +08:00
|
|
|
}
|
|
|
|
|
2018-01-17 20:30:24 +08:00
|
|
|
llvm::Optional<std::string> ClangdServer::getDocument(PathRef File) {
|
|
|
|
auto Latest = DraftMgr.getDraft(File);
|
|
|
|
if (!Latest.Draft)
|
|
|
|
return llvm::None;
|
|
|
|
return std::move(*Latest.Draft);
|
2017-05-16 17:38:59 +08:00
|
|
|
}
|
|
|
|
|
2018-02-15 21:15:47 +08:00
|
|
|
void ClangdServer::dumpAST(PathRef File,
|
|
|
|
UniqueFunction<void(std::string)> Callback) {
|
|
|
|
auto Action = [](decltype(Callback) Callback,
|
|
|
|
llvm::Expected<InputsAndAST> InpAST) {
|
2018-01-31 16:51:16 +08:00
|
|
|
if (!InpAST) {
|
|
|
|
ignoreError(InpAST.takeError());
|
2018-02-15 21:15:47 +08:00
|
|
|
return Callback("<no-ast>");
|
2018-01-31 16:51:16 +08:00
|
|
|
}
|
|
|
|
std::string Result;
|
2017-08-01 23:51:38 +08:00
|
|
|
|
|
|
|
llvm::raw_string_ostream ResultOS(Result);
|
2018-01-31 16:51:16 +08:00
|
|
|
clangd::dumpAST(InpAST->AST, ResultOS);
|
2017-08-01 23:51:38 +08:00
|
|
|
ResultOS.flush();
|
2018-01-31 16:51:16 +08:00
|
|
|
|
2018-02-15 21:15:47 +08:00
|
|
|
Callback(Result);
|
2018-01-31 16:51:16 +08:00
|
|
|
};
|
2018-02-15 21:15:47 +08:00
|
|
|
|
2018-02-23 15:54:17 +08:00
|
|
|
WorkScheduler.runWithAST("DumpAST", File, Bind(Action, std::move(Callback)));
|
2017-05-16 17:38:59 +08:00
|
|
|
}
|
2017-06-29 00:12:10 +08:00
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
void ClangdServer::findDefinitions(PathRef File, Position Pos,
|
|
|
|
Callback<std::vector<Location>> CB) {
|
|
|
|
auto FS = FSProvider.getFileSystem();
|
|
|
|
auto Action = [Pos, FS](Callback<std::vector<Location>> CB,
|
|
|
|
llvm::Expected<InputsAndAST> InpAST) {
|
2018-01-31 16:51:16 +08:00
|
|
|
if (!InpAST)
|
2018-03-13 07:22:35 +08:00
|
|
|
return CB(InpAST.takeError());
|
|
|
|
CB(clangd::findDefinitions(InpAST->AST, Pos));
|
2018-01-31 16:51:16 +08:00
|
|
|
};
|
2018-02-15 21:15:47 +08:00
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB)));
|
2017-06-29 00:12:10 +08:00
|
|
|
}
|
2017-08-14 16:17:24 +08:00
|
|
|
|
2017-09-28 11:14:40 +08:00
|
|
|
llvm::Optional<Path> ClangdServer::switchSourceHeader(PathRef Path) {
|
|
|
|
|
|
|
|
StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx",
|
|
|
|
".c++", ".m", ".mm"};
|
|
|
|
StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx", ".inc"};
|
|
|
|
|
|
|
|
StringRef PathExt = llvm::sys::path::extension(Path);
|
|
|
|
|
|
|
|
// Lookup in a list of known extensions.
|
|
|
|
auto SourceIter =
|
|
|
|
std::find_if(std::begin(SourceExtensions), std::end(SourceExtensions),
|
|
|
|
[&PathExt](PathRef SourceExt) {
|
|
|
|
return SourceExt.equals_lower(PathExt);
|
|
|
|
});
|
|
|
|
bool IsSource = SourceIter != std::end(SourceExtensions);
|
|
|
|
|
|
|
|
auto HeaderIter =
|
|
|
|
std::find_if(std::begin(HeaderExtensions), std::end(HeaderExtensions),
|
|
|
|
[&PathExt](PathRef HeaderExt) {
|
|
|
|
return HeaderExt.equals_lower(PathExt);
|
|
|
|
});
|
|
|
|
|
|
|
|
bool IsHeader = HeaderIter != std::end(HeaderExtensions);
|
|
|
|
|
|
|
|
// We can only switch between extensions known extensions.
|
|
|
|
if (!IsSource && !IsHeader)
|
|
|
|
return llvm::None;
|
|
|
|
|
|
|
|
// Array to lookup extensions for the switch. An opposite of where original
|
|
|
|
// extension was found.
|
|
|
|
ArrayRef<StringRef> NewExts;
|
|
|
|
if (IsSource)
|
|
|
|
NewExts = HeaderExtensions;
|
|
|
|
else
|
|
|
|
NewExts = SourceExtensions;
|
|
|
|
|
|
|
|
// Storage for the new path.
|
|
|
|
SmallString<128> NewPath = StringRef(Path);
|
|
|
|
|
|
|
|
// Instance of vfs::FileSystem, used for file existence checks.
|
2018-03-13 07:22:35 +08:00
|
|
|
auto FS = FSProvider.getFileSystem();
|
2017-09-28 11:14:40 +08:00
|
|
|
|
|
|
|
// Loop through switched extension candidates.
|
|
|
|
for (StringRef NewExt : NewExts) {
|
|
|
|
llvm::sys::path::replace_extension(NewPath, NewExt);
|
|
|
|
if (FS->exists(NewPath))
|
|
|
|
return NewPath.str().str(); // First str() to convert from SmallString to
|
|
|
|
// StringRef, second to convert from StringRef
|
|
|
|
// to std::string
|
2017-10-06 22:39:39 +08:00
|
|
|
|
2017-09-28 11:14:40 +08:00
|
|
|
// Also check NewExt in upper-case, just in case.
|
|
|
|
llvm::sys::path::replace_extension(NewPath, NewExt.upper());
|
|
|
|
if (FS->exists(NewPath))
|
|
|
|
return NewPath.str().str();
|
|
|
|
}
|
|
|
|
|
|
|
|
return llvm::None;
|
|
|
|
}
|
|
|
|
|
2017-12-13 04:25:06 +08:00
|
|
|
llvm::Expected<tooling::Replacements>
|
|
|
|
ClangdServer::formatCode(llvm::StringRef Code, PathRef File,
|
|
|
|
ArrayRef<tooling::Range> Ranges) {
|
|
|
|
// Call clang-format.
|
2018-03-13 07:22:35 +08:00
|
|
|
auto FS = FSProvider.getFileSystem();
|
|
|
|
auto Style = format::getStyle("file", File, "LLVM", Code, FS.get());
|
2018-03-06 18:42:50 +08:00
|
|
|
if (!Style)
|
|
|
|
return Style.takeError();
|
|
|
|
|
|
|
|
tooling::Replacements IncludeReplaces =
|
|
|
|
format::sortIncludes(*Style, Code, Ranges, File);
|
|
|
|
auto Changed = tooling::applyAllReplacements(Code, IncludeReplaces);
|
|
|
|
if (!Changed)
|
|
|
|
return Changed.takeError();
|
|
|
|
|
|
|
|
return IncludeReplaces.merge(format::reformat(
|
|
|
|
Style.get(), *Changed,
|
|
|
|
tooling::calculateRangesAfterReplacements(IncludeReplaces, Ranges),
|
|
|
|
File));
|
2017-12-13 04:25:06 +08:00
|
|
|
}
|
|
|
|
|
2018-02-15 21:15:47 +08:00
|
|
|
void ClangdServer::findDocumentHighlights(
|
2018-03-13 07:22:35 +08:00
|
|
|
PathRef File, Position Pos, Callback<std::vector<DocumentHighlight>> CB) {
|
[clangd] Document highlights for clangd
Summary: Implementation of Document Highlights Request as described in
LSP.
Contributed by William Enright (nebiroth).
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Reviewed By: malaperle
Subscribers: mgrang, sammccall, klimek, ioeric, rwols, cfe-commits, arphaman, ilya-biryukov
Differential Revision: https://reviews.llvm.org/D38425
llvm-svn: 320474
2017-12-12 20:27:47 +08:00
|
|
|
auto FileContents = DraftMgr.getDraft(File);
|
|
|
|
if (!FileContents.Draft)
|
2018-03-13 07:22:35 +08:00
|
|
|
return CB(llvm::make_error<llvm::StringError>(
|
[clangd] Document highlights for clangd
Summary: Implementation of Document Highlights Request as described in
LSP.
Contributed by William Enright (nebiroth).
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Reviewed By: malaperle
Subscribers: mgrang, sammccall, klimek, ioeric, rwols, cfe-commits, arphaman, ilya-biryukov
Differential Revision: https://reviews.llvm.org/D38425
llvm-svn: 320474
2017-12-12 20:27:47 +08:00
|
|
|
"findDocumentHighlights called on non-added file",
|
2018-02-15 21:15:47 +08:00
|
|
|
llvm::errc::invalid_argument));
|
[clangd] Document highlights for clangd
Summary: Implementation of Document Highlights Request as described in
LSP.
Contributed by William Enright (nebiroth).
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Reviewed By: malaperle
Subscribers: mgrang, sammccall, klimek, ioeric, rwols, cfe-commits, arphaman, ilya-biryukov
Differential Revision: https://reviews.llvm.org/D38425
llvm-svn: 320474
2017-12-12 20:27:47 +08:00
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
auto FS = FSProvider.getFileSystem();
|
|
|
|
auto Action = [FS, Pos](Callback<std::vector<DocumentHighlight>> CB,
|
|
|
|
llvm::Expected<InputsAndAST> InpAST) {
|
2018-01-31 16:51:16 +08:00
|
|
|
if (!InpAST)
|
2018-03-13 07:22:35 +08:00
|
|
|
return CB(InpAST.takeError());
|
|
|
|
CB(clangd::findDocumentHighlights(InpAST->AST, Pos));
|
2018-01-31 16:51:16 +08:00
|
|
|
};
|
2018-02-15 21:15:47 +08:00
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
WorkScheduler.runWithAST("Highlights", File, Bind(Action, std::move(CB)));
|
[clangd] Implement textDocument/hover
Summary: Implemention of textDocument/hover as described in LSP definition.
This patch adds a basic Hover implementation. When hovering a variable,
function, method or namespace, clangd will return a text containing the
declaration's scope, as well as the declaration of the hovered entity.
For example, for a variable:
Declared in class Foo::Bar
int hello = 2
For macros, the macro definition is returned.
This patch doesn't include:
- markdown support (the client I use doesn't support it yet)
- range support (optional in the Hover response)
- comments associated to variables/functions/classes
They are kept as future work to keep this patch simpler.
I added tests in XRefsTests.cpp. hover.test contains one simple
smoketest to make sure the feature works from a black box perspective.
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Subscribers: sammccall, mgrang, klimek, rwols, ilya-biryukov, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D35894
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Signed-off-by: William Enright <william.enright@polymtl.ca>
llvm-svn: 325395
2018-02-17 05:38:15 +08:00
|
|
|
}
|
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
void ClangdServer::findHover(PathRef File, Position Pos, Callback<Hover> CB) {
|
[clangd] Implement textDocument/hover
Summary: Implemention of textDocument/hover as described in LSP definition.
This patch adds a basic Hover implementation. When hovering a variable,
function, method or namespace, clangd will return a text containing the
declaration's scope, as well as the declaration of the hovered entity.
For example, for a variable:
Declared in class Foo::Bar
int hello = 2
For macros, the macro definition is returned.
This patch doesn't include:
- markdown support (the client I use doesn't support it yet)
- range support (optional in the Hover response)
- comments associated to variables/functions/classes
They are kept as future work to keep this patch simpler.
I added tests in XRefsTests.cpp. hover.test contains one simple
smoketest to make sure the feature works from a black box perspective.
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Subscribers: sammccall, mgrang, klimek, rwols, ilya-biryukov, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D35894
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Signed-off-by: William Enright <william.enright@polymtl.ca>
llvm-svn: 325395
2018-02-17 05:38:15 +08:00
|
|
|
Hover FinalHover;
|
|
|
|
auto FileContents = DraftMgr.getDraft(File);
|
|
|
|
if (!FileContents.Draft)
|
2018-03-13 07:22:35 +08:00
|
|
|
return CB(llvm::make_error<llvm::StringError>(
|
[clangd] Implement textDocument/hover
Summary: Implemention of textDocument/hover as described in LSP definition.
This patch adds a basic Hover implementation. When hovering a variable,
function, method or namespace, clangd will return a text containing the
declaration's scope, as well as the declaration of the hovered entity.
For example, for a variable:
Declared in class Foo::Bar
int hello = 2
For macros, the macro definition is returned.
This patch doesn't include:
- markdown support (the client I use doesn't support it yet)
- range support (optional in the Hover response)
- comments associated to variables/functions/classes
They are kept as future work to keep this patch simpler.
I added tests in XRefsTests.cpp. hover.test contains one simple
smoketest to make sure the feature works from a black box perspective.
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Subscribers: sammccall, mgrang, klimek, rwols, ilya-biryukov, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D35894
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Signed-off-by: William Enright <william.enright@polymtl.ca>
llvm-svn: 325395
2018-02-17 05:38:15 +08:00
|
|
|
"findHover called on non-added file", llvm::errc::invalid_argument));
|
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
auto FS = FSProvider.getFileSystem();
|
|
|
|
auto Action = [Pos, FS](Callback<Hover> CB,
|
|
|
|
llvm::Expected<InputsAndAST> InpAST) {
|
[clangd] Implement textDocument/hover
Summary: Implemention of textDocument/hover as described in LSP definition.
This patch adds a basic Hover implementation. When hovering a variable,
function, method or namespace, clangd will return a text containing the
declaration's scope, as well as the declaration of the hovered entity.
For example, for a variable:
Declared in class Foo::Bar
int hello = 2
For macros, the macro definition is returned.
This patch doesn't include:
- markdown support (the client I use doesn't support it yet)
- range support (optional in the Hover response)
- comments associated to variables/functions/classes
They are kept as future work to keep this patch simpler.
I added tests in XRefsTests.cpp. hover.test contains one simple
smoketest to make sure the feature works from a black box perspective.
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Subscribers: sammccall, mgrang, klimek, rwols, ilya-biryukov, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D35894
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Signed-off-by: William Enright <william.enright@polymtl.ca>
llvm-svn: 325395
2018-02-17 05:38:15 +08:00
|
|
|
if (!InpAST)
|
2018-03-13 07:22:35 +08:00
|
|
|
return CB(InpAST.takeError());
|
|
|
|
CB(clangd::getHover(InpAST->AST, Pos));
|
[clangd] Implement textDocument/hover
Summary: Implemention of textDocument/hover as described in LSP definition.
This patch adds a basic Hover implementation. When hovering a variable,
function, method or namespace, clangd will return a text containing the
declaration's scope, as well as the declaration of the hovered entity.
For example, for a variable:
Declared in class Foo::Bar
int hello = 2
For macros, the macro definition is returned.
This patch doesn't include:
- markdown support (the client I use doesn't support it yet)
- range support (optional in the Hover response)
- comments associated to variables/functions/classes
They are kept as future work to keep this patch simpler.
I added tests in XRefsTests.cpp. hover.test contains one simple
smoketest to make sure the feature works from a black box perspective.
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Subscribers: sammccall, mgrang, klimek, rwols, ilya-biryukov, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D35894
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Signed-off-by: William Enright <william.enright@polymtl.ca>
llvm-svn: 325395
2018-02-17 05:38:15 +08:00
|
|
|
};
|
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
WorkScheduler.runWithAST("Hover", File, Bind(Action, std::move(CB)));
|
[clangd] Document highlights for clangd
Summary: Implementation of Document Highlights Request as described in
LSP.
Contributed by William Enright (nebiroth).
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Reviewed By: malaperle
Subscribers: mgrang, sammccall, klimek, ioeric, rwols, cfe-commits, arphaman, ilya-biryukov
Differential Revision: https://reviews.llvm.org/D38425
llvm-svn: 320474
2017-12-12 20:27:47 +08:00
|
|
|
}
|
|
|
|
|
2018-02-13 16:59:23 +08:00
|
|
|
void ClangdServer::scheduleReparseAndDiags(
|
2018-02-22 21:11:12 +08:00
|
|
|
PathRef File, VersionedDraft Contents, WantDiagnostics WantDiags,
|
2018-03-13 07:22:35 +08:00
|
|
|
IntrusiveRefCntPtr<vfs::FileSystem> FS) {
|
2018-01-31 16:51:16 +08:00
|
|
|
tooling::CompileCommand Command = CompileArgs.getCompileCommand(File);
|
|
|
|
|
|
|
|
DocVersion Version = Contents.Version;
|
|
|
|
Path FileStr = File.str();
|
2018-01-25 22:19:21 +08:00
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
auto Callback = [this, Version, FileStr](std::vector<Diag> Diags) {
|
2017-09-20 20:58:55 +08:00
|
|
|
// We need to serialize access to resulting diagnostics to avoid calling
|
|
|
|
// `onDiagnosticsReady` in the wrong order.
|
|
|
|
std::lock_guard<std::mutex> DiagsLock(DiagnosticsMutex);
|
|
|
|
DocVersion &LastReportedDiagsVersion = ReportedDiagnosticVersions[FileStr];
|
|
|
|
// FIXME(ibiryukov): get rid of '<' comparison here. In the current
|
|
|
|
// implementation diagnostics will not be reported after version counters'
|
|
|
|
// overflow. This should not happen in practice, since DocVersion is a
|
|
|
|
// 64-bit unsigned integer.
|
|
|
|
if (Version < LastReportedDiagsVersion)
|
|
|
|
return;
|
|
|
|
LastReportedDiagsVersion = Version;
|
|
|
|
|
2018-03-13 07:22:35 +08:00
|
|
|
DiagConsumer.onDiagnosticsReady(FileStr, std::move(Diags));
|
2017-08-14 16:17:24 +08:00
|
|
|
};
|
|
|
|
|
[clangd] Pass Context implicitly using TLS.
Summary:
Instead of passing Context explicitly around, we now have a thread-local
Context object `Context::current()` which is an implicit argument to
every function.
Most manipulation of this should use the WithContextValue helper, which
augments the current Context to add a single KV pair, and restores the
old context on destruction.
Advantages are:
- less boilerplate in functions that just propagate contexts
- reading most code doesn't require understanding context at all, and
using context as values in fewer places still
- fewer options to pass the "wrong" context when it changes within a
scope (e.g. when using Span)
- contexts pass through interfaces we can't modify, such as VFS
- propagating contexts across threads was slightly tricky (e.g.
copy vs move, no move-init in lambdas), and is now encapsulated in
the threadpool
Disadvantages are all the usual TLS stuff - hidden magic, and
potential for higher memory usage on threads that don't use the
context. (In practice, it's just one pointer)
Reviewers: ilya-biryukov
Subscribers: klimek, jkorous-apple, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D42517
llvm-svn: 323872
2018-01-31 21:40:48 +08:00
|
|
|
WorkScheduler.update(File,
|
2018-03-13 07:22:35 +08:00
|
|
|
ParseInputs{std::move(Command), std::move(FS),
|
2018-01-31 16:51:16 +08:00
|
|
|
std::move(*Contents.Draft)},
|
2018-02-22 21:11:12 +08:00
|
|
|
WantDiags, std::move(Callback));
|
2017-08-14 16:17:24 +08:00
|
|
|
}
|
2017-10-03 02:00:37 +08:00
|
|
|
|
[clangd] DidChangeConfiguration Notification
Summary:
Implementation of DidChangeConfiguration notification handling in
clangd. This currently only supports changing one setting: the path of
the compilation database to be used for the current project. In other
words, it is no longer necessary to restart clangd with a different
command line argument in order to change the compilation database.
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Subscribers: jkorous-apple, ioeric, simark, klimek, ilya-biryukov, arphaman, rwols, cfe-commits
Differential Revision: https://reviews.llvm.org/D39571
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Signed-off-by: William Enright <william.enright@polymtl.ca>
llvm-svn: 325784
2018-02-22 22:00:39 +08:00
|
|
|
void ClangdServer::reparseOpenedFiles() {
|
|
|
|
for (const Path &FilePath : DraftMgr.getActiveFiles())
|
|
|
|
forceReparse(FilePath);
|
|
|
|
}
|
|
|
|
|
2017-10-03 02:00:37 +08:00
|
|
|
void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams &Params) {
|
|
|
|
// FIXME: Do nothing for now. This will be used for indexing and potentially
|
|
|
|
// invalidating other caches.
|
|
|
|
}
|
2018-01-25 22:32:21 +08:00
|
|
|
|
|
|
|
std::vector<std::pair<Path, std::size_t>>
|
|
|
|
ClangdServer::getUsedBytesPerFile() const {
|
2018-01-31 16:51:16 +08:00
|
|
|
return WorkScheduler.getUsedBytesPerFile();
|
2018-01-25 22:32:21 +08:00
|
|
|
}
|
2018-02-13 16:59:23 +08:00
|
|
|
|
|
|
|
LLVM_NODISCARD bool
|
|
|
|
ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) {
|
|
|
|
return WorkScheduler.blockUntilIdle(timeoutSeconds(TimeoutSeconds));
|
|
|
|
}
|