[PATCH] D51747: [clangd] Show deprecation diagnostics
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 13 06:57:30 PDT 2018
kadircet updated this revision to Diff 165275.
kadircet marked 2 inline comments as done.
kadircet added a comment.
- Convert unit tests to lit tests and address comments.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D51747
Files:
clangd/ClangdServer.cpp
test/clangd/override-no-deprecations.test
Index: test/clangd/override-no-deprecations.test
===================================================================
--- /dev/null
+++ test/clangd/override-no-deprecations.test
@@ -0,0 +1,55 @@
+# Test that we return deprecation diagnostics even when -Wno-deprecations is set.
+# And always return as warning even if -Werror is set.
+
+# RUN: rm -rf %t.dir/* && mkdir -p %t.dir
+# RUN: mkdir %t.dir/build
+# RUN: mkdir %t.dir/build-1
+# RUN: mkdir %t.dir/build-2
+# RUN: echo '[{"directory": "%/t.dir", "command": "c++ the-file.cpp", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-1", "command": "c++ -Wno-deprecated the-file.cpp", "file": "../the-file.cpp"}]' > %t.dir/build-1/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-2", "command": "c++ -Wno-deprecated -Werror the-file.cpp", "file": "../the-file.cpp"}]' > %t.dir/build-2/compile_commands.json
+
+# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
+
+# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
+# (with the extra slash in the front), so we add it here.
+# RUN: sed -e "s|file://\([A-Z]\):/|file:///\1:/|g" %t.test.1 > %t.test
+
+# RUN: clangd -lit-test < %t.test | FileCheck -strict-whitespace %t.test
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file://INPUT_DIR/the-file.cpp","languageId":"cpp","version":1,"text":"void foo() __attribute__((deprecated));\nint main() { foo(); }"}}}
+# CHECK: "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT: "params": {
+# CHECK-NEXT: "diagnostics": [
+# CHECK-NEXT: {
+# CHECK-NEXT: "message": "'foo' is deprecated\n\nthe-file.cpp:1:27: note: 'foo' has been explicitly marked deprecated here",
+---
+{"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-1"}}}
+# CHECK: "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT: "params": {
+# CHECK-NEXT: "diagnostics": [
+# CHECK-NEXT: {
+# CHECK-NEXT: "message": "'foo' is deprecated\n\nthe-file.cpp:1:27: note: 'foo' has been explicitly marked deprecated here",
+---
+{"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-2"}}}
+# CHECK: "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT: "params": {
+# CHECK-NEXT: "diagnostics": [
+# CHECK-NEXT: {
+# CHECK-NEXT: "message": "'foo' is deprecated\n\nthe-file.cpp:1:27: note: 'foo' has been explicitly marked deprecated here",
+# CHECK-NEXT: "range": {
+# CHECK-NEXT: "end": {
+# CHECK-NEXT: "character": 16,
+# CHECK-NEXT: "line": 1
+# CHECK-NEXT: },
+# CHECK-NEXT: "start": {
+# CHECK-NEXT: "character": 13,
+# CHECK-NEXT: "line": 1
+# CHECK-NEXT: }
+# CHECK-NEXT: }
+# CHECK-NEXT: "severity": 2
+---
+{"jsonrpc":"2.0","id":10000,"method":"shutdown"}
+
Index: clangd/ClangdServer.cpp
===================================================================
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -531,9 +531,15 @@
if (!C) // FIXME: Suppress diagnostics? Let the user know?
C = CDB.getFallbackCommand(File);
+ // These flags are working for both gcc and clang-cl driver modes.
// Inject the resource dir.
// FIXME: Don't overwrite it if it's already there.
C->CommandLine.push_back("-resource-dir=" + ResourceDir);
+ // Deprecations are often hidden for full-project build. They're useful in
+ // context.
+ C->CommandLine.push_back("-Wdeprecated");
+ // Adding -Wdeprecated would trigger errors in projects what set -Werror.
+ C->CommandLine.push_back("-Wno-error=deprecated");
return std::move(*C);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51747.165275.patch
Type: text/x-patch
Size: 3918 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180913/8f8a20e4/attachment-0001.bin>
More information about the cfe-commits
mailing list