Author: arphaman Date: Tue Aug 14 15:21:40 2018 New Revision: 339738 URL: http://llvm.org/viewvc/llvm-project?rev=339738&view=rev Log: [clangd] add an extension field to LSP to transfer the diagnostic's category
This patch adds a 'category' extension field to the LSP diagnostic that's sent by Clangd. This extension is always on by default. Differential Revision: https://reviews.llvm.org/D50571 Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/clangd/Diagnostics.cpp clang-tools-extra/trunk/clangd/Diagnostics.h clang-tools-extra/trunk/clangd/Protocol.h clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test clang-tools-extra/trunk/test/clangd/compile-commands-path.test clang-tools-extra/trunk/test/clangd/diagnostics.test clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test clang-tools-extra/trunk/test/clangd/execute-command.test clang-tools-extra/trunk/test/clangd/extra-flags.test clang-tools-extra/trunk/test/clangd/fixits.test Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=339738&r1=339737&r2=339738&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue Aug 14 15:21:40 2018 @@ -506,6 +506,8 @@ void ClangdLSPServer::onDiagnosticsReady } LSPDiag["clangd_fixes"] = std::move(ClangdFixes); } + if (!Diag.category.empty()) + LSPDiag["category"] = Diag.category; DiagnosticsJSON.push_back(std::move(LSPDiag)); auto &FixItsForDiagnostic = LocalFixIts[Diag]; Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=339738&r1=339737&r2=339738&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original) +++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Tue Aug 14 15:21:40 2018 @@ -226,6 +226,7 @@ void toLSPDiags( clangd::Diagnostic Res; Res.range = D.Range; Res.severity = getSeverity(D.Severity); + Res.category = D.Category; return Res; }; @@ -292,6 +293,9 @@ void StoreDiags::HandleDiagnostic(Diagno D.InsideMainFile = InsideMainFile; D.File = Info.getSourceManager().getFilename(Info.getLocation()); D.Severity = DiagLevel; + D.Category = DiagnosticIDs::getCategoryNameFromID( + DiagnosticIDs::getCategoryNumberForDiag(Info.getID())) + .str(); return D; }; Modified: clang-tools-extra/trunk/clangd/Diagnostics.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.h?rev=339738&r1=339737&r2=339738&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Diagnostics.h (original) +++ clang-tools-extra/trunk/clangd/Diagnostics.h Tue Aug 14 15:21:40 2018 @@ -37,6 +37,7 @@ struct DiagBase { std::string File; clangd::Range Range; DiagnosticsEngine::Level Severity = DiagnosticsEngine::Note; + std::string Category; // Since File is only descriptive, we store a separate flag to distinguish // diags from the main file. bool InsideMainFile = false; Modified: clang-tools-extra/trunk/clangd/Protocol.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=339738&r1=339737&r2=339738&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Protocol.h (original) +++ clang-tools-extra/trunk/clangd/Protocol.h Tue Aug 14 15:21:40 2018 @@ -544,6 +544,12 @@ struct Diagnostic { /// The diagnostic's message. std::string message; + + /// The diagnostic's category. Can be omitted. + /// An LSP extension that's used to send the name of the category over to the + /// client. The category typically describes the compilation stage during + /// which the issue was produced, e.g. "Semantic Issue" or "Parse Issue". + std::string category; }; /// A LSP-specific comparator used to find diagnostic in a container like Modified: clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test?rev=339738&r1=339737&r2=339738&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test (original) +++ clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test Tue Aug 14 15:21:40 2018 @@ -23,6 +23,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { +# CHECK-NEXT: "category": "#pragma message Directive", # CHECK-NEXT: "message": "MACRO is one", --- {"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-2"}}} @@ -30,6 +31,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { +# CHECK-NEXT: "category": "#pragma message Directive", # CHECK-NEXT: "message": "MACRO is two", --- {"jsonrpc":"2.0","id":10000,"method":"shutdown"} Modified: clang-tools-extra/trunk/test/clangd/compile-commands-path.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/compile-commands-path.test?rev=339738&r1=339737&r2=339738&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/compile-commands-path.test (original) +++ clang-tools-extra/trunk/test/clangd/compile-commands-path.test Tue Aug 14 15:21:40 2018 @@ -23,6 +23,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { +# CHECK-NEXT: "category": "#pragma message Directive", # CHECK-NEXT: "message": "MACRO is not defined", --- {"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-1"}}} @@ -30,6 +31,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { +# CHECK-NEXT: "category": "#pragma message Directive", # CHECK-NEXT: "message": "MACRO is one", --- {"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-2"}}} @@ -37,6 +39,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { +# CHECK-NEXT: "category": "#pragma message Directive", # CHECK-NEXT: "message": "MACRO is two", --- {"jsonrpc":"2.0","id":10000,"method":"shutdown"} Modified: clang-tools-extra/trunk/test/clangd/diagnostics.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/diagnostics.test?rev=339738&r1=339737&r2=339738&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/diagnostics.test (original) +++ clang-tools-extra/trunk/test/clangd/diagnostics.test Tue Aug 14 15:21:40 2018 @@ -6,6 +6,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { +# CHECK-NEXT: "category": "Semantic Issue", # CHECK-NEXT: "message": "Return type of 'main' is not 'int'", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { Modified: clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test?rev=339738&r1=339737&r2=339738&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test (original) +++ clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test Tue Aug 14 15:21:40 2018 @@ -24,6 +24,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { +# CHECK-NEXT: "category": "Semantic Issue", # CHECK-NEXT: "message": "Variable 'i' is uninitialized when used here", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { Modified: clang-tools-extra/trunk/test/clangd/execute-command.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/execute-command.test?rev=339738&r1=339737&r2=339738&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/execute-command.test (original) +++ clang-tools-extra/trunk/test/clangd/execute-command.test Tue Aug 14 15:21:40 2018 @@ -6,6 +6,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { +# CHECK-NEXT: "category": "Semantic Issue", # CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { Modified: clang-tools-extra/trunk/test/clangd/extra-flags.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/extra-flags.test?rev=339738&r1=339737&r2=339738&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/extra-flags.test (original) +++ clang-tools-extra/trunk/test/clangd/extra-flags.test Tue Aug 14 15:21:40 2018 @@ -6,6 +6,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { +# CHECK-NEXT: "category": "Semantic Issue", # CHECK-NEXT: "message": "Variable 'i' is uninitialized when used here", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { @@ -28,6 +29,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { +# CHECK-NEXT: "category": "Semantic Issue", # CHECK-NEXT: "message": "Variable 'i' is uninitialized when used here", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { Modified: clang-tools-extra/trunk/test/clangd/fixits.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/fixits.test?rev=339738&r1=339737&r2=339738&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clangd/fixits.test (original) +++ clang-tools-extra/trunk/test/clangd/fixits.test Tue Aug 14 15:21:40 2018 @@ -6,6 +6,7 @@ # CHECK-NEXT: "params": { # CHECK-NEXT: "diagnostics": [ # CHECK-NEXT: { +# CHECK-NEXT: "category": "Semantic Issue", # CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses", # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits