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"}} 3--- 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": [ 8# CHECK-NEXT: { 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 15# CHECK-NEXT: }, 16# CHECK-NEXT: "start": { 17# CHECK-NEXT: "character": 32, 18# CHECK-NEXT: "line": 0 19# CHECK-NEXT: } 20# CHECK-NEXT: }, 21# CHECK-NEXT: "severity": 2, 22# CHECK-NEXT: "source": "clang" 23# CHECK-NEXT: } 24# CHECK-NEXT: ], 25# CHECK-NEXT: "uri": "file://{{.*}}/foo.c", 26# CHECK-NEXT: "version": 0 27# CHECK-NEXT: } 28--- 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)"}]}}} 30# CHECK: "id": 2, 31# CHECK-NEXT: "jsonrpc": "2.0", 32# CHECK-NEXT: "result": [ 33# CHECK-NEXT: { 34# CHECK-NEXT: "arguments": [ 35# CHECK-NEXT: { 36# CHECK-NEXT: "changes": { 37# CHECK-NEXT: "file://{{.*}}/foo.c": [ 38# CHECK-NEXT: { 39# CHECK-NEXT: "newText": "(", 40# CHECK-NEXT: "range": { 41# CHECK-NEXT: "end": { 42# CHECK-NEXT: "character": 32, 43# CHECK-NEXT: "line": 0 44# CHECK-NEXT: }, 45# CHECK-NEXT: "start": { 46# CHECK-NEXT: "character": 32, 47# CHECK-NEXT: "line": 0 48# CHECK-NEXT: } 49# CHECK-NEXT: } 50# CHECK-NEXT: }, 51# CHECK-NEXT: { 52# CHECK-NEXT: "newText": ")", 53# CHECK-NEXT: "range": { 54# CHECK-NEXT: "end": { 55# CHECK-NEXT: "character": 37, 56# CHECK-NEXT: "line": 0 57# CHECK-NEXT: }, 58# CHECK-NEXT: "start": { 59# CHECK-NEXT: "character": 37, 60# CHECK-NEXT: "line": 0 61# CHECK-NEXT: } 62# CHECK-NEXT: } 63# CHECK-NEXT: } 64# CHECK-NEXT: ] 65# CHECK-NEXT: } 66# CHECK-NEXT: } 67# CHECK-NEXT: ], 68# CHECK-NEXT: "command": "clangd.applyFix", 69# CHECK-NEXT: "title": "Apply fix: place parentheses around the assignment to silence this warning" 70# CHECK-NEXT: }, 71# CHECK-NEXT: { 72# CHECK-NEXT: "arguments": [ 73# CHECK-NEXT: { 74# CHECK-NEXT: "changes": { 75# CHECK-NEXT: "file://{{.*}}/foo.c": [ 76# CHECK-NEXT: { 77# CHECK-NEXT: "newText": "==", 78# CHECK-NEXT: "range": { 79# CHECK-NEXT: "end": { 80# CHECK-NEXT: "character": 35, 81# CHECK-NEXT: "line": 0 82# CHECK-NEXT: }, 83# CHECK-NEXT: "start": { 84# CHECK-NEXT: "character": 34, 85# CHECK-NEXT: "line": 0 86# CHECK-NEXT: } 87# CHECK-NEXT: } 88# CHECK-NEXT: } 89# CHECK-NEXT: ] 90# CHECK-NEXT: } 91# CHECK-NEXT: } 92# CHECK-NEXT: ], 93# CHECK-NEXT: "command": "clangd.applyFix", 94# CHECK-NEXT: "title": "Apply fix: use '==' to turn this assignment into an equality comparison" 95# CHECK-NEXT: } 96# CHECK-NEXT: ] 97--- 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 100# CHECK: "id": 3, 101# CHECK-NEXT: "jsonrpc": "2.0", 102# CHECK-NEXT: "result": [ 103# CHECK-NEXT: { 104# CHECK-NEXT: "arguments": [ 105# CHECK-NEXT: { 106# CHECK-NEXT: "changes": { 107# CHECK-NEXT: "file://{{.*}}/foo.c": [ 108# CHECK-NEXT: { 109# CHECK-NEXT: "newText": "(", 110# CHECK-NEXT: "range": { 111# CHECK-NEXT: "end": { 112# CHECK-NEXT: "character": 32, 113# CHECK-NEXT: "line": 0 114# CHECK-NEXT: }, 115# CHECK-NEXT: "start": { 116# CHECK-NEXT: "character": 32, 117# CHECK-NEXT: "line": 0 118# CHECK-NEXT: } 119# CHECK-NEXT: } 120# CHECK-NEXT: }, 121# CHECK-NEXT: { 122# CHECK-NEXT: "newText": ")", 123# CHECK-NEXT: "range": { 124# CHECK-NEXT: "end": { 125# CHECK-NEXT: "character": 37, 126# CHECK-NEXT: "line": 0 127# CHECK-NEXT: }, 128# CHECK-NEXT: "start": { 129# CHECK-NEXT: "character": 37, 130# CHECK-NEXT: "line": 0 131# CHECK-NEXT: } 132# CHECK-NEXT: } 133# CHECK-NEXT: } 134# CHECK-NEXT: ] 135# CHECK-NEXT: } 136# CHECK-NEXT: } 137# CHECK-NEXT: ], 138# CHECK-NEXT: "command": "clangd.applyFix", 139# CHECK-NEXT: "title": "Apply fix: place parentheses around the assignment to silence this warning" 140# CHECK-NEXT: }, 141# CHECK-NEXT: { 142# CHECK-NEXT: "arguments": [ 143# CHECK-NEXT: { 144# CHECK-NEXT: "changes": { 145# CHECK-NEXT: "file://{{.*}}/foo.c": [ 146# CHECK-NEXT: { 147# CHECK-NEXT: "newText": "==", 148# CHECK-NEXT: "range": { 149# CHECK-NEXT: "end": { 150# CHECK-NEXT: "character": 35, 151# CHECK-NEXT: "line": 0 152# CHECK-NEXT: }, 153# CHECK-NEXT: "start": { 154# CHECK-NEXT: "character": 34, 155# CHECK-NEXT: "line": 0 156# CHECK-NEXT: } 157# CHECK-NEXT: } 158# CHECK-NEXT: } 159# CHECK-NEXT: ] 160# CHECK-NEXT: } 161# CHECK-NEXT: } 162# CHECK-NEXT: ], 163# CHECK-NEXT: "command": "clangd.applyFix", 164# CHECK-NEXT: "title": "Apply fix: use '==' to turn this assignment into an equality comparison" 165# CHECK-NEXT: } 166# CHECK-NEXT: ] 167--- 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":")"}]}}]}} 169# CHECK: "id": 0, 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": [ 176# CHECK-NEXT: { 177# CHECK-NEXT: "newText": "(", 178# CHECK-NEXT: "range": { 179# CHECK-NEXT: "end": { 180# CHECK-NEXT: "character": 32, 181# CHECK-NEXT: "line": 0 182# CHECK-NEXT: }, 183# CHECK-NEXT: "start": { 184# CHECK-NEXT: "character": 32, 185# CHECK-NEXT: "line": 0 186# CHECK-NEXT: } 187# CHECK-NEXT: } 188# CHECK-NEXT: }, 189# CHECK-NEXT: { 190# CHECK-NEXT: "newText": ")", 191# CHECK-NEXT: "range": { 192# CHECK-NEXT: "end": { 193# CHECK-NEXT: "character": 37, 194# CHECK-NEXT: "line": 0 195# CHECK-NEXT: }, 196# CHECK-NEXT: "start": { 197# CHECK-NEXT: "character": 37, 198# CHECK-NEXT: "line": 0 199# CHECK-NEXT: } 200# CHECK-NEXT: } 201# CHECK-NEXT: } 202# CHECK-NEXT: ] 203# CHECK-NEXT: } 204# CHECK-NEXT: } 205# CHECK-NEXT: } 206--- 207{"jsonrpc":"2.0","id":0,"result":{"applied":true}} 208# CHECK: "id": 4, 209# CHECK-NEXT: "jsonrpc": "2.0", 210# CHECK-NEXT: "result": "Fix applied." 211--- 212{"jsonrpc":"2.0","id":4,"method":"shutdown"} 213--- 214{"jsonrpc":"2.0","method":"exit"} 215