2017-04-13 01:13:08 +08:00
|
|
|
//===--- ClangdMain.cpp - clangd server loop ------------------------------===//
|
2017-02-07 18:28:20 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-02-07 18:28:20 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-05-16 17:38:59 +08:00
|
|
|
#include "ClangdLSPServer.h"
|
2019-04-10 20:15:35 +08:00
|
|
|
#include "CodeComplete.h"
|
|
|
|
#include "Features.inc"
|
2017-10-10 17:08:47 +08:00
|
|
|
#include "Path.h"
|
2019-03-28 01:47:49 +08:00
|
|
|
#include "Protocol.h"
|
2017-11-02 17:21:51 +08:00
|
|
|
#include "Trace.h"
|
[clangd] Lay JSONRPCDispatcher to rest.
Summary:
Most of its functionality is moved into ClangdLSPServer.
The decoupling between JSONRPCDispatcher, ProtocolCallbacks, ClangdLSPServer
was never real, and only served to obfuscate.
Some previous implicit/magic stuff is now explicit:
- the return type of LSP method calls are now in the signature
- no more reply() that gets the ID using global context magic
- arg tracing no longer relies on RequestArgs::stash context magic either
This is mostly refactoring, but some deliberate fixes while here:
- LSP method params are now by const reference
- notifications and calls are now distinct namespaces.
(some tests had protocol errors and needed updating)
- we now reply to calls we failed to decode
- outgoing calls use distinct IDs
A few error codes and message IDs changed in unimportant ways (see tests).
Reviewers: ioeric
Subscribers: mgorny, ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, jfb, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D53387
llvm-svn: 344737
2018-10-18 20:32:04 +08:00
|
|
|
#include "Transport.h"
|
2019-04-18 21:46:40 +08:00
|
|
|
#include "index/Background.h"
|
[clangd] Merge binary + YAML serialization behind a (mostly) common interface.
Summary:
Interface is in one file, implementation in two as they have little in common.
A couple of ad-hoc YAML functions left exposed:
- symbol -> YAML I expect to keep for tools like dexp
- YAML -> symbol is used for the MR-style indexer, I think we can eliminate
this (merge-on-the-fly, else use a different serialization)
Reviewers: kbobyrev
Subscribers: mgorny, ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D52453
llvm-svn: 342999
2018-09-26 02:06:43 +08:00
|
|
|
#include "index/Serialization.h"
|
2018-07-30 03:12:42 +08:00
|
|
|
#include "clang/Basic/Version.h"
|
2019-05-06 16:11:59 +08:00
|
|
|
#include "clang/Format/Format.h"
|
2019-03-28 01:47:49 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2019-05-21 01:30:46 +08:00
|
|
|
#include "llvm/ADT/StringRef.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"
|
2019-06-26 15:39:14 +08:00
|
|
|
#include "llvm/Support/TargetSelect.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>
|
2019-05-21 01:30:46 +08:00
|
|
|
#include <mutex>
|
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
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
2018-08-21 18:40:19 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<Path> CompileCommandsDir(
|
2017-10-02 23:13:20 +08:00
|
|
|
"compile-commands-dir",
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::desc("Specify a path to look for compile_commands.json. If path "
|
|
|
|
"is invalid, clangd will look in the current directory and "
|
2019-05-28 17:31:27 +08:00
|
|
|
"parent paths of each source file"));
|
2017-10-02 23:13:20 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<unsigned>
|
|
|
|
WorkerThreadsCount("j",
|
|
|
|
llvm::cl::desc("Number of async workers used by clangd"),
|
|
|
|
llvm::cl::init(getDefaultAsyncThreadsCount()));
|
2017-08-14 16:45:47 +08:00
|
|
|
|
[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.
|
2018-09-05 18:39:58 +08:00
|
|
|
enum CompletionStyleFlag { Detailed, Bundled };
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<CompletionStyleFlag> CompletionStyle(
|
|
|
|
"completion-style",
|
|
|
|
llvm::cl::desc("Granularity of code completion suggestions"),
|
|
|
|
llvm::cl::values(
|
[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
|
|
|
clEnumValN(Detailed, "detailed",
|
|
|
|
"One completion item for each semantically distinct "
|
2019-05-28 17:31:27 +08:00
|
|
|
"completion, with full type information"),
|
[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
|
|
|
clEnumValN(Bundled, "bundled",
|
|
|
|
"Similar completion items (e.g. function overloads) are "
|
2019-07-09 01:27:15 +08:00
|
|
|
"combined. Type information shown where possible")));
|
[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
|
|
|
|
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.
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<bool> IncludeIneligibleResults(
|
2017-11-24 00:58:22 +08:00
|
|
|
"include-ineligible-results",
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::desc(
|
|
|
|
"Include ineligible completion results (e.g. private members)"),
|
|
|
|
llvm::cl::init(CodeCompleteOptions().IncludeIneligibleResults),
|
|
|
|
llvm::cl::Hidden);
|
|
|
|
|
|
|
|
static llvm::cl::opt<JSONStreamStyle> InputStyle(
|
|
|
|
"input-style", llvm::cl::desc("Input JSON stream encoding"),
|
|
|
|
llvm::cl::values(
|
2018-02-06 18:47:30 +08:00
|
|
|
clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP protocol"),
|
|
|
|
clEnumValN(JSONStreamStyle::Delimited, "delimited",
|
|
|
|
"messages delimited by --- lines, with # comment support")),
|
2019-07-05 02:49:08 +08:00
|
|
|
llvm::cl::init(JSONStreamStyle::Standard), llvm::cl::Hidden);
|
2018-02-06 18:47:30 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
PrettyPrint("pretty", llvm::cl::desc("Pretty-print JSON output"),
|
|
|
|
llvm::cl::init(false));
|
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
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<Logger::Level> LogLevel(
|
|
|
|
"log", llvm::cl::desc("Verbosity of log messages written to stderr"),
|
|
|
|
llvm::cl::values(clEnumValN(Logger::Error, "error", "Error messages only"),
|
|
|
|
clEnumValN(Logger::Info, "info",
|
|
|
|
"High level execution tracing"),
|
|
|
|
clEnumValN(Logger::Debug, "verbose", "Low level details")),
|
|
|
|
llvm::cl::init(Logger::Info));
|
[clangd] Upgrade logging facilities with levels and formatv.
Summary:
log() is split into four functions:
- elog()/log()/vlog() have different severity levels, allowing filtering
- dlog() is a lazy macro which uses LLVM_DEBUG - it logs to the logger, but
conditionally based on -debug-only flag and is omitted in release builds
All logging functions use formatv-style format strings now, e.g:
log("Could not resolve URI {0}: {1}", URI, Result.takeError());
Existing log sites have been split between elog/log/vlog by best guess.
This includes a workaround for passing Error to formatv that can be
simplified when D49170 or similar lands.
Subscribers: ilya-biryukov, javed.absar, ioeric, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D49008
llvm-svn: 336785
2018-07-11 18:35:11 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<bool>
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
Test("lit-test",
|
2019-05-28 17:20:57 +08:00
|
|
|
llvm::cl::desc("Abbreviation for -input-style=delimited -pretty -sync "
|
|
|
|
"-enable-test-scheme -log=verbose."
|
2019-05-28 17:31:27 +08:00
|
|
|
"Intended to simplify lit tests"),
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::init(false), llvm::cl::Hidden);
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<bool> EnableTestScheme(
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
"enable-test-uri-scheme",
|
2019-05-28 17:31:27 +08:00
|
|
|
llvm::cl::desc("Enable 'test:' URI scheme. Only use in lit tests"),
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::init(false), llvm::cl::Hidden);
|
2018-02-06 18:47:30 +08:00
|
|
|
|
2018-09-05 18:39:58 +08:00
|
|
|
enum PCHStorageFlag { Disk, Memory };
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<PCHStorageFlag> PCHStorage(
|
2017-11-17 00:25:18 +08:00
|
|
|
"pch-storage",
|
2019-01-07 23:45:19 +08:00
|
|
|
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));
|
|
|
|
|
|
|
|
static llvm::cl::opt<int> LimitResults(
|
|
|
|
"limit-results",
|
|
|
|
llvm::cl::desc("Limit the number of results returned by clangd. "
|
2019-05-28 17:31:27 +08:00
|
|
|
"0 means no limit (default=100)"),
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::init(100));
|
|
|
|
|
2019-05-28 17:20:57 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
Sync("sync", llvm::cl::desc("Parse on main thread. If set, -j is ignored"),
|
|
|
|
llvm::cl::init(false), llvm::cl::Hidden);
|
2019-01-07 23:45:19 +08:00
|
|
|
|
|
|
|
static llvm::cl::opt<Path>
|
|
|
|
ResourceDir("resource-dir",
|
|
|
|
llvm::cl::desc("Directory for system clang headers"),
|
|
|
|
llvm::cl::init(""), llvm::cl::Hidden);
|
|
|
|
|
|
|
|
static llvm::cl::opt<Path> InputMirrorFile(
|
2017-10-10 17:08:47 +08:00
|
|
|
"input-mirror-file",
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::desc(
|
2019-05-28 17:31:27 +08:00
|
|
|
"Mirror all LSP input to the specified file. Useful for debugging"),
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::init(""), llvm::cl::Hidden);
|
2017-10-10 17:08:47 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<bool> EnableIndex(
|
[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
|
|
|
"index",
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::desc(
|
2018-09-13 20:53:23 +08:00
|
|
|
"Enable index-based features. By default, clangd maintains an index "
|
|
|
|
"built from symbols in opened files. Global index support needs to "
|
2019-05-28 17:31:27 +08:00
|
|
|
"enabled separatedly"),
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::init(true), llvm::cl::Hidden);
|
2017-12-20 02:00:37 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<bool> AllScopesCompletion(
|
2018-09-28 02:46:00 +08:00
|
|
|
"all-scopes-completion",
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::desc(
|
2018-09-28 02:46:00 +08:00
|
|
|
"If set to true, code completion will include index symbols that are "
|
|
|
|
"not defined in the scopes (e.g. "
|
|
|
|
"namespaces) visible from the code completion point. Such completions "
|
2019-05-28 17:31:27 +08:00
|
|
|
"can insert scope qualifiers"),
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::init(true));
|
2018-09-28 02:46:00 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<bool> ShowOrigins(
|
|
|
|
"debug-origin", llvm::cl::desc("Show origins of completion items"),
|
|
|
|
llvm::cl::init(CodeCompleteOptions().ShowOrigins), llvm::cl::Hidden);
|
2018-07-05 14:20:41 +08:00
|
|
|
|
2019-04-10 20:15:35 +08:00
|
|
|
static llvm::cl::opt<CodeCompleteOptions::IncludeInsertion> HeaderInsertion(
|
|
|
|
"header-insertion",
|
|
|
|
llvm::cl::desc("Add #include directives when accepting code completions"),
|
|
|
|
llvm::cl::init(CodeCompleteOptions().InsertIncludes),
|
|
|
|
llvm::cl::values(
|
|
|
|
clEnumValN(CodeCompleteOptions::IWYU, "iwyu",
|
|
|
|
"Include what you use. "
|
|
|
|
"Insert the owning header for top-level symbols, unless the "
|
|
|
|
"header is already directly included or the symbol is "
|
2019-05-28 17:31:27 +08:00
|
|
|
"forward-declared"),
|
2019-04-10 20:15:35 +08:00
|
|
|
clEnumValN(
|
|
|
|
CodeCompleteOptions::NeverInsert, "never",
|
|
|
|
"Never insert #include directives as part of code completion")));
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<bool> HeaderInsertionDecorators(
|
2018-07-30 03:12:42 +08:00
|
|
|
"header-insertion-decorators",
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::desc("Prepend a circular dot or space before the completion "
|
|
|
|
"label, depending on whether "
|
2019-05-28 17:31:27 +08:00
|
|
|
"an include line will be inserted or not"),
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::init(true));
|
2018-07-30 03:12:42 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<Path> IndexFile(
|
2018-10-08 18:44:54 +08:00
|
|
|
"index-file",
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::desc(
|
2018-10-08 18:44:54 +08:00
|
|
|
"Index file to build the static index. The file must have been created "
|
2019-05-28 17:31:27 +08:00
|
|
|
"by a compatible clangd-indexer\n"
|
2018-01-10 22:44:34 +08:00
|
|
|
"WARNING: This option is experimental only, and will be removed "
|
2019-05-28 17:31:27 +08:00
|
|
|
"eventually. Don't rely on it"),
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::init(""), llvm::cl::Hidden);
|
2018-01-10 22:44:34 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<bool> EnableBackgroundIndex(
|
[clangd] Enable auto-index behind a flag.
Summary:
Ownership and configuration:
The auto-index (background index) is maintained by ClangdServer, like Dynamic.
(This means ClangdServer will be able to enqueue preamble indexing in future).
For now it's enabled by a simple boolean flag in ClangdServer::Options, but
we probably want to eventually allow injecting the storage strategy.
New 'sync' command:
In order to meaningfully test the integration (not just unit-test components)
we need a way for tests to ensure the asynchronous index reads/writes occur
before a certain point.
Because these tests and assertions are few, I think exposing an explicit "sync"
command for use in tests is simpler than allowing threading to be completely
disabled in the background index (as we do for TUScheduler).
Bugs:
I fixed a couple of trivial bugs I found while testing, but there's one I can't.
JSONCompilationDatabase::getAllFiles() may return relative paths, and currently
we trigger an assertion that assumes they are absolute.
There's no efficient way to resolve them (you have to retrieve the corresponding
command and then resolve against its directory property). In general I think
this behavior is broken and we should fix it in JSONCompilationDatabase and
require CompilationDatabase::getAllFiles() to be absolute.
Reviewers: kadircet
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D54894
llvm-svn: 347567
2018-11-27 00:00:11 +08:00
|
|
|
"background-index",
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::desc(
|
|
|
|
"Index project code in the background and persist index on disk. "
|
|
|
|
"Experimental"),
|
2019-07-04 17:56:24 +08:00
|
|
|
llvm::cl::init(true));
|
[clangd] Enable auto-index behind a flag.
Summary:
Ownership and configuration:
The auto-index (background index) is maintained by ClangdServer, like Dynamic.
(This means ClangdServer will be able to enqueue preamble indexing in future).
For now it's enabled by a simple boolean flag in ClangdServer::Options, but
we probably want to eventually allow injecting the storage strategy.
New 'sync' command:
In order to meaningfully test the integration (not just unit-test components)
we need a way for tests to ensure the asynchronous index reads/writes occur
before a certain point.
Because these tests and assertions are few, I think exposing an explicit "sync"
command for use in tests is simpler than allowing threading to be completely
disabled in the background index (as we do for TUScheduler).
Bugs:
I fixed a couple of trivial bugs I found while testing, but there's one I can't.
JSONCompilationDatabase::getAllFiles() may return relative paths, and currently
we trigger an assertion that assumes they are absolute.
There's no efficient way to resolve them (you have to retrieve the corresponding
command and then resolve against its directory property). In general I think
this behavior is broken and we should fix it in JSONCompilationDatabase and
require CompilationDatabase::getAllFiles() to be absolute.
Reviewers: kadircet
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D54894
llvm-svn: 347567
2018-11-27 00:00:11 +08:00
|
|
|
|
2018-08-02 01:39:29 +08:00
|
|
|
enum CompileArgsFrom { LSPCompileArgs, FilesystemCompileArgs };
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::cl::opt<CompileArgsFrom> CompileArgsFrom(
|
|
|
|
"compile_args_from", llvm::cl::desc("The source of compile commands"),
|
|
|
|
llvm::cl::values(clEnumValN(LSPCompileArgs, "lsp",
|
|
|
|
"All compile commands come from LSP and "
|
|
|
|
"'compile_commands.json' files are ignored"),
|
|
|
|
clEnumValN(FilesystemCompileArgs, "filesystem",
|
|
|
|
"All compile commands come from the "
|
|
|
|
"'compile_commands.json' files")),
|
|
|
|
llvm::cl::init(FilesystemCompileArgs), llvm::cl::Hidden);
|
|
|
|
|
|
|
|
static llvm::cl::opt<bool> EnableFunctionArgSnippets(
|
2018-09-19 18:16:44 +08:00
|
|
|
"function-arg-placeholders",
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::desc("When disabled, completions contain only parentheses for "
|
|
|
|
"function calls. When enabled, completions also contain "
|
2019-05-28 17:31:27 +08:00
|
|
|
"placeholders for method parameters"),
|
2019-07-05 02:49:08 +08:00
|
|
|
llvm::cl::init(CodeCompleteOptions().EnableFunctionArgSnippets),
|
|
|
|
llvm::cl::Hidden);
|
2018-09-19 18:16:44 +08:00
|
|
|
|
2019-01-22 17:39:05 +08:00
|
|
|
static llvm::cl::opt<std::string> ClangTidyChecks(
|
|
|
|
"clang-tidy-checks",
|
2019-02-06 17:10:47 +08:00
|
|
|
llvm::cl::desc(
|
|
|
|
"List of clang-tidy checks to run (this will override "
|
2019-05-28 17:31:27 +08:00
|
|
|
".clang-tidy files). Only meaningful when -clang-tidy flag is on"),
|
2019-01-29 23:52:05 +08:00
|
|
|
llvm::cl::init(""));
|
2019-01-22 17:39:05 +08:00
|
|
|
|
2019-05-28 17:20:57 +08:00
|
|
|
static llvm::cl::opt<bool>
|
|
|
|
EnableClangTidy("clang-tidy",
|
2019-05-28 17:31:27 +08:00
|
|
|
llvm::cl::desc("Enable clang-tidy diagnostics"),
|
2019-05-28 17:20:57 +08:00
|
|
|
llvm::cl::init(true));
|
2019-02-06 17:10:47 +08:00
|
|
|
|
2019-05-06 16:11:59 +08:00
|
|
|
static llvm::cl::opt<std::string>
|
|
|
|
FallbackStyle("fallback-style",
|
|
|
|
llvm::cl::desc("clang-format style to apply by default when "
|
|
|
|
"no .clang-format file is found"),
|
|
|
|
llvm::cl::init(clang::format::DefaultFallbackStyle));
|
|
|
|
|
2019-01-28 22:01:55 +08:00
|
|
|
static llvm::cl::opt<bool> SuggestMissingIncludes(
|
|
|
|
"suggest-missing-includes",
|
|
|
|
llvm::cl::desc("Attempts to fix diagnostic errors caused by missing "
|
2019-05-28 17:31:27 +08:00
|
|
|
"includes using index"),
|
2019-03-01 22:17:55 +08:00
|
|
|
llvm::cl::init(true));
|
2019-01-28 22:01:55 +08:00
|
|
|
|
2019-03-28 01:47:49 +08:00
|
|
|
static llvm::cl::opt<OffsetEncoding> ForceOffsetEncoding(
|
|
|
|
"offset-encoding",
|
|
|
|
llvm::cl::desc("Force the offsetEncoding used for character positions. "
|
2019-05-28 17:31:27 +08:00
|
|
|
"This bypasses negotiation via client capabilities"),
|
2019-03-28 01:47:49 +08:00
|
|
|
llvm::cl::values(clEnumValN(OffsetEncoding::UTF8, "utf-8",
|
|
|
|
"Offsets are in UTF-8 bytes"),
|
|
|
|
clEnumValN(OffsetEncoding::UTF16, "utf-16",
|
|
|
|
"Offsets are in UTF-16 code units")),
|
|
|
|
llvm::cl::init(OffsetEncoding::UnsupportedEncoding));
|
|
|
|
|
2019-05-21 21:40:31 +08:00
|
|
|
static llvm::cl::opt<CodeCompleteOptions::CodeCompletionParse>
|
|
|
|
CodeCompletionParse(
|
|
|
|
"completion-parse",
|
|
|
|
llvm::cl::desc("Whether the clang-parser is used for code-completion"),
|
|
|
|
llvm::cl::values(clEnumValN(CodeCompleteOptions::AlwaysParse, "always",
|
|
|
|
"Block until the parser can be used"),
|
|
|
|
clEnumValN(CodeCompleteOptions::ParseIfReady, "auto",
|
|
|
|
"Use text-based completion if the parser "
|
|
|
|
"is not ready"),
|
|
|
|
clEnumValN(CodeCompleteOptions::NeverParse, "never",
|
|
|
|
"Always used text-based completion")),
|
|
|
|
llvm::cl::init(CodeCompleteOptions().RunParser), llvm::cl::Hidden);
|
[clangd] Add fallback mode for code completion when compile command or preamble is not ready.
Summary:
When calling TUScehduler::runWithPreamble (e.g. in code compleiton), allow
entering a fallback mode when compile command or preamble is not ready, instead of
waiting. This allows clangd to perform naive code completion e.g. using identifiers
in the current file or symbols in the index.
This patch simply returns empty result for code completion in fallback mode. Identifier-based
plus more advanced index-based completion will be added in followup patches.
Reviewers: ilya-biryukov, sammccall
Reviewed By: sammccall
Subscribers: sammccall, javed.absar, MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D59811
llvm-svn: 357916
2019-04-08 22:53:16 +08:00
|
|
|
|
2019-06-18 21:37:54 +08:00
|
|
|
static llvm::cl::opt<bool> HiddenFeatures(
|
|
|
|
"hidden-features",
|
|
|
|
llvm::cl::desc("Enable hidden features mostly useful to clangd developers"),
|
|
|
|
llvm::cl::init(false), llvm::cl::Hidden);
|
|
|
|
|
2019-06-26 15:45:27 +08:00
|
|
|
static llvm::cl::list<std::string> QueryDriverGlobs(
|
|
|
|
"query-driver",
|
|
|
|
llvm::cl::desc(
|
|
|
|
"Comma separated list of globs for white-listing gcc-compatible "
|
|
|
|
"drivers that are safe to execute. Drivers matching any of these globs "
|
|
|
|
"will be used to extract system includes. e.g. "
|
|
|
|
"/usr/bin/**/clang-*,/path/to/repo/**/g++-*"),
|
|
|
|
llvm::cl::CommaSeparated);
|
|
|
|
|
2019-07-02 00:55:29 +08:00
|
|
|
static llvm::cl::list<std::string> TweakList(
|
|
|
|
"tweaks",
|
|
|
|
llvm::cl::desc(
|
|
|
|
"Specify a list of Tweaks to enable (only for clangd developers)."),
|
|
|
|
llvm::cl::Hidden, llvm::cl::CommaSeparated);
|
|
|
|
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// \brief Supports a test URI scheme with relaxed constraints for lit tests.
|
|
|
|
/// The path in a test URI will be combined with a platform-specific fake
|
|
|
|
/// directory to form an absolute path. For example, test:///a.cpp is resolved
|
|
|
|
/// C:\clangd-test\a.cpp on Windows and /clangd-test/a.cpp on Unix.
|
|
|
|
class TestScheme : public URIScheme {
|
|
|
|
public:
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::Expected<std::string>
|
|
|
|
getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
|
|
|
|
llvm::StringRef /*HintPath*/) const override {
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
using namespace llvm::sys;
|
|
|
|
// Still require "/" in body to mimic file scheme, as we want lengths of an
|
|
|
|
// equivalent URI in both schemes to be the same.
|
|
|
|
if (!Body.startswith("/"))
|
2019-01-07 23:45:19 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
"Expect URI body to be an absolute path starting with '/': " + Body,
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::inconvertibleErrorCode());
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
Body = Body.ltrim('/');
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::SmallVector<char, 16> Path(Body.begin(), Body.end());
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
path::native(Path);
|
2019-01-16 18:26:52 +08:00
|
|
|
fs::make_absolute(TestScheme::TestDir, Path);
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
return std::string(Path.begin(), Path.end());
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::Expected<URI>
|
|
|
|
uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
|
|
|
|
llvm::StringRef Body = AbsolutePath;
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
if (!Body.consume_front(TestScheme::TestDir)) {
|
2019-01-07 23:45:19 +08:00
|
|
|
return llvm::make_error<llvm::StringError>(
|
|
|
|
"Path " + AbsolutePath + " doesn't start with root " + TestDir,
|
|
|
|
llvm::inconvertibleErrorCode());
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
return URI("test", /*Authority=*/"",
|
|
|
|
llvm::sys::path::convert_to_slash(Body));
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const static char TestDir[];
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
const char TestScheme::TestDir[] = "C:\\clangd-test";
|
|
|
|
#else
|
|
|
|
const char TestScheme::TestDir[] = "/clangd-test";
|
|
|
|
#endif
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
} // namespace
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
|
2019-01-16 08:24:22 +08:00
|
|
|
enum class ErrorResultCode : int {
|
|
|
|
NoShutdownRequest = 1,
|
|
|
|
CantRunAsXPCService = 2
|
|
|
|
};
|
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
int main(int argc, char *argv[]) {
|
2019-01-07 23:45:19 +08:00
|
|
|
using namespace clang;
|
|
|
|
using namespace clang::clangd;
|
|
|
|
|
2019-06-26 15:39:14 +08:00
|
|
|
llvm::InitializeAllTargetInfos();
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
|
|
|
|
llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
|
2018-06-29 21:24:20 +08:00
|
|
|
OS << clang::getClangToolFullVersion("clangd") << "\n";
|
|
|
|
});
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::cl::ParseCommandLineOptions(
|
2018-06-29 21:24:20 +08:00
|
|
|
argc, argv,
|
|
|
|
"clangd is a language server that provides IDE-like features to editors. "
|
2018-10-20 23:30:37 +08:00
|
|
|
"\n\nIt should be used via an editor plugin rather than invoked "
|
|
|
|
"directly. "
|
2018-06-29 21:24:20 +08:00
|
|
|
"For more information, see:"
|
|
|
|
"\n\thttps://clang.llvm.org/extra/clangd.html"
|
|
|
|
"\n\thttps://microsoft.github.io/language-server-protocol/");
|
2018-02-06 18:47:30 +08:00
|
|
|
if (Test) {
|
2019-05-28 17:20:57 +08:00
|
|
|
Sync = true;
|
2018-02-06 18:47:30 +08:00
|
|
|
InputStyle = JSONStreamStyle::Delimited;
|
2019-04-18 18:32:08 +08:00
|
|
|
LogLevel = Logger::Verbose;
|
2018-02-06 18:47:30 +08:00
|
|
|
PrettyPrint = true;
|
2019-07-19 21:40:30 +08:00
|
|
|
// Disable background index on lit tests by default to prevent disk writes.
|
|
|
|
if (!EnableBackgroundIndex.getNumOccurrences())
|
|
|
|
EnableBackgroundIndex = false;
|
2019-04-18 21:46:40 +08:00
|
|
|
// Ensure background index makes progress.
|
2019-07-19 21:40:30 +08:00
|
|
|
else if (EnableBackgroundIndex)
|
|
|
|
BackgroundQueue::preventThreadStarvationInTests();
|
2018-02-06 18:47:30 +08:00
|
|
|
}
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
if (Test || EnableTestScheme) {
|
|
|
|
static URISchemeRegistry::Add<TestScheme> X(
|
|
|
|
"test", "Test scheme for clangd lit tests.");
|
|
|
|
}
|
2017-05-16 22:40:30 +08:00
|
|
|
|
2019-05-28 17:20:57 +08:00
|
|
|
if (!Sync && WorkerThreadsCount == 0) {
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::errs() << "A number of worker threads cannot be 0. Did you mean to "
|
2019-05-28 17:20:57 +08:00
|
|
|
"specify -sync?";
|
2017-08-14 16:45:47 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-05-28 17:20:57 +08:00
|
|
|
if (Sync) {
|
2018-02-25 15:21:16 +08:00
|
|
|
if (WorkerThreadsCount.getNumOccurrences())
|
2019-05-28 17:20:57 +08:00
|
|
|
llvm::errs() << "Ignoring -j because -sync is set.\n";
|
2017-08-14 16:45:47 +08:00
|
|
|
WorkerThreadsCount = 0;
|
2018-02-25 15:21:16 +08:00
|
|
|
}
|
2019-05-06 16:11:59 +08:00
|
|
|
if (FallbackStyle.getNumOccurrences())
|
|
|
|
clang::format::DefaultFallbackStyle = FallbackStyle.c_str();
|
2017-08-14 16:45:47 +08:00
|
|
|
|
2017-10-26 18:07:04 +08:00
|
|
|
// Validate command line arguments.
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::Optional<llvm::raw_fd_ostream> InputMirrorStream;
|
2017-10-10 17:08:47 +08:00
|
|
|
if (!InputMirrorFile.empty()) {
|
|
|
|
std::error_code EC;
|
2018-06-08 03:58:58 +08:00
|
|
|
InputMirrorStream.emplace(InputMirrorFile, /*ref*/ EC,
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::sys::fs::FA_Read | llvm::sys::fs::FA_Write);
|
2017-10-10 17:08:47 +08:00
|
|
|
if (EC) {
|
|
|
|
InputMirrorStream.reset();
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::errs() << "Error while opening an input mirror file: "
|
|
|
|
<< EC.message();
|
2018-11-03 07:47:55 +08:00
|
|
|
} else {
|
|
|
|
InputMirrorStream->SetUnbuffered();
|
2017-10-10 17:08:47 +08:00
|
|
|
}
|
|
|
|
}
|
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.
|
2019-01-07 23:45:19 +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,
|
2019-01-07 23:45:19 +08:00
|
|
|
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();
|
2019-01-07 23:45:19 +08:00
|
|
|
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
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::Optional<trace::Session> TracingSession;
|
2017-12-14 23:04:59 +08:00
|
|
|
if (Tracer)
|
|
|
|
TracingSession.emplace(*Tracer);
|
|
|
|
|
2018-08-28 21:15:50 +08:00
|
|
|
// Use buffered stream to stderr (we still flush each log message). Unbuffered
|
|
|
|
// stream can cause significant (non-deterministic) latency for the logger.
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::errs().SetBuffered();
|
|
|
|
StreamLogger Logger(llvm::errs(), LogLevel);
|
|
|
|
LoggingSession LoggingSession(Logger);
|
2019-07-23 22:30:28 +08:00
|
|
|
// Write some initial logs before we start doing any real work.
|
|
|
|
log("{0}", clang::getClangToolFullVersion("clangd"));
|
|
|
|
{
|
|
|
|
SmallString<128> CWD;
|
|
|
|
if (auto Err = llvm::sys::fs::current_path(CWD))
|
|
|
|
log("Working directory unknown: {0}", Err.message());
|
|
|
|
else
|
|
|
|
log("Working directory: {0}", CWD);
|
|
|
|
}
|
|
|
|
for (int I = 0; I < argc; ++I)
|
|
|
|
log("argv[{0}]: {1}", I, argv[I]);
|
2017-12-13 20:51:22 +08:00
|
|
|
|
2017-10-02 23:13:20 +08:00
|
|
|
// If --compile-commands-dir arg was invoked, check value and override default
|
|
|
|
// path.
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::Optional<Path> CompileCommandsDirPath;
|
2018-10-23 19:54:36 +08:00
|
|
|
if (!CompileCommandsDir.empty()) {
|
2019-01-07 23:45:19 +08:00
|
|
|
if (llvm::sys::fs::exists(CompileCommandsDir)) {
|
2018-10-23 19:54:36 +08:00
|
|
|
// We support passing both relative and absolute paths to the
|
|
|
|
// --compile-commands-dir argument, but we assume the path is absolute in
|
|
|
|
// the rest of clangd so we make sure the path is absolute before
|
|
|
|
// continuing.
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::SmallString<128> Path(CompileCommandsDir);
|
|
|
|
if (std::error_code EC = llvm::sys::fs::make_absolute(Path)) {
|
|
|
|
llvm::errs() << "Error while converting the relative path specified by "
|
|
|
|
"--compile-commands-dir to an absolute path: "
|
|
|
|
<< EC.message() << ". The argument will be ignored.\n";
|
2018-10-23 19:54:36 +08:00
|
|
|
} else {
|
|
|
|
CompileCommandsDirPath = Path.str();
|
|
|
|
}
|
|
|
|
} else {
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::errs()
|
|
|
|
<< "Path specified by --compile-commands-dir does not exist. The "
|
|
|
|
"argument will be ignored.\n";
|
2018-10-23 19:54:36 +08:00
|
|
|
}
|
2017-10-02 23:13:20 +08:00
|
|
|
}
|
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;
|
[clangd] Enable auto-index behind a flag.
Summary:
Ownership and configuration:
The auto-index (background index) is maintained by ClangdServer, like Dynamic.
(This means ClangdServer will be able to enqueue preamble indexing in future).
For now it's enabled by a simple boolean flag in ClangdServer::Options, but
we probably want to eventually allow injecting the storage strategy.
New 'sync' command:
In order to meaningfully test the integration (not just unit-test components)
we need a way for tests to ensure the asynchronous index reads/writes occur
before a certain point.
Because these tests and assertions are few, I think exposing an explicit "sync"
command for use in tests is simpler than allowing threading to be completely
disabled in the background index (as we do for TUScheduler).
Bugs:
I fixed a couple of trivial bugs I found while testing, but there's one I can't.
JSONCompilationDatabase::getAllFiles() may return relative paths, and currently
we trigger an assertion that assumes they are absolute.
There's no efficient way to resolve them (you have to retrieve the corresponding
command and then resolve against its directory property). In general I think
this behavior is broken and we should fix it in JSONCompilationDatabase and
require CompilationDatabase::getAllFiles() to be absolute.
Reviewers: kadircet
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D54894
llvm-svn: 347567
2018-11-27 00:00:11 +08:00
|
|
|
Opts.BackgroundIndex = EnableBackgroundIndex;
|
2018-01-10 22:44:34 +08:00
|
|
|
std::unique_ptr<SymbolIndex> StaticIdx;
|
[clangd] Fix async index loading (from r341376).
Summary:
This wasn't actually async (due to std::future destructor blocking).
If it were, we would have clean shutdown issues if main returned
and destroyed Placeholder before the thread is done with it.
We could attempt to avoid any blocking by using shared_ptr or weak_ptr tricks so
the thread can detect Placeholder's destruction, but there are other potential
issues (e.g. loadIndex does tracing, and we'll destroy the tracer...)
Instead, once LSPServer::run returns, we wait for the index to finish loading
before exiting. Performance is not critical in this situation.
Reviewers: ilya-biryukov
Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51674
llvm-svn: 341797
2018-09-10 18:00:47 +08:00
|
|
|
std::future<void> AsyncIndexLoad; // Block exit while loading the index.
|
2018-10-08 18:44:54 +08:00
|
|
|
if (EnableIndex && !IndexFile.empty()) {
|
2018-09-05 00:19:40 +08:00
|
|
|
// Load the index asynchronously. Meanwhile SwapIndex returns no results.
|
|
|
|
SwapIndex *Placeholder;
|
|
|
|
StaticIdx.reset(Placeholder = new SwapIndex(llvm::make_unique<MemIndex>()));
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
AsyncIndexLoad = runAsync<void>([Placeholder] {
|
|
|
|
if (auto Idx = loadIndex(IndexFile, /*UseDex=*/true))
|
2018-09-05 00:19:40 +08:00
|
|
|
Placeholder->reset(std::move(Idx));
|
|
|
|
});
|
2019-05-28 17:20:57 +08:00
|
|
|
if (Sync)
|
[clangd] Fix async index loading (from r341376).
Summary:
This wasn't actually async (due to std::future destructor blocking).
If it were, we would have clean shutdown issues if main returned
and destroyed Placeholder before the thread is done with it.
We could attempt to avoid any blocking by using shared_ptr or weak_ptr tricks so
the thread can detect Placeholder's destruction, but there are other potential
issues (e.g. loadIndex does tracing, and we'll destroy the tracer...)
Instead, once LSPServer::run returns, we wait for the index to finish loading
before exiting. Performance is not critical in this situation.
Reviewers: ilya-biryukov
Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51674
llvm-svn: 341797
2018-09-10 18:00:47 +08:00
|
|
|
AsyncIndexLoad.wait();
|
2018-03-06 01:28:54 +08:00
|
|
|
}
|
2018-09-05 00:19:40 +08:00
|
|
|
Opts.StaticIndex = StaticIdx.get();
|
2018-03-06 01:28:54 +08:00
|
|
|
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;
|
2019-07-09 01:27:15 +08:00
|
|
|
if (CompletionStyle.getNumOccurrences())
|
|
|
|
CCOpts.BundleOverloads = CompletionStyle != Detailed;
|
2018-07-05 14:20:41 +08:00
|
|
|
CCOpts.ShowOrigins = ShowOrigins;
|
2019-04-10 20:15:35 +08:00
|
|
|
CCOpts.InsertIncludes = HeaderInsertion;
|
2018-07-30 03:12:42 +08:00
|
|
|
if (!HeaderInsertionDecorators) {
|
|
|
|
CCOpts.IncludeIndicator.Insert.clear();
|
|
|
|
CCOpts.IncludeIndicator.NoInsert.clear();
|
|
|
|
}
|
[clangd] Speculative code completion index request before Sema is run.
Summary:
For index-based code completion, send an asynchronous speculative index
request, based on the index request for the last code completion on the same
file and the filter text typed before the cursor, before sema code completion
is invoked. This can reduce the code completion latency (by roughly latency of
sema code completion) if the speculative request is the same as the one
generated for the ongoing code completion from sema. As a sequence of code
completions often have the same scopes and proximity paths etc, this should be
effective for a number of code completions.
Trace with speculative index request:{F6997544}
Reviewers: hokein, ilya-biryukov
Reviewed By: ilya-biryukov
Subscribers: javed.absar, jfb, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D50962
llvm-svn: 340604
2018-08-24 19:23:56 +08:00
|
|
|
CCOpts.SpeculativeIndexRequest = Opts.StaticIndex;
|
2018-09-19 18:16:44 +08:00
|
|
|
CCOpts.EnableFunctionArgSnippets = EnableFunctionArgSnippets;
|
2018-09-28 02:46:00 +08:00
|
|
|
CCOpts.AllScopes = AllScopesCompletion;
|
2019-05-21 21:40:31 +08:00
|
|
|
CCOpts.RunParser = CodeCompletionParse;
|
2018-03-06 01:28:54 +08:00
|
|
|
|
2019-01-22 17:39:05 +08:00
|
|
|
RealFileSystemProvider FSProvider;
|
2017-10-26 18:07:04 +08:00
|
|
|
// Initialize and run ClangdLSPServer.
|
[clangd] Refactor JSON-over-stdin/stdout code into Transport abstraction. (re-land r344620)
Summary:
This paves the way for alternative transports (mac XPC, maybe messagepack?),
and also generally improves layering: testing ClangdLSPServer becomes less of
a pipe dream, we split up the JSONOutput monolith, etc.
This isn't a final state, much of what remains in JSONRPCDispatcher can go away,
handlers can call reply() on the transport directly, JSONOutput can be renamed
to StreamLogger and removed, etc. But this patch is sprawling already.
The main observable change (see tests) is that hitting EOF on input is now an
error: the client should send the 'exit' notification.
This is defensible: the protocol doesn't spell this case out. Reproducing the
current behavior for all combinations of shutdown/exit/EOF clutters interfaces.
We can iterate on this if desired.
Reviewers: jkorous, ioeric, hokein
Subscribers: mgorny, ilya-biryukov, MaskRay, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D53286
llvm-svn: 344672
2018-10-17 15:32:05 +08:00
|
|
|
// Change stdin to binary to not lose \r\n on windows.
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::sys::ChangeStdinToBinary();
|
2019-01-16 08:24:22 +08:00
|
|
|
|
|
|
|
std::unique_ptr<Transport> TransportLayer;
|
|
|
|
if (getenv("CLANGD_AS_XPC_SERVICE")) {
|
2019-01-16 16:13:15 +08:00
|
|
|
#if CLANGD_BUILD_XPC
|
2019-07-23 22:30:28 +08:00
|
|
|
log("Starting LSP over XPC service");
|
2019-01-16 08:24:22 +08:00
|
|
|
TransportLayer = newXPCTransport();
|
|
|
|
#else
|
2019-01-16 16:13:15 +08:00
|
|
|
llvm::errs() << "This clangd binary wasn't built with XPC support.\n";
|
|
|
|
return (int)ErrorResultCode::CantRunAsXPCService;
|
2019-01-16 08:24:22 +08:00
|
|
|
#endif
|
|
|
|
} else {
|
2019-07-23 22:30:28 +08:00
|
|
|
log("Starting LSP over stdin/stdout");
|
2019-01-16 08:24:22 +08:00
|
|
|
TransportLayer = newJSONTransport(
|
|
|
|
stdin, llvm::outs(),
|
|
|
|
InputMirrorStream ? InputMirrorStream.getPointer() : nullptr,
|
|
|
|
PrettyPrint, InputStyle);
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:05 +08:00
|
|
|
// Create an empty clang-tidy option.
|
2019-05-21 01:30:46 +08:00
|
|
|
std::mutex ClangTidyOptMu;
|
|
|
|
std::unique_ptr<tidy::ClangTidyOptionsProvider>
|
|
|
|
ClangTidyOptProvider; /*GUARDED_BY(ClangTidyOptMu)*/
|
2019-02-06 17:10:47 +08:00
|
|
|
if (EnableClangTidy) {
|
|
|
|
auto OverrideClangTidyOptions = tidy::ClangTidyOptions::getDefaults();
|
|
|
|
OverrideClangTidyOptions.Checks = ClangTidyChecks;
|
|
|
|
ClangTidyOptProvider = llvm::make_unique<tidy::FileOptionsProvider>(
|
|
|
|
tidy::ClangTidyGlobalOptions(),
|
|
|
|
/* Default */ tidy::ClangTidyOptions::getDefaults(),
|
|
|
|
/* Override */ OverrideClangTidyOptions, FSProvider.getFileSystem());
|
2019-06-04 15:19:11 +08:00
|
|
|
Opts.GetClangTidyOptions = [&](llvm::vfs::FileSystem &,
|
|
|
|
llvm::StringRef File) {
|
|
|
|
// This function must be thread-safe and tidy option providers are not.
|
|
|
|
std::lock_guard<std::mutex> Lock(ClangTidyOptMu);
|
|
|
|
// FIXME: use the FS provided to the function.
|
|
|
|
return ClangTidyOptProvider->getOptions(File);
|
|
|
|
};
|
2019-02-06 17:10:47 +08:00
|
|
|
}
|
2019-01-28 22:01:55 +08:00
|
|
|
Opts.SuggestMissingIncludes = SuggestMissingIncludes;
|
2019-06-26 15:45:27 +08:00
|
|
|
Opts.QueryDriverGlobs = std::move(QueryDriverGlobs);
|
2019-07-12 16:50:20 +08:00
|
|
|
|
|
|
|
Opts.TweakFilter = [&](const Tweak &T) {
|
|
|
|
if (T.hidden() && !HiddenFeatures)
|
|
|
|
return false;
|
|
|
|
if (TweakList.getNumOccurrences())
|
|
|
|
return llvm::is_contained(TweakList, T.id());
|
|
|
|
return true;
|
|
|
|
};
|
2019-03-28 01:47:49 +08:00
|
|
|
llvm::Optional<OffsetEncoding> OffsetEncodingFromFlag;
|
|
|
|
if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding)
|
|
|
|
OffsetEncodingFromFlag = ForceOffsetEncoding;
|
2018-08-02 01:39:29 +08:00
|
|
|
ClangdLSPServer LSPServer(
|
2019-01-22 17:39:05 +08:00
|
|
|
*TransportLayer, FSProvider, CCOpts, CompileCommandsDirPath,
|
2019-03-28 01:47:49 +08:00
|
|
|
/*UseDirBasedCDB=*/CompileArgsFrom == FilesystemCompileArgs,
|
|
|
|
OffsetEncodingFromFlag, Opts);
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::set_thread_name("clangd.main");
|
2019-01-16 08:24:22 +08:00
|
|
|
return LSPServer.run() ? 0
|
|
|
|
: static_cast<int>(ErrorResultCode::NoShutdownRequest);
|
2017-02-07 18:28:20 +08:00
|
|
|
}
|