[clang-tools-extra] r321106 - [clangd] Don't use the optional "severity" when comparing Diagnostic.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 19 12:52:56 PST 2017
Author: hokein
Date: Tue Dec 19 12:52:56 2017
New Revision: 321106
URL: http://llvm.org/viewvc/llvm-project?rev=321106&view=rev
Log:
[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
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/Protocol.h
Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=321106&r1=321105&r2=321106&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Tue Dec 19 12:52:56 2017
@@ -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;
Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=321106&r1=321105&r2=321106&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Tue Dec 19 12:52:56 2017
@@ -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 &);
More information about the cfe-commits
mailing list