summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2017-12-19 20:52:56 +0000
committerHaojian Wu <hokein@google.com>2017-12-19 20:52:56 +0000
commit5291528b34d2863450db23a04232be2ab5ec1f15 (patch)
tree223a226c7816f565e6650cd84036e4809d332ecc
parent03e56fe65df27ef01f553d2ffe6b67af2db41508 (diff)
[clangd] Don't use the optional "severity" when comparing Diagnostic.
Summary: We use Diagnostic as a key to find the corresponding FixIt when we do the "apply-fix", but the "severity" field could be omitted, in some cases, the codeAction request sent from LSP clients (e.g. VScode) doesn't include the `severity` field, which makes clangd fail to find the FixIt. Test the following code in VScode, before the fix, no FixIt shown. ``` void main() {} ^~~~ ``` Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41280 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@321106 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--clangd/ClangdLSPServer.h3
-rw-r--r--clangd/Protocol.h17
2 files changed, 11 insertions, 9 deletions
diff --git a/clangd/ClangdLSPServer.h b/clangd/ClangdLSPServer.h
index ed055251..ca4b5724 100644
--- a/clangd/ClangdLSPServer.h
+++ b/clangd/ClangdLSPServer.h
@@ -88,7 +88,8 @@ private:
bool IsDone = false;
std::mutex FixItsMutex;
- typedef std::map<clangd::Diagnostic, std::vector<TextEdit>>
+ typedef std::map<clangd::Diagnostic, std::vector<TextEdit>,
+ LSPDiagnosticCompare>
DiagnosticToReplacementMap;
/// Caches FixIts per file and diagnostics
llvm::StringMap<DiagnosticToReplacementMap> FixItsMap;
diff --git a/clangd/Protocol.h b/clangd/Protocol.h
index 098df13c..f2ad0db0 100644
--- a/clangd/Protocol.h
+++ b/clangd/Protocol.h
@@ -322,14 +322,15 @@ struct Diagnostic {
/// The diagnostic's message.
std::string message;
-
- friend bool operator==(const Diagnostic &LHS, const Diagnostic &RHS) {
- return std::tie(LHS.range, LHS.severity, LHS.message) ==
- std::tie(RHS.range, RHS.severity, RHS.message);
- }
- friend bool operator<(const Diagnostic &LHS, const Diagnostic &RHS) {
- return std::tie(LHS.range, LHS.severity, LHS.message) <
- std::tie(RHS.range, RHS.severity, RHS.message);
+};
+/// 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 {
+ bool operator()(const Diagnostic& LHS, const Diagnostic& RHS) const {
+ return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
}
};
bool fromJSON(const json::Expr &, Diagnostic &);