1 # RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
2 {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
4 {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","text":"int main(int i, char **a) { if (i = 2) {}}"}}}
5 # CHECK: "method": "textDocument/publishDiagnostics",
6 # CHECK-NEXT: "params": {
7 # CHECK-NEXT: "diagnostics": [
9 # CHECK-NEXT: "code": "-Wparentheses",
10 # CHECK-NEXT: "message": "Using the result of an assignment as a condition without parentheses (fixes available)",
11 # CHECK-NEXT: "range": {
12 # CHECK-NEXT: "end": {
13 # CHECK-NEXT: "character": 37,
14 # CHECK-NEXT: "line": 0
16 # CHECK-NEXT: "start": {
17 # CHECK-NEXT: "character": 32,
18 # CHECK-NEXT: "line": 0
21 # CHECK-NEXT: "severity": 2,
22 # CHECK-NEXT: "source": "clang"
25 # CHECK-NEXT: "uri": "file://{{.*}}/foo.c",
26 # CHECK-NEXT: "version": 0
29 {"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":0,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"Using the result of an assignment as a condition without parentheses (fixes available)"}]}}}
31 # CHECK-NEXT: "jsonrpc": "2.0",
32 # CHECK-NEXT: "result": [
34 # CHECK-NEXT: "arguments": [
36 # CHECK-NEXT: "changes": {
37 # CHECK-NEXT: "file://{{.*}}/foo.c": [
39 # CHECK-NEXT: "newText": "(",
40 # CHECK-NEXT: "range": {
41 # CHECK-NEXT: "end": {
42 # CHECK-NEXT: "character": 32,
43 # CHECK-NEXT: "line": 0
45 # CHECK-NEXT: "start": {
46 # CHECK-NEXT: "character": 32,
47 # CHECK-NEXT: "line": 0
52 # CHECK-NEXT: "newText": ")",
53 # CHECK-NEXT: "range": {
54 # CHECK-NEXT: "end": {
55 # CHECK-NEXT: "character": 37,
56 # CHECK-NEXT: "line": 0
58 # CHECK-NEXT: "start": {
59 # CHECK-NEXT: "character": 37,
60 # CHECK-NEXT: "line": 0
68 # CHECK-NEXT: "command": "clangd.applyFix",
69 # CHECK-NEXT: "title": "Apply fix: place parentheses around the assignment to silence this warning"
72 # CHECK-NEXT: "arguments": [
74 # CHECK-NEXT: "changes": {
75 # CHECK-NEXT: "file://{{.*}}/foo.c": [
77 # CHECK-NEXT: "newText": "==",
78 # CHECK-NEXT: "range": {
79 # CHECK-NEXT: "end": {
80 # CHECK-NEXT: "character": 35,
81 # CHECK-NEXT: "line": 0
83 # CHECK-NEXT: "start": {
84 # CHECK-NEXT: "character": 34,
85 # CHECK-NEXT: "line": 0
93 # CHECK-NEXT: "command": "clangd.applyFix",
94 # CHECK-NEXT: "title": "Apply fix: use '==' to turn this assignment into an equality comparison"
98 {"jsonrpc":"2.0","id":3,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":0,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"Using the result of an assignment as a condition without parentheses (fixes available)"}]}}}
99 # Make sure unused "code" and "source" fields ignored gracefully
101 # CHECK-NEXT: "jsonrpc": "2.0",
102 # CHECK-NEXT: "result": [
104 # CHECK-NEXT: "arguments": [
106 # CHECK-NEXT: "changes": {
107 # CHECK-NEXT: "file://{{.*}}/foo.c": [
109 # CHECK-NEXT: "newText": "(",
110 # CHECK-NEXT: "range": {
111 # CHECK-NEXT: "end": {
112 # CHECK-NEXT: "character": 32,
113 # CHECK-NEXT: "line": 0
115 # CHECK-NEXT: "start": {
116 # CHECK-NEXT: "character": 32,
117 # CHECK-NEXT: "line": 0
122 # CHECK-NEXT: "newText": ")",
123 # CHECK-NEXT: "range": {
124 # CHECK-NEXT: "end": {
125 # CHECK-NEXT: "character": 37,
126 # CHECK-NEXT: "line": 0
128 # CHECK-NEXT: "start": {
129 # CHECK-NEXT: "character": 37,
130 # CHECK-NEXT: "line": 0
138 # CHECK-NEXT: "command": "clangd.applyFix",
139 # CHECK-NEXT: "title": "Apply fix: place parentheses around the assignment to silence this warning"
142 # CHECK-NEXT: "arguments": [
144 # CHECK-NEXT: "changes": {
145 # CHECK-NEXT: "file://{{.*}}/foo.c": [
147 # CHECK-NEXT: "newText": "==",
148 # CHECK-NEXT: "range": {
149 # CHECK-NEXT: "end": {
150 # CHECK-NEXT: "character": 35,
151 # CHECK-NEXT: "line": 0
153 # CHECK-NEXT: "start": {
154 # CHECK-NEXT: "character": 34,
155 # CHECK-NEXT: "line": 0
163 # CHECK-NEXT: "command": "clangd.applyFix",
164 # CHECK-NEXT: "title": "Apply fix: use '==' to turn this assignment into an equality comparison"
168 {"jsonrpc":"2.0","id":4,"method":"workspace/executeCommand","params":{"command":"clangd.applyFix","arguments":[{"changes":{"test:///foo.c":[{"range":{"start":{"line":0,"character":32},"end":{"line":0,"character":32}},"newText":"("},{"range":{"start":{"line":0,"character":37},"end":{"line":0,"character":37}},"newText":")"}]}}]}}
170 # CHECK-NEXT: "jsonrpc": "2.0",
171 # CHECK-NEXT: "method": "workspace/applyEdit",
172 # CHECK-NEXT: "params": {
173 # CHECK-NEXT: "edit": {
174 # CHECK-NEXT: "changes": {
175 # CHECK-NEXT: "{{.*}}/foo.c": [
177 # CHECK-NEXT: "newText": "(",
178 # CHECK-NEXT: "range": {
179 # CHECK-NEXT: "end": {
180 # CHECK-NEXT: "character": 32,
181 # CHECK-NEXT: "line": 0
183 # CHECK-NEXT: "start": {
184 # CHECK-NEXT: "character": 32,
185 # CHECK-NEXT: "line": 0
190 # CHECK-NEXT: "newText": ")",
191 # CHECK-NEXT: "range": {
192 # CHECK-NEXT: "end": {
193 # CHECK-NEXT: "character": 37,
194 # CHECK-NEXT: "line": 0
196 # CHECK-NEXT: "start": {
197 # CHECK-NEXT: "character": 37,
198 # CHECK-NEXT: "line": 0
207 {"jsonrpc":"2.0","id":0,"result":{"applied":true}}
209 # CHECK-NEXT: "jsonrpc": "2.0",
210 # CHECK-NEXT: "result": "Fix applied."
212 {"jsonrpc":"2.0","id":4,"method":"shutdown"}
214 {"jsonrpc":"2.0","method":"exit"}