2017-02-07 18:28:20 +08:00
|
|
|
//===--- Protocol.cpp - Language Server Protocol Implementation -----------===//
|
|
|
|
//
|
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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the serialization code for the LSP structs.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Protocol.h"
|
2018-01-29 23:37:46 +08:00
|
|
|
#include "Logger.h"
|
2018-02-16 20:20:47 +08:00
|
|
|
#include "URI.h"
|
2018-11-28 00:40:46 +08:00
|
|
|
#include "index/Index.h"
|
2017-02-07 18:28:20 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
2018-11-28 00:40:46 +08:00
|
|
|
#include "llvm/ADT/Hashing.h"
|
2017-02-07 18:28:20 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
2017-09-18 23:02:59 +08:00
|
|
|
#include "llvm/Support/FormatVariadic.h"
|
2018-11-23 23:21:19 +08:00
|
|
|
#include "llvm/Support/JSON.h"
|
2017-04-07 19:03:26 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2017-08-02 17:08:39 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-09-20 15:24:15 +08:00
|
|
|
|
2017-12-01 05:32:29 +08:00
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
2017-11-29 19:36:46 +08:00
|
|
|
|
[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
|
|
|
char LSPError::ID;
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
URIForFile URIForFile::canonicalize(llvm::StringRef AbsPath,
|
|
|
|
llvm::StringRef TUPath) {
|
|
|
|
assert(llvm::sys::path::is_absolute(AbsPath) && "the path is relative");
|
2018-11-28 18:30:42 +08:00
|
|
|
auto Resolved = URI::resolvePath(AbsPath, TUPath);
|
|
|
|
if (!Resolved) {
|
|
|
|
elog("URIForFile: failed to resolve path {0} with TU path {1}: "
|
|
|
|
"{2}.\nUsing unresolved path.",
|
|
|
|
AbsPath, TUPath, Resolved.takeError());
|
|
|
|
return URIForFile(AbsPath);
|
|
|
|
}
|
|
|
|
return URIForFile(std::move(*Resolved));
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::Expected<URIForFile> URIForFile::fromURI(const URI &U,
|
|
|
|
llvm::StringRef HintPath) {
|
2018-11-28 18:30:42 +08:00
|
|
|
auto Resolved = URI::resolve(U, HintPath);
|
|
|
|
if (!Resolved)
|
|
|
|
return Resolved.takeError();
|
|
|
|
return URIForFile(std::move(*Resolved));
|
2018-02-16 20:20:47 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &E, URIForFile &R) {
|
2018-07-09 22:25:59 +08:00
|
|
|
if (auto S = E.getAsString()) {
|
2018-11-28 18:30:42 +08:00
|
|
|
auto Parsed = URI::parse(*S);
|
|
|
|
if (!Parsed) {
|
|
|
|
elog("Failed to parse URI {0}: {1}", *S, Parsed.takeError());
|
2018-01-29 23:37:46 +08:00
|
|
|
return false;
|
|
|
|
}
|
2018-11-28 18:30:42 +08:00
|
|
|
if (Parsed->scheme() != "file" && Parsed->scheme() != "test") {
|
[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
|
|
|
elog("Clangd only supports 'file' URI scheme for workspace files: {0}",
|
|
|
|
*S);
|
2018-01-29 23:37:46 +08:00
|
|
|
return false;
|
|
|
|
}
|
2018-11-28 18:30:42 +08:00
|
|
|
// "file" and "test" schemes do not require hint path.
|
|
|
|
auto U = URIForFile::fromURI(*Parsed, /*HintPath=*/"");
|
|
|
|
if (!U) {
|
|
|
|
elog("{0}", U.takeError());
|
2018-01-30 19:23:11 +08:00
|
|
|
return false;
|
|
|
|
}
|
2018-11-28 18:30:42 +08:00
|
|
|
R = std::move(*U);
|
2017-12-01 05:32:29 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-11-29 19:36:46 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const URIForFile &U) { return U.uri(); }
|
2017-04-07 19:03:26 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const URIForFile &U) {
|
2018-01-29 23:37:46 +08:00
|
|
|
return OS << U.uri();
|
2017-12-20 18:26:53 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const TextDocumentIdentifier &R) {
|
|
|
|
return llvm::json::Object{{"uri", R.uri}};
|
2018-02-16 22:15:55 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, TextDocumentIdentifier &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("uri", R.uri);
|
2017-02-07 18:28:20 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, Position &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("line", R.line) && O.map("character", R.character);
|
2017-02-07 18:28:20 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const Position &P) {
|
|
|
|
return llvm::json::Object{
|
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
|
|
|
{"line", P.line},
|
|
|
|
{"character", P.character},
|
|
|
|
};
|
2017-02-07 18:28:20 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Position &P) {
|
2017-12-20 18:26:53 +08:00
|
|
|
return OS << P.line << ':' << P.character;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, Range &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("start", R.start) && O.map("end", R.end);
|
2017-02-07 18:28:20 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const Range &P) {
|
|
|
|
return llvm::json::Object{
|
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
|
|
|
{"start", P.start},
|
|
|
|
{"end", P.end},
|
|
|
|
};
|
2017-02-07 18:28:20 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Range &R) {
|
2017-12-20 18:26:53 +08:00
|
|
|
return OS << R.start << '-' << R.end;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const Location &P) {
|
|
|
|
return llvm::json::Object{
|
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
|
|
|
{"uri", P.uri},
|
|
|
|
{"range", P.range},
|
|
|
|
};
|
2017-06-29 00:12:10 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Location &L) {
|
2017-12-20 18:26:53 +08:00
|
|
|
return OS << L.range << '@' << L.uri;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, TextDocumentItem &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("uri", R.uri) && O.map("languageId", R.languageId) &&
|
|
|
|
O.map("version", R.version) && O.map("text", R.text);
|
2017-02-07 18:28:20 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, TextEdit &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("range", R.range) && O.map("newText", R.newText);
|
2017-02-07 18:28:20 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const TextEdit &P) {
|
|
|
|
return llvm::json::Object{
|
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
|
|
|
{"range", P.range},
|
|
|
|
{"newText", P.newText},
|
|
|
|
};
|
[clangd] Handle clangd.applyFix server-side
Summary:
When the user selects a fix-it (or any code action with commands), it is
possible to let the client forward the selected command to the server.
When the clangd.applyFix command is handled on the server, it can send a
workspace/applyEdit request to the client. This has the advantage that
the client doesn't explicitly have to know how to handle
clangd.applyFix. Therefore, the code to handle clangd.applyFix in the VS
Code extension (and any other Clangd client) is not required anymore.
Reviewers: ilya-biryukov, sammccall, Nebiroth, hokein
Reviewed By: hokein
Subscribers: ioeric, hokein, rwols, puremourning, bkramer, ilya-biryukov
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D39276
llvm-svn: 317322
2017-11-03 21:39:15 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const TextEdit &TE) {
|
2018-01-26 01:29:17 +08:00
|
|
|
OS << TE.range << " => \"";
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::printEscapedString(TE.newText, OS);
|
2018-01-26 01:29:17 +08:00
|
|
|
return OS << '"';
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &E, TraceLevel &Out) {
|
2018-07-09 22:25:59 +08:00
|
|
|
if (auto S = E.getAsString()) {
|
2017-12-01 05:32:29 +08:00
|
|
|
if (*S == "off") {
|
|
|
|
Out = TraceLevel::Off;
|
|
|
|
return true;
|
|
|
|
} else if (*S == "messages") {
|
|
|
|
Out = TraceLevel::Messages;
|
|
|
|
return true;
|
|
|
|
} else if (*S == "verbose") {
|
|
|
|
Out = TraceLevel::Verbose;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &E, SymbolKind &Out) {
|
2018-07-09 22:25:59 +08:00
|
|
|
if (auto T = E.getAsInteger()) {
|
[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 (*T < static_cast<int>(SymbolKind::File) ||
|
|
|
|
*T > static_cast<int>(SymbolKind::TypeParameter))
|
|
|
|
return false;
|
|
|
|
Out = static_cast<SymbolKind>(*T);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &E, SymbolKindBitset &Out) {
|
2018-07-09 22:25:59 +08:00
|
|
|
if (auto *A = E.getAsArray()) {
|
[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
|
|
|
for (size_t I = 0; I < A->size(); ++I) {
|
|
|
|
SymbolKind KindOut;
|
|
|
|
if (fromJSON((*A)[I], KindOut))
|
2018-10-17 15:33:42 +08:00
|
|
|
Out.set(size_t(KindOut));
|
[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
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SymbolKind adjustKindToCapability(SymbolKind Kind,
|
2018-07-26 20:05:31 +08:00
|
|
|
SymbolKindBitset &SupportedSymbolKinds) {
|
[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
|
|
|
auto KindVal = static_cast<size_t>(Kind);
|
2018-07-26 20:05:31 +08:00
|
|
|
if (KindVal >= SymbolKindMin && KindVal <= SupportedSymbolKinds.size() &&
|
|
|
|
SupportedSymbolKinds[KindVal])
|
[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
|
|
|
return Kind;
|
|
|
|
|
|
|
|
switch (Kind) {
|
|
|
|
// Provide some fall backs for common kinds that are close enough.
|
|
|
|
case SymbolKind::Struct:
|
|
|
|
return SymbolKind::Class;
|
|
|
|
case SymbolKind::EnumMember:
|
|
|
|
return SymbolKind::Enum;
|
|
|
|
default:
|
|
|
|
return SymbolKind::String;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, ClientCapabilities &R) {
|
|
|
|
const llvm::json::Object *O = Params.getAsObject();
|
2018-02-15 22:32:57 +08:00
|
|
|
if (!O)
|
|
|
|
return false;
|
2018-10-17 15:33:42 +08:00
|
|
|
if (auto *TextDocument = O->getObject("textDocument")) {
|
|
|
|
if (auto *Diagnostics = TextDocument->getObject("publishDiagnostics")) {
|
|
|
|
if (auto CategorySupport = Diagnostics->getBoolean("categorySupport"))
|
|
|
|
R.DiagnosticCategory = *CategorySupport;
|
[clangd] Embed fixes as CodeAction, instead of clangd_fixes. Clean up serialization.
Summary:
CodeAction provides us with a standard way of representing fixes inline, so
use it, replacing our existing ad-hoc extension.
After this, it's easy to serialize diagnostics using the structured
toJSON/Protocol.h mechanism rather than assembling JSON ad-hoc.
Reviewers: hokein, arphaman
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D53391
llvm-svn: 345119
2018-10-24 15:59:38 +08:00
|
|
|
if (auto CodeActions = Diagnostics->getBoolean("codeActionsInline"))
|
|
|
|
R.DiagnosticFixes = *CodeActions;
|
2018-10-17 15:33:42 +08:00
|
|
|
}
|
|
|
|
if (auto *Completion = TextDocument->getObject("completion")) {
|
|
|
|
if (auto *Item = Completion->getObject("completionItem")) {
|
|
|
|
if (auto SnippetSupport = Item->getBoolean("snippetSupport"))
|
|
|
|
R.CompletionSnippets = *SnippetSupport;
|
|
|
|
}
|
|
|
|
if (auto *ItemKind = Completion->getObject("completionItemKind")) {
|
|
|
|
if (auto *ValueSet = ItemKind->get("valueSet")) {
|
|
|
|
R.CompletionItemKinds.emplace();
|
|
|
|
if (!fromJSON(*ValueSet, *R.CompletionItemKinds))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (auto *CodeAction = TextDocument->getObject("codeAction")) {
|
|
|
|
if (CodeAction->getObject("codeActionLiteralSupport"))
|
|
|
|
R.CodeActionStructure = true;
|
|
|
|
}
|
2018-11-23 23:21:19 +08:00
|
|
|
if (auto *DocumentSymbol = TextDocument->getObject("documentSymbol")) {
|
|
|
|
if (auto HierarchicalSupport =
|
|
|
|
DocumentSymbol->getBoolean("hierarchicalDocumentSymbolSupport"))
|
|
|
|
R.HierarchicalDocumentSymbol = *HierarchicalSupport;
|
|
|
|
}
|
2018-10-17 15:33:42 +08:00
|
|
|
}
|
|
|
|
if (auto *Workspace = O->getObject("workspace")) {
|
|
|
|
if (auto *Symbol = Workspace->getObject("symbol")) {
|
|
|
|
if (auto *SymbolKind = Symbol->getObject("symbolKind")) {
|
|
|
|
if (auto *ValueSet = SymbolKind->get("valueSet")) {
|
|
|
|
R.WorkspaceSymbolKinds.emplace();
|
|
|
|
if (!fromJSON(*ValueSet, *R.WorkspaceSymbolKinds))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-15 22:32:57 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, InitializeParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-11-28 17:37:43 +08:00
|
|
|
if (!O)
|
2017-12-01 05:32:29 +08:00
|
|
|
return false;
|
2017-11-29 19:36:46 +08:00
|
|
|
// We deliberately don't fail if we can't parse individual fields.
|
|
|
|
// Failing to handle a slightly malformed initialize would be a disaster.
|
2017-12-01 05:32:29 +08:00
|
|
|
O.map("processId", R.processId);
|
|
|
|
O.map("rootUri", R.rootUri);
|
|
|
|
O.map("rootPath", R.rootPath);
|
2018-02-15 22:32:57 +08:00
|
|
|
O.map("capabilities", R.capabilities);
|
2017-12-01 05:32:29 +08:00
|
|
|
O.map("trace", R.trace);
|
2018-08-01 19:28:49 +08:00
|
|
|
O.map("initializationOptions", R.initializationOptions);
|
2017-12-01 05:32:29 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, DidOpenTextDocumentParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2018-11-02 21:06:55 +08:00
|
|
|
return O && O.map("textDocument", R.textDocument);
|
2017-12-01 05:32:29 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, DidCloseTextDocumentParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("textDocument", R.textDocument);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, DidChangeTextDocumentParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("textDocument", R.textDocument) &&
|
2018-02-23 02:40:39 +08:00
|
|
|
O.map("contentChanges", R.contentChanges) &&
|
|
|
|
O.map("wantDiagnostics", R.wantDiagnostics);
|
2017-12-01 05:32:29 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &E, FileChangeType &Out) {
|
2018-07-09 22:25:59 +08:00
|
|
|
if (auto T = E.getAsInteger()) {
|
2017-12-01 05:32:29 +08:00
|
|
|
if (*T < static_cast<int>(FileChangeType::Created) ||
|
|
|
|
*T > static_cast<int>(FileChangeType::Deleted))
|
|
|
|
return false;
|
|
|
|
Out = static_cast<FileChangeType>(*T);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, FileEvent &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("uri", R.uri) && O.map("type", R.type);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, DidChangeWatchedFilesParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("changes", R.changes);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params,
|
|
|
|
TextDocumentContentChangeEvent &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
[clangd] Support incremental document syncing
Summary:
This patch adds support for incremental document syncing, as described
in the LSP spec. The protocol specifies ranges in terms of Position (a
line and a character), and our drafts are stored as plain strings. So I
see two things that may not be super efficient for very large files:
- Converting a Position to an offset (the positionToOffset function)
requires searching for end of lines until we reach the desired line.
- When we update a range, we construct a new string, which implies
copying the whole document.
However, for the typical size of a C++ document and the frequency of
update (at which a user types), it may not be an issue. This patch aims
at getting the basic feature in, and we can always improve it later if
we find it's too slow.
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Reviewers: malaperle, ilya-biryukov
Reviewed By: ilya-biryukov
Subscribers: MaskRay, klimek, mgorny, ilya-biryukov, jkorous-apple, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D44272
llvm-svn: 328500
2018-03-26 22:41:40 +08:00
|
|
|
return O && O.map("range", R.range) && O.map("rangeLength", R.rangeLength) &&
|
|
|
|
O.map("text", R.text);
|
2017-12-01 05:32:29 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, FormattingOptions &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("tabSize", R.tabSize) &&
|
|
|
|
O.map("insertSpaces", R.insertSpaces);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const FormattingOptions &P) {
|
|
|
|
return llvm::json::Object{
|
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
|
|
|
{"tabSize", P.tabSize},
|
|
|
|
{"insertSpaces", P.insertSpaces},
|
|
|
|
};
|
2017-02-07 18:28:20 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params,
|
|
|
|
DocumentRangeFormattingParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("textDocument", R.textDocument) &&
|
|
|
|
O.map("range", R.range) && O.map("options", R.options);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params,
|
|
|
|
DocumentOnTypeFormattingParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("textDocument", R.textDocument) &&
|
|
|
|
O.map("position", R.position) && O.map("ch", R.ch) &&
|
|
|
|
O.map("options", R.options);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, DocumentFormattingParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("textDocument", R.textDocument) &&
|
|
|
|
O.map("options", R.options);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, DocumentSymbolParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2018-07-06 03:35:01 +08:00
|
|
|
return O && O.map("textDocument", R.textDocument);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const Diagnostic &D) {
|
|
|
|
llvm::json::Object Diag{
|
2018-10-17 00:29:41 +08:00
|
|
|
{"range", D.range},
|
|
|
|
{"severity", D.severity},
|
|
|
|
{"message", D.message},
|
|
|
|
};
|
[clangd] Embed fixes as CodeAction, instead of clangd_fixes. Clean up serialization.
Summary:
CodeAction provides us with a standard way of representing fixes inline, so
use it, replacing our existing ad-hoc extension.
After this, it's easy to serialize diagnostics using the structured
toJSON/Protocol.h mechanism rather than assembling JSON ad-hoc.
Reviewers: hokein, arphaman
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D53391
llvm-svn: 345119
2018-10-24 15:59:38 +08:00
|
|
|
if (D.category)
|
|
|
|
Diag["category"] = *D.category;
|
|
|
|
if (D.codeActions)
|
|
|
|
Diag["codeActions"] = D.codeActions;
|
2018-10-17 00:29:41 +08:00
|
|
|
return std::move(Diag);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, Diagnostic &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
if (!O || !O.map("range", R.range) || !O.map("message", R.message))
|
|
|
|
return false;
|
|
|
|
O.map("severity", R.severity);
|
[clangd] Embed fixes as CodeAction, instead of clangd_fixes. Clean up serialization.
Summary:
CodeAction provides us with a standard way of representing fixes inline, so
use it, replacing our existing ad-hoc extension.
After this, it's easy to serialize diagnostics using the structured
toJSON/Protocol.h mechanism rather than assembling JSON ad-hoc.
Reviewers: hokein, arphaman
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D53391
llvm-svn: 345119
2018-10-24 15:59:38 +08:00
|
|
|
O.map("category", R.category);
|
2017-12-01 05:32:29 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, CodeActionContext &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("diagnostics", R.diagnostics);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Diagnostic &D) {
|
2018-01-26 01:29:17 +08:00
|
|
|
OS << D.range << " [";
|
|
|
|
switch (D.severity) {
|
2019-01-03 21:28:05 +08:00
|
|
|
case 1:
|
|
|
|
OS << "error";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
OS << "warning";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
OS << "note";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
OS << "remark";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
OS << "diagnostic";
|
|
|
|
break;
|
2018-01-26 01:29:17 +08:00
|
|
|
}
|
|
|
|
return OS << '(' << D.severity << "): " << D.message << "]";
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, CodeActionParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("textDocument", R.textDocument) &&
|
|
|
|
O.map("range", R.range) && O.map("context", R.context);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, WorkspaceEdit &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("changes", R.changes);
|
[clangd] Handle clangd.applyFix server-side
Summary:
When the user selects a fix-it (or any code action with commands), it is
possible to let the client forward the selected command to the server.
When the clangd.applyFix command is handled on the server, it can send a
workspace/applyEdit request to the client. This has the advantage that
the client doesn't explicitly have to know how to handle
clangd.applyFix. Therefore, the code to handle clangd.applyFix in the VS
Code extension (and any other Clangd client) is not required anymore.
Reviewers: ilya-biryukov, sammccall, Nebiroth, hokein
Reviewed By: hokein
Subscribers: ioeric, hokein, rwols, puremourning, bkramer, ilya-biryukov
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D39276
llvm-svn: 317322
2017-11-03 21:39:15 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
const llvm::StringLiteral ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND =
|
[clangd] Handle clangd.applyFix server-side
Summary:
When the user selects a fix-it (or any code action with commands), it is
possible to let the client forward the selected command to the server.
When the clangd.applyFix command is handled on the server, it can send a
workspace/applyEdit request to the client. This has the advantage that
the client doesn't explicitly have to know how to handle
clangd.applyFix. Therefore, the code to handle clangd.applyFix in the VS
Code extension (and any other Clangd client) is not required anymore.
Reviewers: ilya-biryukov, sammccall, Nebiroth, hokein
Reviewed By: hokein
Subscribers: ioeric, hokein, rwols, puremourning, bkramer, ilya-biryukov
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D39276
llvm-svn: 317322
2017-11-03 21:39:15 +08:00
|
|
|
"clangd.applyFix";
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, ExecuteCommandParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
if (!O || !O.map("command", R.command))
|
|
|
|
return false;
|
|
|
|
|
2018-07-09 22:25:59 +08:00
|
|
|
auto Args = Params.getAsObject()->getArray("arguments");
|
2017-12-01 05:32:29 +08:00
|
|
|
if (R.command == ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND) {
|
|
|
|
return Args && Args->size() == 1 &&
|
|
|
|
fromJSON(Args->front(), R.workspaceEdit);
|
|
|
|
}
|
|
|
|
return false; // Unrecognized command.
|
[clangd] Handle clangd.applyFix server-side
Summary:
When the user selects a fix-it (or any code action with commands), it is
possible to let the client forward the selected command to the server.
When the clangd.applyFix command is handled on the server, it can send a
workspace/applyEdit request to the client. This has the advantage that
the client doesn't explicitly have to know how to handle
clangd.applyFix. Therefore, the code to handle clangd.applyFix in the VS
Code extension (and any other Clangd client) is not required anymore.
Reviewers: ilya-biryukov, sammccall, Nebiroth, hokein
Reviewed By: hokein
Subscribers: ioeric, hokein, rwols, puremourning, bkramer, ilya-biryukov
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D39276
llvm-svn: 317322
2017-11-03 21:39:15 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const SymbolInformation &P) {
|
|
|
|
return llvm::json::Object{
|
[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
|
|
|
{"name", P.name},
|
|
|
|
{"kind", static_cast<int>(P.kind)},
|
|
|
|
{"location", P.location},
|
|
|
|
{"containerName", P.containerName},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &O,
|
|
|
|
const SymbolInformation &SI) {
|
[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
|
|
|
O << SI.containerName << "::" << SI.name << " - " << toJSON(SI);
|
|
|
|
return O;
|
|
|
|
}
|
|
|
|
|
2018-11-28 00:40:46 +08:00
|
|
|
bool operator==(const SymbolDetails &LHS, const SymbolDetails &RHS) {
|
|
|
|
return LHS.name == RHS.name && LHS.containerName == RHS.containerName &&
|
|
|
|
LHS.USR == RHS.USR && LHS.ID == RHS.ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::json::Value toJSON(const SymbolDetails &P) {
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Object result{{"name", llvm::json::Value(nullptr)},
|
|
|
|
{"containerName", llvm::json::Value(nullptr)},
|
|
|
|
{"usr", llvm::json::Value(nullptr)},
|
|
|
|
{"id", llvm::json::Value(nullptr)}};
|
2018-11-28 00:40:46 +08:00
|
|
|
|
|
|
|
if (!P.name.empty())
|
|
|
|
result["name"] = P.name;
|
|
|
|
|
|
|
|
if (!P.containerName.empty())
|
|
|
|
result["containerName"] = P.containerName;
|
|
|
|
|
|
|
|
if (!P.USR.empty())
|
|
|
|
result["usr"] = P.USR;
|
|
|
|
|
|
|
|
if (P.ID.hasValue())
|
|
|
|
result["id"] = P.ID.getValue().str();
|
|
|
|
|
2018-11-28 18:24:07 +08:00
|
|
|
// Older clang cannot compile 'return Result', even though it is legal.
|
2019-01-07 23:45:19 +08:00
|
|
|
return llvm::json::Value(std::move(result));
|
2018-11-28 00:40:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const SymbolDetails &S) {
|
|
|
|
if (!S.containerName.empty()) {
|
|
|
|
O << S.containerName;
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::StringRef ContNameRef;
|
2018-11-28 00:40:46 +08:00
|
|
|
if (!ContNameRef.endswith("::")) {
|
|
|
|
O << " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
O << S.name << " - " << toJSON(S);
|
|
|
|
return O;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, WorkspaceSymbolParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
[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
|
|
|
return O && O.map("query", R.query);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const Command &C) {
|
|
|
|
auto Cmd = llvm::json::Object{{"title", C.title}, {"command", C.command}};
|
2018-02-16 22:15:55 +08:00
|
|
|
if (C.workspaceEdit)
|
|
|
|
Cmd["arguments"] = {*C.workspaceEdit};
|
|
|
|
return std::move(Cmd);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
const llvm::StringLiteral CodeAction::QUICKFIX_KIND = "quickfix";
|
2018-10-17 00:29:41 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const CodeAction &CA) {
|
|
|
|
auto CodeAction = llvm::json::Object{{"title", CA.title}};
|
2018-10-17 00:29:41 +08:00
|
|
|
if (CA.kind)
|
|
|
|
CodeAction["kind"] = *CA.kind;
|
|
|
|
if (CA.diagnostics)
|
2019-01-07 23:45:19 +08:00
|
|
|
CodeAction["diagnostics"] = llvm::json::Array(*CA.diagnostics);
|
2018-10-17 00:29:41 +08:00
|
|
|
if (CA.edit)
|
|
|
|
CodeAction["edit"] = *CA.edit;
|
|
|
|
if (CA.command)
|
|
|
|
CodeAction["command"] = *CA.command;
|
|
|
|
return std::move(CodeAction);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const DocumentSymbol &S) {
|
2018-11-23 23:21:19 +08:00
|
|
|
return O << S.name << " - " << toJSON(S);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const DocumentSymbol &S) {
|
|
|
|
llvm::json::Object Result{{"name", S.name},
|
|
|
|
{"kind", static_cast<int>(S.kind)},
|
|
|
|
{"range", S.range},
|
|
|
|
{"selectionRange", S.selectionRange}};
|
2018-11-23 23:21:19 +08:00
|
|
|
|
|
|
|
if (!S.detail.empty())
|
|
|
|
Result["detail"] = S.detail;
|
|
|
|
if (!S.children.empty())
|
|
|
|
Result["children"] = S.children;
|
|
|
|
if (S.deprecated)
|
|
|
|
Result["deprecated"] = true;
|
2018-11-26 17:57:41 +08:00
|
|
|
// Older gcc cannot compile 'return Result', even though it is legal.
|
2019-01-07 23:45:19 +08:00
|
|
|
return llvm::json::Value(std::move(Result));
|
2018-11-23 23:21:19 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const WorkspaceEdit &WE) {
|
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
|
|
|
if (!WE.changes)
|
2019-01-07 23:45:19 +08:00
|
|
|
return llvm::json::Object{};
|
|
|
|
llvm::json::Object FileChanges;
|
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
|
|
|
for (auto &Change : *WE.changes)
|
2019-01-07 23:45:19 +08:00
|
|
|
FileChanges[Change.first] = llvm::json::Array(Change.second);
|
|
|
|
return llvm::json::Object{{"changes", std::move(FileChanges)}};
|
[clangd] Handle clangd.applyFix server-side
Summary:
When the user selects a fix-it (or any code action with commands), it is
possible to let the client forward the selected command to the server.
When the clangd.applyFix command is handled on the server, it can send a
workspace/applyEdit request to the client. This has the advantage that
the client doesn't explicitly have to know how to handle
clangd.applyFix. Therefore, the code to handle clangd.applyFix in the VS
Code extension (and any other Clangd client) is not required anymore.
Reviewers: ilya-biryukov, sammccall, Nebiroth, hokein
Reviewed By: hokein
Subscribers: ioeric, hokein, rwols, puremourning, bkramer, ilya-biryukov
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D39276
llvm-svn: 317322
2017-11-03 21:39:15 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const ApplyWorkspaceEditParams &Params) {
|
|
|
|
return llvm::json::Object{{"edit", Params.edit}};
|
[clangd] Handle clangd.applyFix server-side
Summary:
When the user selects a fix-it (or any code action with commands), it is
possible to let the client forward the selected command to the server.
When the clangd.applyFix command is handled on the server, it can send a
workspace/applyEdit request to the client. This has the advantage that
the client doesn't explicitly have to know how to handle
clangd.applyFix. Therefore, the code to handle clangd.applyFix in the VS
Code extension (and any other Clangd client) is not required anymore.
Reviewers: ilya-biryukov, sammccall, Nebiroth, hokein
Reviewed By: hokein
Subscribers: ioeric, hokein, rwols, puremourning, bkramer, ilya-biryukov
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D39276
llvm-svn: 317322
2017-11-03 21:39:15 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, TextDocumentPositionParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("textDocument", R.textDocument) &&
|
|
|
|
O.map("position", R.position);
|
2017-04-04 17:46:39 +08:00
|
|
|
}
|
|
|
|
|
2019-01-03 21:37:12 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, CompletionContext &R) {
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::ObjectMapper O(Params);
|
2019-01-03 21:37:12 +08:00
|
|
|
if (!O)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int triggerKind;
|
|
|
|
if (!O.map("triggerKind", triggerKind))
|
|
|
|
return false;
|
|
|
|
R.triggerKind = static_cast<CompletionTriggerKind>(triggerKind);
|
|
|
|
|
|
|
|
if (auto *TC = Params.getAsObject()->get("triggerCharacter"))
|
|
|
|
return fromJSON(*TC, R.triggerCharacter);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool fromJSON(const llvm::json::Value &Params, CompletionParams &R) {
|
|
|
|
if (!fromJSON(Params, static_cast<TextDocumentPositionParams &>(R)))
|
|
|
|
return false;
|
|
|
|
if (auto *Context = Params.getAsObject()->get("context"))
|
|
|
|
return fromJSON(*Context, R.context);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
static llvm::StringRef toTextKind(MarkupKind Kind) {
|
[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
|
|
|
switch (Kind) {
|
|
|
|
case MarkupKind::PlainText:
|
|
|
|
return "plaintext";
|
|
|
|
case MarkupKind::Markdown:
|
|
|
|
return "markdown";
|
|
|
|
}
|
|
|
|
llvm_unreachable("Invalid MarkupKind");
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const MarkupContent &MC) {
|
2018-02-17 07:12:26 +08:00
|
|
|
if (MC.value.empty())
|
[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
|
|
|
return nullptr;
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
return llvm::json::Object{
|
2018-02-17 07:12:26 +08:00
|
|
|
{"kind", toTextKind(MC.kind)},
|
|
|
|
{"value", MC.value},
|
[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
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const Hover &H) {
|
|
|
|
llvm::json::Object Result{{"contents", toJSON(H.contents)}};
|
[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-02-17 07:12:26 +08:00
|
|
|
if (H.range.hasValue())
|
|
|
|
Result["range"] = toJSON(*H.range);
|
[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
|
|
|
|
|
|
|
return std::move(Result);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &E, CompletionItemKind &Out) {
|
2018-09-28 01:13:07 +08:00
|
|
|
if (auto T = E.getAsInteger()) {
|
|
|
|
if (*T < static_cast<int>(CompletionItemKind::Text) ||
|
|
|
|
*T > static_cast<int>(CompletionItemKind::TypeParameter))
|
|
|
|
return false;
|
|
|
|
Out = static_cast<CompletionItemKind>(*T);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CompletionItemKind
|
|
|
|
adjustKindToCapability(CompletionItemKind Kind,
|
|
|
|
CompletionItemKindBitset &supportedCompletionItemKinds) {
|
|
|
|
auto KindVal = static_cast<size_t>(Kind);
|
|
|
|
if (KindVal >= CompletionItemKindMin &&
|
|
|
|
KindVal <= supportedCompletionItemKinds.size() &&
|
|
|
|
supportedCompletionItemKinds[KindVal])
|
|
|
|
return Kind;
|
|
|
|
|
|
|
|
switch (Kind) {
|
|
|
|
// Provide some fall backs for common kinds that are close enough.
|
|
|
|
case CompletionItemKind::Folder:
|
|
|
|
return CompletionItemKind::File;
|
|
|
|
case CompletionItemKind::EnumMember:
|
|
|
|
return CompletionItemKind::Enum;
|
|
|
|
case CompletionItemKind::Struct:
|
|
|
|
return CompletionItemKind::Class;
|
|
|
|
default:
|
|
|
|
return CompletionItemKind::Text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &E, CompletionItemKindBitset &Out) {
|
2018-09-28 01:13:07 +08:00
|
|
|
if (auto *A = E.getAsArray()) {
|
|
|
|
for (size_t I = 0; I < A->size(); ++I) {
|
|
|
|
CompletionItemKind KindOut;
|
|
|
|
if (fromJSON((*A)[I], KindOut))
|
2018-10-17 15:33:42 +08:00
|
|
|
Out.set(size_t(KindOut));
|
2018-09-28 01:13:07 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const CompletionItem &CI) {
|
2017-04-04 17:46:39 +08:00
|
|
|
assert(!CI.label.empty() && "completion item label is required");
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Object Result{{"label", CI.label}};
|
2017-04-04 17:46:39 +08:00
|
|
|
if (CI.kind != CompletionItemKind::Missing)
|
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
|
|
|
Result["kind"] = static_cast<int>(CI.kind);
|
2017-04-04 17:46:39 +08:00
|
|
|
if (!CI.detail.empty())
|
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
|
|
|
Result["detail"] = CI.detail;
|
2017-04-04 17:46:39 +08:00
|
|
|
if (!CI.documentation.empty())
|
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
|
|
|
Result["documentation"] = CI.documentation;
|
2017-04-04 17:46:39 +08:00
|
|
|
if (!CI.sortText.empty())
|
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
|
|
|
Result["sortText"] = CI.sortText;
|
2017-04-04 17:46:39 +08:00
|
|
|
if (!CI.filterText.empty())
|
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
|
|
|
Result["filterText"] = CI.filterText;
|
2017-04-04 17:46:39 +08:00
|
|
|
if (!CI.insertText.empty())
|
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
|
|
|
Result["insertText"] = CI.insertText;
|
|
|
|
if (CI.insertTextFormat != InsertTextFormat::Missing)
|
|
|
|
Result["insertTextFormat"] = static_cast<int>(CI.insertTextFormat);
|
2017-04-04 17:46:39 +08:00
|
|
|
if (CI.textEdit)
|
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
|
|
|
Result["textEdit"] = *CI.textEdit;
|
|
|
|
if (!CI.additionalTextEdits.empty())
|
2019-01-07 23:45:19 +08:00
|
|
|
Result["additionalTextEdits"] = llvm::json::Array(CI.additionalTextEdits);
|
2018-09-07 02:52:26 +08:00
|
|
|
if (CI.deprecated)
|
|
|
|
Result["deprecated"] = CI.deprecated;
|
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
|
|
|
return std::move(Result);
|
2017-04-04 17:46:39 +08:00
|
|
|
}
|
2017-10-06 19:54:17 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const CompletionItem &I) {
|
[clangd] Use operator<< to prevent printers issues in Gtest
Summary:
It is possible that there will be two different instantiations of
the printer template for a given type and some tests could end up calling the
wrong (default) one. For example, it was seen in CodeCompleteTests.cpp when
printing CompletionItems that it would use the wrong printer because the default
is also instantiated in ClangdTests.cpp.
With this change, objects that were previously printed with a custom Printer now
get printed through the operator<< which is declared alongside the class.
This rule of the thumb should make it less error-prone.
Reviewers: simark, ilya-biryukov, sammccall
Reviewed By: simark, ilya-biryukov, sammccall
Subscribers: bkramer, hokein, sammccall, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44764
llvm-svn: 329725
2018-04-11 01:34:46 +08:00
|
|
|
O << I.label << " - " << toJSON(I);
|
|
|
|
return O;
|
|
|
|
}
|
|
|
|
|
2017-12-01 05:32:29 +08:00
|
|
|
bool operator<(const CompletionItem &L, const CompletionItem &R) {
|
2017-11-08 15:44:12 +08:00
|
|
|
return (L.sortText.empty() ? L.label : L.sortText) <
|
|
|
|
(R.sortText.empty() ? R.label : R.sortText);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const CompletionList &L) {
|
|
|
|
return llvm::json::Object{
|
2017-11-15 17:16:29 +08:00
|
|
|
{"isIncomplete", L.isIncomplete},
|
2019-01-07 23:45:19 +08:00
|
|
|
{"items", llvm::json::Array(L.items)},
|
2017-11-15 17:16:29 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const ParameterInformation &PI) {
|
2017-10-06 19:54:17 +08:00
|
|
|
assert(!PI.label.empty() && "parameter information label is required");
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Object Result{{"label", PI.label}};
|
2017-10-06 19:54:17 +08:00
|
|
|
if (!PI.documentation.empty())
|
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
|
|
|
Result["documentation"] = PI.documentation;
|
|
|
|
return std::move(Result);
|
2017-10-06 19:54:17 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const SignatureInformation &SI) {
|
2017-10-06 19:54:17 +08:00
|
|
|
assert(!SI.label.empty() && "signature information label is required");
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Object Result{
|
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
|
|
|
{"label", SI.label},
|
2019-01-07 23:45:19 +08:00
|
|
|
{"parameters", llvm::json::Array(SI.parameters)},
|
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
|
|
|
};
|
2017-10-06 19:54:17 +08:00
|
|
|
if (!SI.documentation.empty())
|
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
|
|
|
Result["documentation"] = SI.documentation;
|
|
|
|
return std::move(Result);
|
2017-10-06 19:54:17 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &O,
|
|
|
|
const SignatureInformation &I) {
|
[clangd] Use operator<< to prevent printers issues in Gtest
Summary:
It is possible that there will be two different instantiations of
the printer template for a given type and some tests could end up calling the
wrong (default) one. For example, it was seen in CodeCompleteTests.cpp when
printing CompletionItems that it would use the wrong printer because the default
is also instantiated in ClangdTests.cpp.
With this change, objects that were previously printed with a custom Printer now
get printed through the operator<< which is declared alongside the class.
This rule of the thumb should make it less error-prone.
Reviewers: simark, ilya-biryukov, sammccall
Reviewed By: simark, ilya-biryukov, sammccall
Subscribers: bkramer, hokein, sammccall, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44764
llvm-svn: 329725
2018-04-11 01:34:46 +08:00
|
|
|
O << I.label << " - " << toJSON(I);
|
|
|
|
return O;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const SignatureHelp &SH) {
|
2017-10-06 19:54:17 +08:00
|
|
|
assert(SH.activeSignature >= 0 &&
|
|
|
|
"Unexpected negative value for number of active signatures.");
|
|
|
|
assert(SH.activeParameter >= 0 &&
|
|
|
|
"Unexpected negative value for active parameter index");
|
2019-01-07 23:45:19 +08:00
|
|
|
return llvm::json::Object{
|
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
|
|
|
{"activeSignature", SH.activeSignature},
|
|
|
|
{"activeParameter", SH.activeParameter},
|
2019-01-07 23:45:19 +08:00
|
|
|
{"signatures", llvm::json::Array(SH.signatures)},
|
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
|
|
|
};
|
2017-10-06 19:54:17 +08:00
|
|
|
}
|
2017-11-09 19:30:04 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, RenameParams &R) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2017-12-01 05:32:29 +08:00
|
|
|
return O && O.map("textDocument", R.textDocument) &&
|
|
|
|
O.map("position", R.position) && O.map("newName", R.newName);
|
2017-11-09 19:30:04 +08:00
|
|
|
}
|
2017-12-01 05:32:29 +08:00
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::json::Value toJSON(const DocumentHighlight &DH) {
|
|
|
|
return llvm::json::Object{
|
[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
|
|
|
{"range", toJSON(DH.range)},
|
|
|
|
{"kind", static_cast<int>(DH.kind)},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-12-20 23:39:12 +08:00
|
|
|
llvm::json::Value toJSON(const FileStatus &FStatus) {
|
2019-01-07 23:45:19 +08:00
|
|
|
return llvm::json::Object{
|
2019-01-03 21:28:05 +08:00
|
|
|
{"uri", FStatus.uri},
|
|
|
|
{"state", FStatus.state},
|
2018-12-20 23:39:12 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &O,
|
|
|
|
const DocumentHighlight &V) {
|
[clangd] Use operator<< to prevent printers issues in Gtest
Summary:
It is possible that there will be two different instantiations of
the printer template for a given type and some tests could end up calling the
wrong (default) one. For example, it was seen in CodeCompleteTests.cpp when
printing CompletionItems that it would use the wrong printer because the default
is also instantiated in ClangdTests.cpp.
With this change, objects that were previously printed with a custom Printer now
get printed through the operator<< which is declared alongside the class.
This rule of the thumb should make it less error-prone.
Reviewers: simark, ilya-biryukov, sammccall
Reviewed By: simark, ilya-biryukov, sammccall
Subscribers: bkramer, hokein, sammccall, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44764
llvm-svn: 329725
2018-04-11 01:34:46 +08:00
|
|
|
O << V.range;
|
|
|
|
if (V.kind == DocumentHighlightKind::Read)
|
|
|
|
O << "(r)";
|
|
|
|
if (V.kind == DocumentHighlightKind::Write)
|
|
|
|
O << "(w)";
|
|
|
|
return O;
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params,
|
|
|
|
DidChangeConfigurationParams &CCP) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
[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
|
|
|
return O && O.map("settings", CCP.settings);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params,
|
|
|
|
ClangdCompileCommand &CDbUpdate) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2018-08-02 01:39:29 +08:00
|
|
|
return O && O.map("workingDirectory", CDbUpdate.workingDirectory) &&
|
|
|
|
O.map("compilationCommand", CDbUpdate.compilationCommand);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, ConfigurationSettings &S) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2018-10-25 12:22:52 +08:00
|
|
|
if (!O)
|
|
|
|
return true; // 'any' type in LSP.
|
|
|
|
O.map("compilationDatabaseChanges", S.compilationDatabaseChanges);
|
|
|
|
return true;
|
[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
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, InitializationOptions &Opts) {
|
|
|
|
llvm::json::ObjectMapper O(Params);
|
2018-10-25 12:22:52 +08:00
|
|
|
if (!O)
|
|
|
|
return true; // 'any' type in LSP.
|
|
|
|
|
|
|
|
fromJSON(Params, Opts.ConfigSettings);
|
|
|
|
O.map("compilationDatabasePath", Opts.compilationDatabasePath);
|
2018-11-02 22:07:51 +08:00
|
|
|
O.map("fallbackFlags", Opts.fallbackFlags);
|
2018-12-20 23:39:12 +08:00
|
|
|
O.map("clangdFileStatus", Opts.FileStatus);
|
2018-10-25 12:22:52 +08:00
|
|
|
return true;
|
2018-10-16 23:55:03 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 23:45:19 +08:00
|
|
|
bool fromJSON(const llvm::json::Value &Params, ReferenceParams &R) {
|
2018-09-05 19:53:07 +08:00
|
|
|
TextDocumentPositionParams &Base = R;
|
|
|
|
return fromJSON(Params, Base);
|
|
|
|
}
|
|
|
|
|
2017-12-01 05:32:29 +08:00
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|