2017-04-13 01:13:08 +08:00
|
|
|
//===--- ClangdMain.cpp - clangd server loop ------------------------------===//
|
2017-02-07 18:28:20 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-05-16 17:38:59 +08:00
|
|
|
#include "ClangdLSPServer.h"
|
2017-05-16 22:40:30 +08:00
|
|
|
#include "JSONRPCDispatcher.h"
|
2017-10-10 17:08:47 +08:00
|
|
|
#include "Path.h"
|
2017-11-02 17:21:51 +08:00
|
|
|
#include "Trace.h"
|
2018-01-10 22:44:34 +08:00
|
|
|
#include "index/SymbolYAML.h"
|
2017-03-02 00:16:29 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2017-02-07 18:28:20 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2017-10-02 23:13:20 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2017-02-07 20:40:59 +08:00
|
|
|
#include "llvm/Support/Program.h"
|
2018-02-16 22:15:55 +08:00
|
|
|
#include "llvm/Support/Signals.h"
|
2017-10-10 17:08:47 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2018-02-14 11:20:07 +08:00
|
|
|
#include <cstdlib>
|
2017-02-07 18:28:20 +08:00
|
|
|
#include <iostream>
|
2017-05-16 17:38:59 +08:00
|
|
|
#include <memory>
|
2017-02-07 18:28:20 +08:00
|
|
|
#include <string>
|
2017-08-14 16:45:47 +08:00
|
|
|
#include <thread>
|
2017-05-16 17:38:59 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
2017-02-07 18:28:20 +08:00
|
|
|
using namespace clang::clangd;
|
|
|
|
|
2017-11-17 00:25:18 +08:00
|
|
|
namespace {
|
|
|
|
enum class PCHStorageFlag { Disk, Memory };
|
2018-01-10 22:44:34 +08:00
|
|
|
|
|
|
|
// Build an in-memory static index for global symbols from a YAML-format file.
|
|
|
|
// The size of global symbols should be relatively small, so that all symbols
|
|
|
|
// can be managed in memory.
|
2018-05-29 19:50:51 +08:00
|
|
|
std::unique_ptr<SymbolIndex> buildStaticIndex(llvm::StringRef YamlSymbolFile) {
|
2018-01-10 22:44:34 +08:00
|
|
|
auto Buffer = llvm::MemoryBuffer::getFile(YamlSymbolFile);
|
|
|
|
if (!Buffer) {
|
|
|
|
llvm::errs() << "Can't open " << YamlSymbolFile << "\n";
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-02-09 22:42:01 +08:00
|
|
|
auto Slab = SymbolsFromYAML(Buffer.get()->getBuffer());
|
2018-01-10 22:44:34 +08:00
|
|
|
SymbolSlab::Builder SymsBuilder;
|
|
|
|
for (auto Sym : Slab)
|
|
|
|
SymsBuilder.insert(Sym);
|
|
|
|
|
|
|
|
return MemIndex::build(std::move(SymsBuilder).build());
|
2017-11-17 00:25:18 +08:00
|
|
|
}
|
2018-01-10 22:44:34 +08:00
|
|
|
} // namespace
|
2017-11-17 00:25:18 +08:00
|
|
|
|
2017-10-02 23:13:20 +08:00
|
|
|
static llvm::cl::opt<Path> CompileCommandsDir(
|
|
|
|
"compile-commands-dir",
|
|
|
|
llvm::cl::desc("Specify a path to look for compile_commands.json. If path "
|
|
|
|
"is invalid, clangd will look in the current directory and "
|
|
|
|
"parent paths of each source file."));
|
|
|
|
|
2017-08-14 16:45:47 +08:00
|
|
|
static llvm::cl::opt<unsigned>
|
|
|
|
WorkerThreadsCount("j",
|
|
|
|
llvm::cl::desc("Number of async workers used by clangd"),
|
|
|
|
llvm::cl::init(getDefaultAsyncThreadsCount()));
|
|
|
|
|
[clangd] Add option to fold overloads into a single completion item.
Summary:
Adds a CodeCompleteOption to folds together compatible function/method overloads
into a single item. This feels pretty good (for editors with signatureHelp
support), but has limitations.
This happens in the code completion merge step, so there may be inconsistencies
(e.g. if only one overload made it into the index result list, no folding).
We don't want to bundle together completions that have different side-effects
(include insertion), because we can't constructo a coherent CompletionItem.
This may be confusing for users, as the reason for non-bundling may not
be immediately obvious. (Also, the implementation seems a little fragile)
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47957
llvm-svn: 334822
2018-06-15 19:06:29 +08:00
|
|
|
// FIXME: also support "plain" style where signatures are always omitted.
|
|
|
|
enum CompletionStyleFlag {
|
|
|
|
Detailed,
|
|
|
|
Bundled,
|
|
|
|
};
|
|
|
|
static llvm::cl::opt<CompletionStyleFlag> CompletionStyle(
|
|
|
|
"completion-style",
|
|
|
|
llvm::cl::desc("Granularity of code completion suggestions"),
|
|
|
|
llvm::cl::values(
|
|
|
|
clEnumValN(Detailed, "detailed",
|
|
|
|
"One completion item for each semantically distinct "
|
|
|
|
"completion, with full type information."),
|
|
|
|
clEnumValN(Bundled, "bundled",
|
|
|
|
"Similar completion items (e.g. function overloads) are "
|
|
|
|
"combined. Type information shown where possible.")),
|
|
|
|
llvm::cl::init(Detailed));
|
|
|
|
|
2017-11-24 00:58:22 +08:00
|
|
|
// FIXME: Flags are the wrong mechanism for user preferences.
|
|
|
|
// We should probably read a dotfile or similar.
|
|
|
|
static llvm::cl::opt<bool> IncludeIneligibleResults(
|
|
|
|
"include-ineligible-results",
|
|
|
|
llvm::cl::desc(
|
|
|
|
"Include ineligible completion results (e.g. private members)"),
|
|
|
|
llvm::cl::init(clangd::CodeCompleteOptions().IncludeIneligibleResults),
|
|
|
|
llvm::cl::Hidden);
|
2017-09-12 21:57:14 +08:00
|
|
|
|
2018-02-06 18:47:30 +08:00
|
|
|
static llvm::cl::opt<JSONStreamStyle> InputStyle(
|
|
|
|
"input-style", llvm::cl::desc("Input JSON stream encoding"),
|
|
|
|
llvm::cl::values(
|
|
|
|
clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP protocol"),
|
|
|
|
clEnumValN(JSONStreamStyle::Delimited, "delimited",
|
|
|
|
"messages delimited by --- lines, with # comment support")),
|
|
|
|
llvm::cl::init(JSONStreamStyle::Standard));
|
|
|
|
|
Adds a json::Expr type to represent intermediate JSON expressions.
Summary:
This form can be created with a nice clang-format-friendly literal syntax,
and gets escaping right. It knows how to call unparse() on our Protocol types.
All the places where we pass around JSON internally now use this type.
Object properties are sorted (stored as std::map) and so serialization is
canonicalized, with optional prettyprinting (triggered by a -pretty flag).
This makes the lit tests much nicer to read and somewhat nicer to debug.
(Unfortunately the completion tests use CHECK-DAG, which only has
line-granularity, so pretty-printing is disabled there. In future we
could make completion ordering deterministic, or switch to unittests).
Compared to the current approach, it has some efficiencies like avoiding copies
of string literals used as object keys, but is probably slower overall.
I think the code/test quality benefits are worth it.
This patch doesn't attempt to do anything about JSON *parsing*.
It takes direction from the proposal in this doc[1], but is limited in scope
and visibility, for now.
I am of half a mind just to use Expr as the target of a parser, and maybe do a
little string deduplication, but not bother with clever memory allocation.
That would be simple, and fast enough for clangd...
[1] https://docs.google.com/document/d/1OEF9IauWwNuSigZzvvbjc1cVS1uGHRyGTXaoy3DjqM4/edit
+cc d0k so he can tell me not to use std::map.
Reviewers: ioeric, malaperle
Subscribers: bkramer, ilya-biryukov, mgorny, klimek
Differential Revision: https://reviews.llvm.org/D39435
llvm-svn: 317486
2017-11-06 23:40:30 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
PrettyPrint("pretty", llvm::cl::desc("Pretty-print JSON output"),
|
|
|
|
llvm::cl::init(false));
|
|
|
|
|
2018-02-06 18:47:30 +08:00
|
|
|
static llvm::cl::opt<bool> Test(
|
|
|
|
"lit-test",
|
|
|
|
llvm::cl::desc(
|
|
|
|
"Abbreviation for -input-style=delimited -pretty -run-synchronously. "
|
|
|
|
"Intended to simplify lit tests."),
|
|
|
|
llvm::cl::init(false), llvm::cl::Hidden);
|
|
|
|
|
2017-11-17 00:25:18 +08:00
|
|
|
static llvm::cl::opt<PCHStorageFlag> PCHStorage(
|
|
|
|
"pch-storage",
|
|
|
|
llvm::cl::desc("Storing PCHs in memory increases memory usages, but may "
|
|
|
|
"improve performance"),
|
|
|
|
llvm::cl::values(
|
|
|
|
clEnumValN(PCHStorageFlag::Disk, "disk", "store PCHs on disk"),
|
|
|
|
clEnumValN(PCHStorageFlag::Memory, "memory", "store PCHs in memory")),
|
|
|
|
llvm::cl::init(PCHStorageFlag::Disk));
|
|
|
|
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
static llvm::cl::opt<int> LimitResults(
|
|
|
|
"limit-results",
|
|
|
|
llvm::cl::desc("Limit the number of results returned by clangd. "
|
2018-01-25 17:20:09 +08:00
|
|
|
"0 means no limit."),
|
2018-01-30 17:21:30 +08:00
|
|
|
llvm::cl::init(100));
|
2018-01-25 17:20:09 +08:00
|
|
|
|
2017-08-14 16:45:47 +08:00
|
|
|
static llvm::cl::opt<bool> RunSynchronously(
|
|
|
|
"run-synchronously",
|
|
|
|
llvm::cl::desc("Parse on main thread. If set, -j is ignored"),
|
|
|
|
llvm::cl::init(false), llvm::cl::Hidden);
|
2017-03-02 00:16:29 +08:00
|
|
|
|
2017-10-10 17:08:47 +08:00
|
|
|
static llvm::cl::opt<Path>
|
2017-07-19 23:43:35 +08:00
|
|
|
ResourceDir("resource-dir",
|
2017-08-02 16:53:48 +08:00
|
|
|
llvm::cl::desc("Directory for system clang headers"),
|
2017-07-19 23:43:35 +08:00
|
|
|
llvm::cl::init(""), llvm::cl::Hidden);
|
|
|
|
|
2017-10-10 17:08:47 +08:00
|
|
|
static llvm::cl::opt<Path> InputMirrorFile(
|
|
|
|
"input-mirror-file",
|
|
|
|
llvm::cl::desc(
|
|
|
|
"Mirror all LSP input to the specified file. Useful for debugging."),
|
|
|
|
llvm::cl::init(""), llvm::cl::Hidden);
|
|
|
|
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
static llvm::cl::opt<bool> EnableIndex(
|
|
|
|
"index",
|
|
|
|
llvm::cl::desc("Enable index-based features such as global code completion "
|
|
|
|
"and searching for symbols."
|
|
|
|
"Clang uses an index built from symbols in opened files"),
|
2018-01-30 17:21:30 +08:00
|
|
|
llvm::cl::init(true));
|
2017-12-20 02:00:37 +08:00
|
|
|
|
2018-01-10 22:44:34 +08:00
|
|
|
static llvm::cl::opt<Path> YamlSymbolFile(
|
|
|
|
"yaml-symbol-file",
|
|
|
|
llvm::cl::desc(
|
|
|
|
"YAML-format global symbol file to build the static index. Clangd will "
|
|
|
|
"use the static index for global code completion.\n"
|
|
|
|
"WARNING: This option is experimental only, and will be removed "
|
|
|
|
"eventually. Don't rely on it."),
|
|
|
|
llvm::cl::init(""), llvm::cl::Hidden);
|
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
int main(int argc, char *argv[]) {
|
2018-02-20 19:46:39 +08:00
|
|
|
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
|
2017-03-02 00:16:29 +08:00
|
|
|
llvm::cl::ParseCommandLineOptions(argc, argv, "clangd");
|
2018-02-06 18:47:30 +08:00
|
|
|
if (Test) {
|
|
|
|
RunSynchronously = true;
|
|
|
|
InputStyle = JSONStreamStyle::Delimited;
|
|
|
|
PrettyPrint = true;
|
|
|
|
}
|
2017-05-16 22:40:30 +08:00
|
|
|
|
2017-08-14 16:45:47 +08:00
|
|
|
if (!RunSynchronously && WorkerThreadsCount == 0) {
|
|
|
|
llvm::errs() << "A number of worker threads cannot be 0. Did you mean to "
|
|
|
|
"specify -run-synchronously?";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-02-25 15:21:16 +08:00
|
|
|
if (RunSynchronously) {
|
|
|
|
if (WorkerThreadsCount.getNumOccurrences())
|
|
|
|
llvm::errs() << "Ignoring -j because -run-synchronously is set.\n";
|
2017-08-14 16:45:47 +08:00
|
|
|
WorkerThreadsCount = 0;
|
2018-02-25 15:21:16 +08:00
|
|
|
}
|
2017-08-14 16:45:47 +08:00
|
|
|
|
2017-10-26 18:07:04 +08:00
|
|
|
// Validate command line arguments.
|
2017-10-10 17:08:47 +08:00
|
|
|
llvm::Optional<llvm::raw_fd_ostream> InputMirrorStream;
|
|
|
|
if (!InputMirrorFile.empty()) {
|
|
|
|
std::error_code EC;
|
2018-06-08 03:58:58 +08:00
|
|
|
InputMirrorStream.emplace(InputMirrorFile, /*ref*/ EC,
|
|
|
|
llvm::sys::fs::FA_Read | llvm::sys::fs::FA_Write);
|
2017-10-10 17:08:47 +08:00
|
|
|
if (EC) {
|
|
|
|
InputMirrorStream.reset();
|
|
|
|
llvm::errs() << "Error while opening an input mirror file: "
|
|
|
|
<< EC.message();
|
|
|
|
}
|
|
|
|
}
|
2017-12-14 23:04:59 +08:00
|
|
|
|
2018-02-14 11:20:07 +08:00
|
|
|
// Setup tracing facilities if CLANGD_TRACE is set. In practice enabling a
|
|
|
|
// trace flag in your editor's config is annoying, launching with
|
|
|
|
// `CLANGD_TRACE=trace.json vim` is easier.
|
2017-11-02 17:21:51 +08:00
|
|
|
llvm::Optional<llvm::raw_fd_ostream> TraceStream;
|
2017-12-14 23:04:59 +08:00
|
|
|
std::unique_ptr<trace::EventTracer> Tracer;
|
2018-02-14 11:20:07 +08:00
|
|
|
if (auto *TraceFile = getenv("CLANGD_TRACE")) {
|
2017-11-02 17:21:51 +08:00
|
|
|
std::error_code EC;
|
2018-06-08 03:58:58 +08:00
|
|
|
TraceStream.emplace(TraceFile, /*ref*/ EC,
|
|
|
|
llvm::sys::fs::FA_Read | llvm::sys::fs::FA_Write);
|
2017-11-02 17:21:51 +08:00
|
|
|
if (EC) {
|
2018-02-14 11:20:07 +08:00
|
|
|
TraceStream.reset();
|
|
|
|
llvm::errs() << "Error while opening trace file " << TraceFile << ": "
|
|
|
|
<< EC.message();
|
2017-11-02 17:21:51 +08:00
|
|
|
} else {
|
2017-12-14 23:04:59 +08:00
|
|
|
Tracer = trace::createJSONTracer(*TraceStream, PrettyPrint);
|
2017-11-02 17:21:51 +08:00
|
|
|
}
|
|
|
|
}
|
2017-10-10 17:08:47 +08:00
|
|
|
|
2017-12-14 23:04:59 +08:00
|
|
|
llvm::Optional<trace::Session> TracingSession;
|
|
|
|
if (Tracer)
|
|
|
|
TracingSession.emplace(*Tracer);
|
|
|
|
|
2018-03-06 01:28:54 +08:00
|
|
|
JSONOutput Out(llvm::outs(), llvm::errs(),
|
Adds a json::Expr type to represent intermediate JSON expressions.
Summary:
This form can be created with a nice clang-format-friendly literal syntax,
and gets escaping right. It knows how to call unparse() on our Protocol types.
All the places where we pass around JSON internally now use this type.
Object properties are sorted (stored as std::map) and so serialization is
canonicalized, with optional prettyprinting (triggered by a -pretty flag).
This makes the lit tests much nicer to read and somewhat nicer to debug.
(Unfortunately the completion tests use CHECK-DAG, which only has
line-granularity, so pretty-printing is disabled there. In future we
could make completion ordering deterministic, or switch to unittests).
Compared to the current approach, it has some efficiencies like avoiding copies
of string literals used as object keys, but is probably slower overall.
I think the code/test quality benefits are worth it.
This patch doesn't attempt to do anything about JSON *parsing*.
It takes direction from the proposal in this doc[1], but is limited in scope
and visibility, for now.
I am of half a mind just to use Expr as the target of a parser, and maybe do a
little string deduplication, but not bother with clever memory allocation.
That would be simple, and fast enough for clangd...
[1] https://docs.google.com/document/d/1OEF9IauWwNuSigZzvvbjc1cVS1uGHRyGTXaoy3DjqM4/edit
+cc d0k so he can tell me not to use std::map.
Reviewers: ioeric, malaperle
Subscribers: bkramer, ilya-biryukov, mgorny, klimek
Differential Revision: https://reviews.llvm.org/D39435
llvm-svn: 317486
2017-11-06 23:40:30 +08:00
|
|
|
InputMirrorStream ? InputMirrorStream.getPointer() : nullptr,
|
|
|
|
PrettyPrint);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
2017-12-13 20:51:22 +08:00
|
|
|
clangd::LoggingSession LoggingSession(Out);
|
|
|
|
|
2017-10-02 23:13:20 +08:00
|
|
|
// If --compile-commands-dir arg was invoked, check value and override default
|
|
|
|
// path.
|
|
|
|
llvm::Optional<Path> CompileCommandsDirPath;
|
|
|
|
if (CompileCommandsDir.empty()) {
|
|
|
|
CompileCommandsDirPath = llvm::None;
|
|
|
|
} else if (!llvm::sys::path::is_absolute(CompileCommandsDir) ||
|
|
|
|
!llvm::sys::fs::exists(CompileCommandsDir)) {
|
|
|
|
llvm::errs() << "Path specified by --compile-commands-dir either does not "
|
|
|
|
"exist or is not an absolute "
|
|
|
|
"path. The argument will be ignored.\n";
|
|
|
|
CompileCommandsDirPath = llvm::None;
|
|
|
|
} else {
|
|
|
|
CompileCommandsDirPath = CompileCommandsDir;
|
|
|
|
}
|
2017-02-07 20:40:59 +08:00
|
|
|
|
2018-03-06 01:28:54 +08:00
|
|
|
ClangdServer::Options Opts;
|
2017-11-17 00:25:18 +08:00
|
|
|
switch (PCHStorage) {
|
|
|
|
case PCHStorageFlag::Memory:
|
2018-03-06 01:28:54 +08:00
|
|
|
Opts.StorePreamblesInMemory = true;
|
2017-11-17 00:25:18 +08:00
|
|
|
break;
|
|
|
|
case PCHStorageFlag::Disk:
|
2018-03-06 01:28:54 +08:00
|
|
|
Opts.StorePreamblesInMemory = false;
|
2017-11-17 00:25:18 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-07-19 23:43:35 +08:00
|
|
|
if (!ResourceDir.empty())
|
2018-03-06 01:28:54 +08:00
|
|
|
Opts.ResourceDir = ResourceDir;
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
Opts.BuildDynamicSymbolIndex = EnableIndex;
|
2018-01-10 22:44:34 +08:00
|
|
|
std::unique_ptr<SymbolIndex> StaticIdx;
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
if (EnableIndex && !YamlSymbolFile.empty()) {
|
2018-05-29 19:50:51 +08:00
|
|
|
StaticIdx = buildStaticIndex(YamlSymbolFile);
|
2018-03-06 01:28:54 +08:00
|
|
|
Opts.StaticIndex = StaticIdx.get();
|
|
|
|
}
|
|
|
|
Opts.AsyncThreadsCount = WorkerThreadsCount;
|
|
|
|
|
2017-11-24 00:58:22 +08:00
|
|
|
clangd::CodeCompleteOptions CCOpts;
|
|
|
|
CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
CCOpts.Limit = LimitResults;
|
[clangd] Add option to fold overloads into a single completion item.
Summary:
Adds a CodeCompleteOption to folds together compatible function/method overloads
into a single item. This feels pretty good (for editors with signatureHelp
support), but has limitations.
This happens in the code completion merge step, so there may be inconsistencies
(e.g. if only one overload made it into the index result list, no folding).
We don't want to bundle together completions that have different side-effects
(include insertion), because we can't constructo a coherent CompletionItem.
This may be confusing for users, as the reason for non-bundling may not
be immediately obvious. (Also, the implementation seems a little fragile)
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47957
llvm-svn: 334822
2018-06-15 19:06:29 +08:00
|
|
|
CCOpts.BundleOverloads = CompletionStyle != Detailed;
|
2018-03-06 01:28:54 +08:00
|
|
|
|
2017-10-26 18:07:04 +08:00
|
|
|
// Initialize and run ClangdLSPServer.
|
2018-03-06 01:28:54 +08:00
|
|
|
ClangdLSPServer LSPServer(Out, CCOpts, CompileCommandsDirPath, Opts);
|
2017-10-25 16:45:41 +08:00
|
|
|
constexpr int NoShutdownRequestErrorCode = 1;
|
2017-11-02 17:21:51 +08:00
|
|
|
llvm::set_thread_name("clangd.main");
|
2018-03-06 01:28:54 +08:00
|
|
|
// Change stdin to binary to not lose \r\n on windows.
|
|
|
|
llvm::sys::ChangeStdinToBinary();
|
2018-06-05 17:34:46 +08:00
|
|
|
return LSPServer.run(stdin, InputStyle) ? 0 : NoShutdownRequestErrorCode;
|
2017-02-07 18:28:20 +08:00
|
|
|
}
|