This revision was automatically updated to reflect the committed changes. Closed by commit rCTE321106: [clangd] Don't use the optional "severity" when comparing Diagnostic. (authored by hokein, committed by ).
Changed prior to commit: https://reviews.llvm.org/D41280?vs=127586&id=127595#toc Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D41280 Files: clangd/ClangdLSPServer.h clangd/Protocol.h Index: clangd/Protocol.h =================================================================== --- clangd/Protocol.h +++ clangd/Protocol.h @@ -322,14 +322,15 @@ /// 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 &); Index: clangd/ClangdLSPServer.h =================================================================== --- clangd/ClangdLSPServer.h +++ clangd/ClangdLSPServer.h @@ -88,7 +88,8 @@ 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;
Index: clangd/Protocol.h =================================================================== --- clangd/Protocol.h +++ clangd/Protocol.h @@ -322,14 +322,15 @@ /// 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 &); Index: clangd/ClangdLSPServer.h =================================================================== --- clangd/ClangdLSPServer.h +++ clangd/ClangdLSPServer.h @@ -88,7 +88,8 @@ 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits