2017-02-07 18:28:20 +08:00
|
|
|
//===--- Protocol.h - Language Server Protocol Implementation ---*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains structs based on the LSP specification at
|
|
|
|
// https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md
|
|
|
|
//
|
|
|
|
// This is not meant to be a complete implementation, new interfaces are added
|
|
|
|
// when they're needed.
|
|
|
|
//
|
2017-12-01 05:32:29 +08:00
|
|
|
// Each struct has a toJSON and fromJSON function, that converts between
|
|
|
|
// the struct and a JSON representation. (See JSONExpr.h)
|
2017-02-07 18:28:20 +08:00
|
|
|
//
|
2017-12-20 18:26:53 +08:00
|
|
|
// Some structs also have operator<< serialization. This is for debugging and
|
|
|
|
// tests, and is not generally machine-readable.
|
|
|
|
//
|
2017-02-07 18:28:20 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROTOCOL_H
|
|
|
|
|
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
|
|
|
#include "JSONExpr.h"
|
2018-01-29 23:37:46 +08:00
|
|
|
#include "URI.h"
|
2017-02-07 18:28:20 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
|
|
|
#include <string>
|
2017-02-07 18:47:40 +08:00
|
|
|
#include <vector>
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
|
2017-11-07 18:21:02 +08:00
|
|
|
enum class ErrorCode {
|
|
|
|
// Defined by JSON RPC.
|
|
|
|
ParseError = -32700,
|
|
|
|
InvalidRequest = -32600,
|
|
|
|
MethodNotFound = -32601,
|
|
|
|
InvalidParams = -32602,
|
|
|
|
InternalError = -32603,
|
|
|
|
|
|
|
|
ServerNotInitialized = -32002,
|
|
|
|
UnknownErrorCode = -32001,
|
|
|
|
|
|
|
|
// Defined by the protocol.
|
|
|
|
RequestCancelled = -32800,
|
|
|
|
};
|
|
|
|
|
2018-01-29 23:37:46 +08:00
|
|
|
struct URIForFile {
|
2018-02-16 20:20:47 +08:00
|
|
|
URIForFile() = default;
|
|
|
|
explicit URIForFile(std::string AbsPath);
|
2017-04-07 19:03:26 +08:00
|
|
|
|
2018-02-16 20:20:47 +08:00
|
|
|
/// Retrieves absolute path to the file.
|
|
|
|
llvm::StringRef file() const { return File; }
|
|
|
|
|
|
|
|
explicit operator bool() const { return !File.empty(); }
|
|
|
|
std::string uri() const { return URI::createFile(File).toString(); }
|
2017-04-07 19:03:26 +08:00
|
|
|
|
2018-01-29 23:37:46 +08:00
|
|
|
friend bool operator==(const URIForFile &LHS, const URIForFile &RHS) {
|
2018-02-16 20:20:47 +08:00
|
|
|
return LHS.File == RHS.File;
|
2017-06-29 00:12:10 +08:00
|
|
|
}
|
|
|
|
|
2018-01-29 23:37:46 +08:00
|
|
|
friend bool operator!=(const URIForFile &LHS, const URIForFile &RHS) {
|
2017-06-29 00:12:10 +08:00
|
|
|
return !(LHS == RHS);
|
|
|
|
}
|
|
|
|
|
2018-01-29 23:37:46 +08:00
|
|
|
friend bool operator<(const URIForFile &LHS, const URIForFile &RHS) {
|
2018-02-16 20:20:47 +08:00
|
|
|
return LHS.File < RHS.File;
|
2017-06-29 00:12:10 +08:00
|
|
|
}
|
2018-02-16 20:20:47 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string File;
|
2017-04-07 19:03:26 +08:00
|
|
|
};
|
2018-01-29 23:37:46 +08:00
|
|
|
|
|
|
|
/// Serialize/deserialize \p URIForFile to/from a string URI.
|
|
|
|
json::Expr toJSON(const URIForFile &U);
|
|
|
|
bool fromJSON(const json::Expr &, URIForFile &);
|
2017-04-07 19:03:26 +08:00
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
struct TextDocumentIdentifier {
|
|
|
|
/// The text document's URI.
|
2018-01-29 23:37:46 +08:00
|
|
|
URIForFile uri;
|
2017-02-07 18:28:20 +08:00
|
|
|
};
|
2018-02-16 22:15:55 +08:00
|
|
|
json::Expr toJSON(const TextDocumentIdentifier &);
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, TextDocumentIdentifier &);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
struct Position {
|
|
|
|
/// Line position in a document (zero-based).
|
2018-02-14 18:52:04 +08:00
|
|
|
int line = 0;
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
/// Character offset on a line in a document (zero-based).
|
2018-02-14 18:52:04 +08:00
|
|
|
int character = 0;
|
2017-02-07 18:28:20 +08:00
|
|
|
|
2017-03-02 00:16:29 +08:00
|
|
|
friend bool operator==(const Position &LHS, const Position &RHS) {
|
|
|
|
return std::tie(LHS.line, LHS.character) ==
|
|
|
|
std::tie(RHS.line, RHS.character);
|
|
|
|
}
|
|
|
|
friend bool operator<(const Position &LHS, const Position &RHS) {
|
|
|
|
return std::tie(LHS.line, LHS.character) <
|
|
|
|
std::tie(RHS.line, RHS.character);
|
|
|
|
}
|
2018-02-21 10:39:08 +08:00
|
|
|
friend bool operator<=(const Position &LHS, const Position &RHS) {
|
|
|
|
return std::tie(LHS.line, LHS.character) <=
|
|
|
|
std::tie(RHS.line, RHS.character);
|
|
|
|
}
|
2017-02-07 18:28:20 +08:00
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, Position &);
|
|
|
|
json::Expr toJSON(const Position &);
|
2017-12-20 18:26:53 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Position &);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
struct Range {
|
|
|
|
/// The range's start position.
|
|
|
|
Position start;
|
|
|
|
|
|
|
|
/// The range's end position.
|
|
|
|
Position end;
|
|
|
|
|
2017-03-02 00:16:29 +08:00
|
|
|
friend bool operator==(const Range &LHS, const Range &RHS) {
|
|
|
|
return std::tie(LHS.start, LHS.end) == std::tie(RHS.start, RHS.end);
|
|
|
|
}
|
2018-03-12 23:28:22 +08:00
|
|
|
friend bool operator!=(const Range &LHS, const Range &RHS) {
|
|
|
|
return !(LHS == RHS);
|
|
|
|
}
|
2017-03-02 00:16:29 +08:00
|
|
|
friend bool operator<(const Range &LHS, const Range &RHS) {
|
|
|
|
return std::tie(LHS.start, LHS.end) < std::tie(RHS.start, RHS.end);
|
|
|
|
}
|
2018-02-21 10:39:08 +08:00
|
|
|
|
|
|
|
bool contains(Position Pos) const { return start <= Pos && Pos < end; }
|
2017-02-07 18:28:20 +08:00
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, Range &);
|
|
|
|
json::Expr toJSON(const Range &);
|
2017-12-20 18:26:53 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Range &);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
2017-06-29 00:12:10 +08:00
|
|
|
struct Location {
|
|
|
|
/// The text document's URI.
|
2018-01-29 23:37:46 +08:00
|
|
|
URIForFile uri;
|
2017-06-29 00:12:10 +08:00
|
|
|
Range range;
|
|
|
|
|
|
|
|
friend bool operator==(const Location &LHS, const Location &RHS) {
|
|
|
|
return LHS.uri == RHS.uri && LHS.range == RHS.range;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator!=(const Location &LHS, const Location &RHS) {
|
|
|
|
return !(LHS == RHS);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator<(const Location &LHS, const Location &RHS) {
|
|
|
|
return std::tie(LHS.uri, LHS.range) < std::tie(RHS.uri, RHS.range);
|
|
|
|
}
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
json::Expr toJSON(const Location &);
|
2017-12-20 18:26:53 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Location &);
|
2017-06-29 00:12:10 +08:00
|
|
|
|
2017-07-06 16:44:54 +08:00
|
|
|
struct Metadata {
|
|
|
|
std::vector<std::string> extraFlags;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, Metadata &);
|
2017-07-06 16:44:54 +08:00
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
struct TextEdit {
|
|
|
|
/// The range of the text document to be manipulated. To insert
|
|
|
|
/// text into a document create a range where start === end.
|
|
|
|
Range range;
|
|
|
|
|
|
|
|
/// The string to be inserted. For delete operations use an
|
|
|
|
/// empty string.
|
|
|
|
std::string newText;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, TextEdit &);
|
|
|
|
json::Expr toJSON(const TextEdit &);
|
2018-01-26 01:29:17 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TextEdit &);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
struct TextDocumentItem {
|
|
|
|
/// The text document's URI.
|
2018-01-29 23:37:46 +08:00
|
|
|
URIForFile uri;
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
/// The text document's language identifier.
|
|
|
|
std::string languageId;
|
|
|
|
|
|
|
|
/// The version number of this document (it will strictly increase after each
|
2018-02-14 18:52:04 +08:00
|
|
|
int version = 0;
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
/// The content of the opened text document.
|
|
|
|
std::string text;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, TextDocumentItem &);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
2017-09-27 23:31:17 +08:00
|
|
|
enum class TraceLevel {
|
|
|
|
Off = 0,
|
|
|
|
Messages = 1,
|
|
|
|
Verbose = 2,
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &E, TraceLevel &Out);
|
2017-09-27 23:31:17 +08:00
|
|
|
|
2017-12-01 05:32:29 +08:00
|
|
|
struct NoParams {};
|
|
|
|
inline bool fromJSON(const json::Expr &, NoParams &) { return true; }
|
2017-10-12 21:29:58 +08:00
|
|
|
using ShutdownParams = NoParams;
|
2017-10-25 16:45:41 +08:00
|
|
|
using ExitParams = NoParams;
|
2017-10-12 21:29:58 +08:00
|
|
|
|
[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
|
|
|
/// Defines how the host (editor) should sync document changes to the language
|
|
|
|
/// server.
|
|
|
|
enum class TextDocumentSyncKind {
|
|
|
|
/// Documents should not be synced at all.
|
|
|
|
None = 0,
|
|
|
|
|
|
|
|
/// Documents are synced by always sending the full content of the document.
|
|
|
|
Full = 1,
|
|
|
|
|
|
|
|
/// Documents are synced by sending the full content on open. After that
|
|
|
|
/// only incremental updates to the document are send.
|
|
|
|
Incremental = 2,
|
|
|
|
};
|
|
|
|
|
2018-02-15 22:32:57 +08:00
|
|
|
struct CompletionItemClientCapabilities {
|
|
|
|
/// Client supports snippets as insert text.
|
|
|
|
bool snippetSupport = false;
|
|
|
|
/// Client supports commit characters on a completion item.
|
|
|
|
bool commitCharacterSupport = false;
|
|
|
|
// Client supports the follow content formats for the documentation property.
|
|
|
|
// The order describes the preferred format of the client.
|
|
|
|
// NOTE: not used by clangd at the moment.
|
|
|
|
// std::vector<MarkupKind> documentationFormat;
|
|
|
|
};
|
|
|
|
bool fromJSON(const json::Expr &, CompletionItemClientCapabilities &);
|
|
|
|
|
|
|
|
struct CompletionClientCapabilities {
|
|
|
|
/// Whether completion supports dynamic registration.
|
|
|
|
bool dynamicRegistration = false;
|
|
|
|
/// The client supports the following `CompletionItem` specific capabilities.
|
|
|
|
CompletionItemClientCapabilities completionItem;
|
|
|
|
// NOTE: not used by clangd at the moment.
|
|
|
|
// llvm::Optional<CompletionItemKindCapabilities> completionItemKind;
|
|
|
|
|
|
|
|
/// The client supports to send additional context information for a
|
|
|
|
/// `textDocument/completion` request.
|
|
|
|
bool contextSupport = false;
|
|
|
|
};
|
|
|
|
bool fromJSON(const json::Expr &, CompletionClientCapabilities &);
|
|
|
|
|
|
|
|
// FIXME: most of the capabilities are missing from this struct. Only the ones
|
|
|
|
// used by clangd are currently there.
|
|
|
|
struct TextDocumentClientCapabilities {
|
|
|
|
/// Capabilities specific to the `textDocument/completion`
|
|
|
|
CompletionClientCapabilities completion;
|
|
|
|
};
|
|
|
|
bool fromJSON(const json::Expr &, TextDocumentClientCapabilities &);
|
|
|
|
|
|
|
|
struct ClientCapabilities {
|
|
|
|
// Workspace specific client capabilities.
|
|
|
|
// NOTE: not used by clangd at the moment.
|
|
|
|
// WorkspaceClientCapabilities workspace;
|
|
|
|
|
|
|
|
// Text document specific client capabilities.
|
|
|
|
TextDocumentClientCapabilities textDocument;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool fromJSON(const json::Expr &, ClientCapabilities &);
|
|
|
|
|
2017-09-27 23:31:17 +08:00
|
|
|
struct InitializeParams {
|
|
|
|
/// The process Id of the parent process that started
|
|
|
|
/// the server. Is null if the process has not been started by another
|
|
|
|
/// process. If the parent process is not alive then the server should exit
|
|
|
|
/// (see exit notification) its process.
|
|
|
|
llvm::Optional<int> processId;
|
|
|
|
|
|
|
|
/// The rootPath of the workspace. Is null
|
|
|
|
/// if no folder is open.
|
|
|
|
///
|
|
|
|
/// @deprecated in favour of rootUri.
|
|
|
|
llvm::Optional<std::string> rootPath;
|
|
|
|
|
|
|
|
/// The rootUri of the workspace. Is null if no
|
|
|
|
/// folder is open. If both `rootPath` and `rootUri` are set
|
|
|
|
/// `rootUri` wins.
|
2018-01-29 23:37:46 +08:00
|
|
|
llvm::Optional<URIForFile> rootUri;
|
2017-09-27 23:31:17 +08:00
|
|
|
|
|
|
|
// User provided initialization options.
|
|
|
|
// initializationOptions?: any;
|
|
|
|
|
|
|
|
/// The capabilities provided by the client (editor or tool)
|
2018-02-15 22:32:57 +08:00
|
|
|
ClientCapabilities capabilities;
|
2017-09-27 23:31:17 +08:00
|
|
|
|
|
|
|
/// The initial trace setting. If omitted trace is disabled ('off').
|
|
|
|
llvm::Optional<TraceLevel> trace;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, InitializeParams &);
|
2017-09-27 23:31:17 +08:00
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
struct DidOpenTextDocumentParams {
|
|
|
|
/// The document that was opened.
|
|
|
|
TextDocumentItem textDocument;
|
|
|
|
|
2017-07-06 16:44:54 +08:00
|
|
|
/// Extension storing per-file metadata, such as compilation flags.
|
|
|
|
llvm::Optional<Metadata> metadata;
|
2017-02-07 18:28:20 +08:00
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, DidOpenTextDocumentParams &);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
2017-04-10 21:31:39 +08:00
|
|
|
struct DidCloseTextDocumentParams {
|
|
|
|
/// The document that was closed.
|
|
|
|
TextDocumentIdentifier textDocument;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, DidCloseTextDocumentParams &);
|
2017-04-10 21:31:39 +08:00
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
struct TextDocumentContentChangeEvent {
|
[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
|
|
|
/// The range of the document that changed.
|
|
|
|
llvm::Optional<Range> range;
|
|
|
|
|
|
|
|
/// The length of the range that got replaced.
|
|
|
|
llvm::Optional<int> rangeLength;
|
|
|
|
|
|
|
|
/// The new text of the range/document.
|
2017-02-07 18:28:20 +08:00
|
|
|
std::string text;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, TextDocumentContentChangeEvent &);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
struct DidChangeTextDocumentParams {
|
|
|
|
/// The document that did change. The version number points
|
|
|
|
/// to the version after all provided content changes have
|
|
|
|
/// been applied.
|
|
|
|
TextDocumentIdentifier textDocument;
|
|
|
|
|
|
|
|
/// The actual content changes.
|
|
|
|
std::vector<TextDocumentContentChangeEvent> contentChanges;
|
2018-02-23 02:40:39 +08:00
|
|
|
|
|
|
|
/// Forces diagnostics to be generated, or to not be generated, for this
|
|
|
|
/// version of the file. If not set, diagnostics are eventually consistent:
|
|
|
|
/// either they will be provided for this version or some subsequent one.
|
|
|
|
/// This is a clangd extension.
|
|
|
|
llvm::Optional<bool> wantDiagnostics;
|
2017-02-07 18:28:20 +08:00
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, DidChangeTextDocumentParams &);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
2017-10-03 02:00:37 +08:00
|
|
|
enum class FileChangeType {
|
|
|
|
/// The file got created.
|
|
|
|
Created = 1,
|
|
|
|
/// The file got changed.
|
|
|
|
Changed = 2,
|
|
|
|
/// The file got deleted.
|
|
|
|
Deleted = 3
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &E, FileChangeType &Out);
|
2017-10-03 02:00:37 +08:00
|
|
|
|
|
|
|
struct FileEvent {
|
|
|
|
/// The file's URI.
|
2018-01-29 23:37:46 +08:00
|
|
|
URIForFile uri;
|
2017-10-03 02:00:37 +08:00
|
|
|
/// The change type.
|
2018-02-14 18:52:04 +08:00
|
|
|
FileChangeType type = FileChangeType::Created;
|
2017-10-03 02:00:37 +08:00
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, FileEvent &);
|
2017-10-03 02:00:37 +08:00
|
|
|
|
|
|
|
struct DidChangeWatchedFilesParams {
|
|
|
|
/// The actual file events.
|
|
|
|
std::vector<FileEvent> changes;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, DidChangeWatchedFilesParams &);
|
2017-10-03 02:00:37 +08:00
|
|
|
|
[clangd] DidChangeConfiguration Notification
Summary:
Implementation of DidChangeConfiguration notification handling in
clangd. This currently only supports changing one setting: the path of
the compilation database to be used for the current project. In other
words, it is no longer necessary to restart clangd with a different
command line argument in order to change the compilation database.
Reviewers: malaperle, krasimir, bkramer, ilya-biryukov
Subscribers: jkorous-apple, ioeric, simark, klimek, ilya-biryukov, arphaman, rwols, cfe-commits
Differential Revision: https://reviews.llvm.org/D39571
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Signed-off-by: William Enright <william.enright@polymtl.ca>
llvm-svn: 325784
2018-02-22 22:00:39 +08:00
|
|
|
/// Clangd extension to manage a workspace/didChangeConfiguration notification
|
|
|
|
/// since the data received is described as 'any' type in LSP.
|
|
|
|
struct ClangdConfigurationParamsChange {
|
|
|
|
llvm::Optional<std::string> compilationDatabasePath;
|
|
|
|
};
|
|
|
|
bool fromJSON(const json::Expr &, ClangdConfigurationParamsChange &);
|
|
|
|
|
|
|
|
struct DidChangeConfigurationParams {
|
|
|
|
// We use this predefined struct because it is easier to use
|
|
|
|
// than the protocol specified type of 'any'.
|
|
|
|
ClangdConfigurationParamsChange settings;
|
|
|
|
};
|
|
|
|
bool fromJSON(const json::Expr &, DidChangeConfigurationParams &);
|
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
struct FormattingOptions {
|
|
|
|
/// Size of a tab in spaces.
|
2018-02-14 18:52:04 +08:00
|
|
|
int tabSize = 0;
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
/// Prefer spaces over tabs.
|
2018-02-14 18:52:04 +08:00
|
|
|
bool insertSpaces = false;
|
2017-02-07 18:28:20 +08:00
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, FormattingOptions &);
|
|
|
|
json::Expr toJSON(const FormattingOptions &);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
|
|
|
struct DocumentRangeFormattingParams {
|
|
|
|
/// The document to format.
|
|
|
|
TextDocumentIdentifier textDocument;
|
|
|
|
|
|
|
|
/// The range to format
|
|
|
|
Range range;
|
|
|
|
|
|
|
|
/// The format options
|
|
|
|
FormattingOptions options;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, DocumentRangeFormattingParams &);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
2017-02-16 18:49:46 +08:00
|
|
|
struct DocumentOnTypeFormattingParams {
|
|
|
|
/// The document to format.
|
|
|
|
TextDocumentIdentifier textDocument;
|
|
|
|
|
|
|
|
/// The position at which this request was sent.
|
|
|
|
Position position;
|
|
|
|
|
|
|
|
/// The character that has been typed.
|
|
|
|
std::string ch;
|
|
|
|
|
|
|
|
/// The format options.
|
|
|
|
FormattingOptions options;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, DocumentOnTypeFormattingParams &);
|
2017-02-16 18:49:46 +08:00
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
struct DocumentFormattingParams {
|
|
|
|
/// The document to format.
|
|
|
|
TextDocumentIdentifier textDocument;
|
|
|
|
|
|
|
|
/// The format options
|
|
|
|
FormattingOptions options;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, DocumentFormattingParams &);
|
2017-02-07 18:28:20 +08:00
|
|
|
|
2017-03-02 00:16:29 +08:00
|
|
|
struct Diagnostic {
|
|
|
|
/// The range at which the message applies.
|
|
|
|
Range range;
|
|
|
|
|
|
|
|
/// The diagnostic's severity. Can be omitted. If omitted it is up to the
|
|
|
|
/// client to interpret diagnostics as error, warning, info or hint.
|
2018-02-14 18:52:04 +08:00
|
|
|
int severity = 0;
|
2017-03-02 00:16:29 +08:00
|
|
|
|
2017-09-18 23:02:59 +08:00
|
|
|
/// The diagnostic's code. Can be omitted.
|
|
|
|
/// Note: Not currently used by clangd
|
|
|
|
// std::string code;
|
|
|
|
|
|
|
|
/// A human-readable string describing the source of this
|
|
|
|
/// diagnostic, e.g. 'typescript' or 'super lint'.
|
|
|
|
/// Note: Not currently used by clangd
|
|
|
|
// std::string source;
|
|
|
|
|
2017-03-02 00:16:29 +08:00
|
|
|
/// The diagnostic's message.
|
|
|
|
std::string message;
|
2017-12-20 04:52:56 +08:00
|
|
|
};
|
2018-03-12 23:28:22 +08:00
|
|
|
|
2017-12-20 04:52:56 +08:00
|
|
|
/// A LSP-specific comparator used to find diagnostic in a container like
|
|
|
|
/// std:map.
|
|
|
|
/// We only use the required fields of Diagnostic to do the comparsion to avoid
|
|
|
|
/// any regression issues from LSP clients (e.g. VScode), see
|
|
|
|
/// https://git.io/vbr29
|
|
|
|
struct LSPDiagnosticCompare {
|
2018-03-12 23:28:22 +08:00
|
|
|
bool operator()(const Diagnostic &LHS, const Diagnostic &RHS) const {
|
2017-12-20 04:52:56 +08:00
|
|
|
return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
|
2017-03-02 00:16:29 +08:00
|
|
|
}
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, Diagnostic &);
|
2018-01-26 01:29:17 +08:00
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Diagnostic &);
|
2017-03-02 00:16:29 +08:00
|
|
|
|
|
|
|
struct CodeActionContext {
|
|
|
|
/// An array of diagnostics.
|
|
|
|
std::vector<Diagnostic> diagnostics;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, CodeActionContext &);
|
2017-03-02 00:16:29 +08:00
|
|
|
|
|
|
|
struct CodeActionParams {
|
|
|
|
/// The document in which the command was invoked.
|
|
|
|
TextDocumentIdentifier textDocument;
|
|
|
|
|
|
|
|
/// The range for which the command was invoked.
|
|
|
|
Range range;
|
|
|
|
|
|
|
|
/// Context carrying additional information.
|
|
|
|
CodeActionContext context;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, CodeActionParams &);
|
2017-03-02 00:16:29 +08:00
|
|
|
|
[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
|
|
|
struct WorkspaceEdit {
|
|
|
|
/// Holds changes to existing resources.
|
|
|
|
llvm::Optional<std::map<std::string, std::vector<TextEdit>>> changes;
|
|
|
|
|
|
|
|
/// Note: "documentChanges" is not currently used because currently there is
|
|
|
|
/// no support for versioned edits.
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, WorkspaceEdit &);
|
|
|
|
json::Expr toJSON(const WorkspaceEdit &WE);
|
[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
|
|
|
|
2018-02-16 22:15:55 +08:00
|
|
|
struct IncludeInsertion {
|
|
|
|
/// The document in which the command was invoked.
|
2018-02-26 16:32:13 +08:00
|
|
|
/// If either originalHeader or preferredHeader has been (directly) included
|
|
|
|
/// in the current file, no new include will be inserted.
|
2018-02-16 22:15:55 +08:00
|
|
|
TextDocumentIdentifier textDocument;
|
|
|
|
|
2018-02-26 16:32:13 +08:00
|
|
|
/// The declaring header corresponding to this insertion e.g. the header that
|
|
|
|
/// declares a symbol. This could be either a URI or a literal string quoted
|
|
|
|
/// with <> or "" that can be #included directly.
|
|
|
|
std::string declaringHeader;
|
|
|
|
/// The preferred header to be inserted. This may be different from
|
|
|
|
/// originalHeader as a header file can have a different canonical include.
|
|
|
|
/// This could be either a URI or a literal string quoted with <> or "" that
|
|
|
|
/// can be #included directly. If empty, declaringHeader is used to calculate
|
|
|
|
/// the #include path.
|
|
|
|
std::string preferredHeader;
|
2018-02-16 22:15:55 +08:00
|
|
|
};
|
|
|
|
bool fromJSON(const json::Expr &, IncludeInsertion &);
|
|
|
|
json::Expr toJSON(const IncludeInsertion &II);
|
|
|
|
|
[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
|
|
|
/// Exact commands are not specified in the protocol so we define the
|
|
|
|
/// ones supported by Clangd here. The protocol specifies the command arguments
|
|
|
|
/// to be "any[]" but to make this safer and more manageable, each command we
|
|
|
|
/// handle maps to a certain llvm::Optional of some struct to contain its
|
|
|
|
/// arguments. Different commands could reuse the same llvm::Optional as
|
|
|
|
/// arguments but a command that needs different arguments would simply add a
|
|
|
|
/// new llvm::Optional and not use any other ones. In practice this means only
|
|
|
|
/// one argument type will be parsed and set.
|
|
|
|
struct ExecuteCommandParams {
|
|
|
|
// Command to apply fix-its. Uses WorkspaceEdit as argument.
|
2017-12-28 23:03:02 +08:00
|
|
|
const static llvm::StringLiteral CLANGD_APPLY_FIX_COMMAND;
|
2018-02-16 22:15:55 +08:00
|
|
|
// Command to insert an #include into code.
|
|
|
|
const static llvm::StringLiteral CLANGD_INSERT_HEADER_INCLUDE;
|
[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
|
|
|
|
|
|
|
/// The command identifier, e.g. CLANGD_APPLY_FIX_COMMAND
|
|
|
|
std::string command;
|
|
|
|
|
|
|
|
// Arguments
|
|
|
|
llvm::Optional<WorkspaceEdit> workspaceEdit;
|
2018-02-16 22:15:55 +08:00
|
|
|
|
|
|
|
llvm::Optional<IncludeInsertion> includeInsertion;
|
[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
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, ExecuteCommandParams &);
|
[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
|
|
|
|
2018-02-16 22:15:55 +08:00
|
|
|
struct Command : public ExecuteCommandParams {
|
|
|
|
std::string title;
|
|
|
|
};
|
|
|
|
|
|
|
|
json::Expr toJSON(const Command &C);
|
|
|
|
|
[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
|
|
|
struct ApplyWorkspaceEditParams {
|
|
|
|
WorkspaceEdit edit;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
json::Expr toJSON(const ApplyWorkspaceEditParams &);
|
[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
|
|
|
|
2017-04-04 17:46:39 +08:00
|
|
|
struct TextDocumentPositionParams {
|
|
|
|
/// The text document.
|
|
|
|
TextDocumentIdentifier textDocument;
|
|
|
|
|
|
|
|
/// The position inside the text document.
|
|
|
|
Position position;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, TextDocumentPositionParams &);
|
2017-04-04 17:46:39 +08:00
|
|
|
|
[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
|
|
|
enum class MarkupKind {
|
|
|
|
PlainText,
|
|
|
|
Markdown,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MarkupContent {
|
2018-02-17 07:12:26 +08:00
|
|
|
MarkupKind kind = MarkupKind::PlainText;
|
|
|
|
std::string 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
|
|
|
};
|
|
|
|
json::Expr toJSON(const MarkupContent &MC);
|
|
|
|
|
|
|
|
struct Hover {
|
|
|
|
/// The hover's content
|
2018-02-17 07:12:26 +08:00
|
|
|
MarkupContent 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
|
|
|
|
|
|
|
/// An optional range is a range inside a text document
|
|
|
|
/// that is used to visualize a hover, e.g. by changing the background color.
|
2018-02-17 07:12:26 +08:00
|
|
|
llvm::Optional<Range> 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
|
|
|
};
|
|
|
|
json::Expr toJSON(const Hover &H);
|
|
|
|
|
2017-04-04 17:46:39 +08:00
|
|
|
/// The kind of a completion entry.
|
|
|
|
enum class CompletionItemKind {
|
|
|
|
Missing = 0,
|
|
|
|
Text = 1,
|
|
|
|
Method = 2,
|
|
|
|
Function = 3,
|
|
|
|
Constructor = 4,
|
|
|
|
Field = 5,
|
|
|
|
Variable = 6,
|
|
|
|
Class = 7,
|
|
|
|
Interface = 8,
|
|
|
|
Module = 9,
|
|
|
|
Property = 10,
|
|
|
|
Unit = 11,
|
|
|
|
Value = 12,
|
|
|
|
Enum = 13,
|
|
|
|
Keyword = 14,
|
|
|
|
Snippet = 15,
|
|
|
|
Color = 16,
|
|
|
|
File = 17,
|
|
|
|
Reference = 18,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Defines whether the insert text in a completion item should be interpreted
|
|
|
|
/// as plain text or a snippet.
|
|
|
|
enum class InsertTextFormat {
|
|
|
|
Missing = 0,
|
|
|
|
/// The primary text to be inserted is treated as a plain string.
|
|
|
|
PlainText = 1,
|
|
|
|
/// The primary text to be inserted is treated as a snippet.
|
|
|
|
///
|
|
|
|
/// A snippet can define tab stops and placeholders with `$1`, `$2`
|
|
|
|
/// and `${3:foo}`. `$0` defines the final tab stop, it defaults to the end
|
|
|
|
/// of the snippet. Placeholders with equal identifiers are linked, that is
|
|
|
|
/// typing in one will update others too.
|
|
|
|
///
|
|
|
|
/// See also:
|
|
|
|
/// https//github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md
|
|
|
|
Snippet = 2,
|
|
|
|
};
|
|
|
|
|
2018-01-13 00:16:09 +08:00
|
|
|
/// Provides details for how a completion item was scored.
|
|
|
|
/// This can be used for client-side filtering of completion items as the
|
|
|
|
/// user keeps typing.
|
|
|
|
/// This is a clangd extension.
|
|
|
|
struct CompletionItemScores {
|
2018-02-14 18:52:04 +08:00
|
|
|
/// The score that items are ranked by.
|
|
|
|
/// This is filterScore * symbolScore.
|
|
|
|
float finalScore = 0.f;
|
|
|
|
/// How the partial identifier matched filterText. [0-1]
|
|
|
|
float filterScore = 0.f;
|
|
|
|
/// How the symbol fits, ignoring the partial identifier.
|
|
|
|
float symbolScore = 0.f;
|
2018-01-13 00:16:09 +08:00
|
|
|
};
|
|
|
|
|
2017-04-04 17:46:39 +08:00
|
|
|
struct CompletionItem {
|
|
|
|
/// The label of this completion item. By default also the text that is
|
|
|
|
/// inserted when selecting this completion.
|
|
|
|
std::string label;
|
|
|
|
|
|
|
|
/// The kind of this completion item. Based of the kind an icon is chosen by
|
|
|
|
/// the editor.
|
|
|
|
CompletionItemKind kind = CompletionItemKind::Missing;
|
|
|
|
|
|
|
|
/// A human-readable string with additional information about this item, like
|
|
|
|
/// type or symbol information.
|
|
|
|
std::string detail;
|
|
|
|
|
|
|
|
/// A human-readable string that represents a doc-comment.
|
|
|
|
std::string documentation;
|
|
|
|
|
|
|
|
/// A string that should be used when comparing this item with other items.
|
|
|
|
/// When `falsy` the label is used.
|
|
|
|
std::string sortText;
|
|
|
|
|
2018-01-13 00:16:09 +08:00
|
|
|
/// Details about the quality of this completion item. (clangd extension)
|
|
|
|
llvm::Optional<CompletionItemScores> scoreInfo;
|
|
|
|
|
2017-04-04 17:46:39 +08:00
|
|
|
/// A string that should be used when filtering a set of completion items.
|
|
|
|
/// When `falsy` the label is used.
|
|
|
|
std::string filterText;
|
|
|
|
|
|
|
|
/// A string that should be inserted to a document when selecting this
|
|
|
|
/// completion. When `falsy` the label is used.
|
|
|
|
std::string insertText;
|
|
|
|
|
|
|
|
/// The format of the insert text. The format applies to both the `insertText`
|
|
|
|
/// property and the `newText` property of a provided `textEdit`.
|
|
|
|
InsertTextFormat insertTextFormat = InsertTextFormat::Missing;
|
|
|
|
|
|
|
|
/// An edit which is applied to a document when selecting this completion.
|
|
|
|
/// When an edit is provided `insertText` is ignored.
|
|
|
|
///
|
|
|
|
/// Note: The range of the edit must be a single line range and it must
|
|
|
|
/// contain the position at which completion has been requested.
|
|
|
|
llvm::Optional<TextEdit> textEdit;
|
|
|
|
|
|
|
|
/// An optional array of additional text edits that are applied when selecting
|
|
|
|
/// this completion. Edits must not overlap with the main edit nor with
|
|
|
|
/// themselves.
|
|
|
|
std::vector<TextEdit> additionalTextEdits;
|
2017-04-07 19:03:26 +08:00
|
|
|
|
2018-02-16 22:15:55 +08:00
|
|
|
llvm::Optional<Command> command;
|
2017-04-04 17:46:39 +08:00
|
|
|
// TODO(krasimir): The following optional fields defined by the language
|
|
|
|
// server protocol are unsupported:
|
|
|
|
//
|
|
|
|
// data?: any - A data entry field that is preserved on a completion item
|
|
|
|
// between a completion and a completion resolve request.
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
json::Expr toJSON(const CompletionItem &);
|
[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
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const CompletionItem &);
|
2017-04-04 17:46:39 +08:00
|
|
|
|
2017-11-08 15:44:12 +08:00
|
|
|
bool operator<(const CompletionItem &, const CompletionItem &);
|
|
|
|
|
2017-11-15 17:16:29 +08:00
|
|
|
/// Represents a collection of completion items to be presented in the editor.
|
|
|
|
struct CompletionList {
|
|
|
|
/// The list is not complete. Further typing should result in recomputing the
|
|
|
|
/// list.
|
|
|
|
bool isIncomplete = false;
|
|
|
|
|
|
|
|
/// The completion items.
|
|
|
|
std::vector<CompletionItem> items;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
json::Expr toJSON(const CompletionList &);
|
2017-11-15 17:16:29 +08:00
|
|
|
|
2017-10-06 19:54:17 +08:00
|
|
|
/// A single parameter of a particular signature.
|
|
|
|
struct ParameterInformation {
|
|
|
|
|
|
|
|
/// The label of this parameter. Mandatory.
|
|
|
|
std::string label;
|
|
|
|
|
|
|
|
/// The documentation of this parameter. Optional.
|
|
|
|
std::string documentation;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
json::Expr toJSON(const ParameterInformation &);
|
2017-10-06 19:54:17 +08:00
|
|
|
|
|
|
|
/// Represents the signature of something callable.
|
|
|
|
struct SignatureInformation {
|
|
|
|
|
|
|
|
/// The label of this signature. Mandatory.
|
|
|
|
std::string label;
|
|
|
|
|
|
|
|
/// The documentation of this signature. Optional.
|
|
|
|
std::string documentation;
|
|
|
|
|
|
|
|
/// The parameters of this signature.
|
|
|
|
std::vector<ParameterInformation> parameters;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
json::Expr toJSON(const SignatureInformation &);
|
[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
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &,
|
|
|
|
const SignatureInformation &);
|
2017-10-06 19:54:17 +08:00
|
|
|
|
|
|
|
/// Represents the signature of a callable.
|
|
|
|
struct SignatureHelp {
|
|
|
|
|
|
|
|
/// The resulting signatures.
|
|
|
|
std::vector<SignatureInformation> signatures;
|
|
|
|
|
|
|
|
/// The active signature.
|
|
|
|
int activeSignature = 0;
|
|
|
|
|
|
|
|
/// The active parameter of the active signature.
|
|
|
|
int activeParameter = 0;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
json::Expr toJSON(const SignatureHelp &);
|
2017-10-06 19:54:17 +08:00
|
|
|
|
2017-11-09 19:30:04 +08:00
|
|
|
struct RenameParams {
|
|
|
|
/// The document that was opened.
|
|
|
|
TextDocumentIdentifier textDocument;
|
|
|
|
|
|
|
|
/// The position at which this request was sent.
|
|
|
|
Position position;
|
|
|
|
|
|
|
|
/// The new name of the symbol.
|
|
|
|
std::string newName;
|
|
|
|
};
|
2017-12-01 05:32:29 +08:00
|
|
|
bool fromJSON(const json::Expr &, RenameParams &);
|
2017-11-09 19:30:04 +08:00
|
|
|
|
[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
|
|
|
enum class DocumentHighlightKind { Text = 1, Read = 2, Write = 3 };
|
|
|
|
|
|
|
|
/// A document highlight is a range inside a text document which deserves
|
|
|
|
/// special attention. Usually a document highlight is visualized by changing
|
|
|
|
/// the background color of its range.
|
|
|
|
|
|
|
|
struct DocumentHighlight {
|
|
|
|
/// The range this highlight applies to.
|
|
|
|
Range range;
|
|
|
|
|
|
|
|
/// The highlight kind, default is DocumentHighlightKind.Text.
|
|
|
|
DocumentHighlightKind kind = DocumentHighlightKind::Text;
|
|
|
|
|
|
|
|
friend bool operator<(const DocumentHighlight &LHS,
|
|
|
|
const DocumentHighlight &RHS) {
|
|
|
|
int LHSKind = static_cast<int>(LHS.kind);
|
|
|
|
int RHSKind = static_cast<int>(RHS.kind);
|
|
|
|
return std::tie(LHS.range, LHSKind) < std::tie(RHS.range, RHSKind);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator==(const DocumentHighlight &LHS,
|
|
|
|
const DocumentHighlight &RHS) {
|
|
|
|
return LHS.kind == RHS.kind && LHS.range == RHS.range;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
json::Expr toJSON(const DocumentHighlight &DH);
|
[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
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DocumentHighlight &);
|
[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
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
|
|
|
|
[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
|
|
|
namespace llvm {
|
|
|
|
template <> struct format_provider<clang::clangd::Position> {
|
|
|
|
static void format(const clang::clangd::Position &Pos, raw_ostream &OS,
|
|
|
|
StringRef Style) {
|
|
|
|
assert(Style.empty() && "style modifiers for this type are not supported");
|
|
|
|
OS << Pos;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace llvm
|
|
|
|
|
2017-02-07 18:28:20 +08:00
|
|
|
#endif
|