Skip to content

Commit 51fed18

Browse files
author
Eric Liu
committedFeb 22, 2018
[clangd] Extend textDocument/didChange to specify whether diagnostics should be generated.
Summary: This would allow us to disable diagnostics when didChange is called but diagnostics are not wanted (e.g. code completion). Reviewers: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43634 llvm-svn: 325813
1 parent 7ef47a6 commit 51fed18

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed
 

‎clang-tools-extra/clangd/ClangdLSPServer.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,13 @@ void ClangdLSPServer::onDocumentDidChange(DidChangeTextDocumentParams &Params) {
149149
if (Params.contentChanges.size() != 1)
150150
return replyError(ErrorCode::InvalidParams,
151151
"can only apply one change at a time");
152+
auto WantDiags = WantDiagnostics::Auto;
153+
if (Params.wantDiagnostics.hasValue())
154+
WantDiags = Params.wantDiagnostics.getValue() ? WantDiagnostics::Yes
155+
: WantDiagnostics::No;
152156
// We only support full syncing right now.
153157
Server.addDocument(Params.textDocument.uri.file(),
154-
Params.contentChanges[0].text, WantDiagnostics::Auto);
158+
Params.contentChanges[0].text, WantDiags);
155159
}
156160

157161
void ClangdLSPServer::onFileEvent(DidChangeWatchedFilesParams &Params) {

‎clang-tools-extra/clangd/Protocol.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ bool fromJSON(const json::Expr &Params, DidCloseTextDocumentParams &R) {
221221
bool fromJSON(const json::Expr &Params, DidChangeTextDocumentParams &R) {
222222
json::ObjectMapper O(Params);
223223
return O && O.map("textDocument", R.textDocument) &&
224-
O.map("contentChanges", R.contentChanges);
224+
O.map("contentChanges", R.contentChanges) &&
225+
O.map("wantDiagnostics", R.wantDiagnostics);
225226
}
226227

227228
bool fromJSON(const json::Expr &E, FileChangeType &Out) {

‎clang-tools-extra/clangd/Protocol.h

+6
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ struct DidChangeTextDocumentParams {
297297

298298
/// The actual content changes.
299299
std::vector<TextDocumentContentChangeEvent> contentChanges;
300+
301+
/// Forces diagnostics to be generated, or to not be generated, for this
302+
/// version of the file. If not set, diagnostics are eventually consistent:
303+
/// either they will be provided for this version or some subsequent one.
304+
/// This is a clangd extension.
305+
llvm::Optional<bool> wantDiagnostics;
300306
};
301307
bool fromJSON(const json::Expr &, DidChangeTextDocumentParams &);
302308

0 commit comments

Comments
 (0)
Please sign in to comment.