mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 06:54:44 +01:00
Allow LSP test_file to autofill didOpen params from previous splits (#5078)
Currently file tests for LSP must provide carbon source code as an
escaped string within notify params, i.e.
```
[[@LSP-NOTIFY:textDocument/didOpen:
"textDocument": {
"uri": "file:/class.carbon",
"languageId": "carbon",
"text": "class A {\n fn F();\n fn G() {}\n}\n"
}
]]
```
This works fine for simple, single line files but gets annoying when
working with more complicated files which are necessary when testing
more complicated features e.g. goto-definition
```
--- class.carbon
class A {
fn F();
fn G() {}
}
--- STDIN
[[@LSP-NOTIFY:textDocument/didOpen:
"textDocument": {
"uri": "file:/class.carbon",
"languageId": "carbon",
"text": "AUTOFILL"
}
]]
```
This PR extends file_test_base to be able to parse the notify/call
params and inject files from the test_file's splits into the JSON input.
I purposely avoid using the clangd types and manually parse the
llvm::json::Value here to avoid introducing a depdendency on clangd to
the generic file_test_base, but happy to change if we think that is
fine. Also happy to accept other suggestions on alternative methods to
achieve same result.
---------
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
59003a5d4c
commit
c302d0bc7a
+38
@@ -0,0 +1,38 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //testing/file_test:file_test_base_test --test_arg=--file_tests=testing/file_test/testdata/lsp_autofill.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //testing/file_test:file_test_base_test -- --dump_output --file_tests=testing/file_test/testdata/lsp_autofill.carbon
|
||||
|
||||
// --- foo.carbon
|
||||
class Foo {
|
||||
fn foo();
|
||||
fn bar() {}
|
||||
}
|
||||
|
||||
// --- STDIN
|
||||
[[@LSP-NOTIFY:textDocument/didOpen:
|
||||
"textDocument": {
|
||||
"uri": "file:/foo.carbon",
|
||||
"languageId": "carbon",
|
||||
"text": "FROM_FILE_SPLIT"
|
||||
}
|
||||
]]
|
||||
|
||||
// --- AUTOUPDATE-SPLIT
|
||||
|
||||
// CHECK:STDERR: --- STDIN:
|
||||
// CHECK:STDERR: Content-Length: 182
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"carbon","text":"class Foo {\n fn foo();\n fn bar() {}\n}\n\n","uri":"file:/foo.carbon"}}}
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDOUT: 2 args: `default_args`, `foo.carbon`
|
||||
// CHECK:STDOUT: foo.carbon:1: class Foo {
|
||||
// CHECK:STDOUT: foo.carbon:2: fn foo();
|
||||
// CHECK:STDOUT: foo.carbon:3: fn bar() {}
|
||||
// CHECK:STDOUT: foo.carbon:4: }
|
||||
+23
-28
@@ -11,62 +11,57 @@
|
||||
// --- STDIN
|
||||
[[@LSP:foo:]]
|
||||
[[@LSP:foo]]
|
||||
[[@LSP:bar:content]]
|
||||
[[@LSP:bar:"content": 0]]
|
||||
[[@LSP:baz:
|
||||
multi
|
||||
line
|
||||
"multi": 0,
|
||||
"line": 1
|
||||
]]
|
||||
[[@LSP-CALL:bar:content]]
|
||||
[[@LSP-CALL:bar:"content": 0]]
|
||||
[[@LSP-CALL:baz:
|
||||
multi
|
||||
line]]
|
||||
"multi": 0,
|
||||
"line": 1]]
|
||||
[[@LSP-REPLY:7]]
|
||||
[[@LSP-REPLY:8:bar]]
|
||||
[[@LSP-REPLY:8:"bar": 0]]
|
||||
[[@LSP-NOTIFY:exit]]
|
||||
|
||||
// --- AUTOUPDATE-SPLIT
|
||||
|
||||
// CHECK:STDERR: --- STDIN:
|
||||
// CHECK:STDERR: Content-Length: 37
|
||||
// CHECK:STDERR: Content-Length: 34
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: {"jsonrpc": "2.0", "method": "foo"}
|
||||
// CHECK:STDERR: {"jsonrpc":"2.0","method":"foo"}
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: Content-Length: 37
|
||||
// CHECK:STDERR: Content-Length: 34
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: {"jsonrpc": "2.0", "method": "foo"}
|
||||
// CHECK:STDERR: {"jsonrpc":"2.0","method":"foo"}
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: Content-Length: 46
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: {"jsonrpc": "2.0", "method": "bar", content}
|
||||
// CHECK:STDERR: {"jsonrpc":"2.0","method":"bar","content":0}
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: Content-Length: 50
|
||||
// CHECK:STDERR: Content-Length: 53
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: {"jsonrpc": "2.0", "method": "baz",
|
||||
// CHECK:STDERR: multi
|
||||
// CHECK:STDERR: line
|
||||
// CHECK:STDERR: }
|
||||
// CHECK:STDERR: {"jsonrpc":"2.0","method":"baz","multi":0,"line":1}
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: Content-Length: 67
|
||||
// CHECK:STDERR: Content-Length: 64
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: {"jsonrpc": "2.0", "method": "bar", "id": 1, "params": {content}}
|
||||
// CHECK:STDERR: {"jsonrpc":"2.0","method":"bar","id":1,"params":{"content":0}}
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: Content-Length: 71
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: {"jsonrpc": "2.0", "method": "baz", "id": 2, "params": {
|
||||
// CHECK:STDERR: multi
|
||||
// CHECK:STDERR: line}}
|
||||
// CHECK:STDERR: {"jsonrpc":"2.0","method":"baz","id":2,"params":{"line":1,"multi":0}}
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: Content-Length: 31
|
||||
// CHECK:STDERR: Content-Length: 28
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: {"jsonrpc": "2.0", "id": "7"}
|
||||
// CHECK:STDERR: {"jsonrpc":"2.0","id":"7"}
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: Content-Length: 48
|
||||
// CHECK:STDERR: Content-Length: 47
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: {"jsonrpc": "2.0", "id": "8", "result": {bar}}
|
||||
// CHECK:STDERR: {"jsonrpc":"2.0","id":"8","result":{"bar":0}}
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: Content-Length: 38
|
||||
// CHECK:STDERR: Content-Length: 35
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR: {"jsonrpc": "2.0", "method": "exit"}
|
||||
// CHECK:STDERR: {"jsonrpc":"2.0","method":"exit"}
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDERR:
|
||||
// CHECK:STDOUT: 1 args: `default_args`
|
||||
|
||||
Reference in New Issue
Block a user