Author: ioeric Date: Thu Feb 22 10:40:39 2018 New Revision: 325813 URL: http://llvm.org/viewvc/llvm-project?rev=325813&view=rev Log: [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 Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/clangd/Protocol.cpp clang-tools-extra/trunk/clangd/Protocol.h Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=325813&r1=325812&r2=325813&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Feb 22 10:40:39 2018 @@ -149,9 +149,13 @@ void ClangdLSPServer::onDocumentDidChang if (Params.contentChanges.size() != 1) return replyError(ErrorCode::InvalidParams, "can only apply one change at a time"); + auto WantDiags = WantDiagnostics::Auto; + if (Params.wantDiagnostics.hasValue()) + WantDiags = Params.wantDiagnostics.getValue() ? WantDiagnostics::Yes + : WantDiagnostics::No; // We only support full syncing right now. Server.addDocument(Params.textDocument.uri.file(), - Params.contentChanges[0].text, WantDiagnostics::Auto); + Params.contentChanges[0].text, WantDiags); } void ClangdLSPServer::onFileEvent(DidChangeWatchedFilesParams &Params) { Modified: clang-tools-extra/trunk/clangd/Protocol.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=325813&r1=325812&r2=325813&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Protocol.cpp (original) +++ clang-tools-extra/trunk/clangd/Protocol.cpp Thu Feb 22 10:40:39 2018 @@ -221,7 +221,8 @@ bool fromJSON(const json::Expr &Params, bool fromJSON(const json::Expr &Params, DidChangeTextDocumentParams &R) { json::ObjectMapper O(Params); return O && O.map("textDocument", R.textDocument) && - O.map("contentChanges", R.contentChanges); + O.map("contentChanges", R.contentChanges) && + O.map("wantDiagnostics", R.wantDiagnostics); } bool fromJSON(const json::Expr &E, FileChangeType &Out) { Modified: clang-tools-extra/trunk/clangd/Protocol.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=325813&r1=325812&r2=325813&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Protocol.h (original) +++ clang-tools-extra/trunk/clangd/Protocol.h Thu Feb 22 10:40:39 2018 @@ -297,6 +297,12 @@ struct DidChangeTextDocumentParams { /// The actual content changes. std::vector<TextDocumentContentChangeEvent> contentChanges; + + /// 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; }; bool fromJSON(const json::Expr &, DidChangeTextDocumentParams &); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits