diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/behaviour/language_servers.zig | 25 | ||||
| -rw-r--r-- | test/lspmock.zig | 11 |
2 files changed, 34 insertions, 2 deletions
diff --git a/test/behaviour/language_servers.zig b/test/behaviour/language_servers.zig index 904fcfba..13e42fa6 100644 --- a/test/behaviour/language_servers.zig +++ b/test/behaviour/language_servers.zig @@ -298,3 +298,28 @@ test "language-servers: Index runs the language's indexer at the project's root, const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; try std.testing.expect(std.mem.startsWith(u8, try bodyOf(&s, dir), s.at("% cd '{s}' && rust-analyzer scip .", .{dir}))); } + +test "language-servers: SPC l a lists the server's code actions in the pane's tag by their digits, the one under the cursor shown as its edit, and its digit applies it, one the server left to resolve resolved first" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var s = try Session.initLanguage(std.testing.allocator); + defer s.deinit(); + const before = "mod lib;\n\nfn main() {\n let x = add(1, 2);\n let y = add(3, 4);\n let _ = x + y;\n}\n"; + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "main.rs", .data = before }); + var buf: [4096]u8 = undefined; + const main = try s.lookFile(s.at("{s}/main.rs:4:13", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]})); + const body = s.at("/pane/{d}/body", .{main}); + try s.keys(" la"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), "+Lsp") == null); + _ = try s.where("▶ 1 mock action: extract"); + _ = try s.where(" 2 mock action: add a line"); + _ = try s.where(" 3 mock action: rename add to sum"); + // The third, its edit asked for with codeAction/resolve: the two calls. + try s.keys("\u{F800}\u{F800}"); + _ = try s.where("let x = sum(1, 2);"); + try s.expect(body, before); + try s.keys("3"); + try s.expect(body, "mod lib;\n\nfn main() {\n let x = sum(1, 2);\n let y = sum(3, 4);\n let _ = x + y;\n}\n"); + try s.keys("u"); + try s.expect(body, before); +} diff --git a/test/lspmock.zig b/test/lspmock.zig index 8b5c73a8..0fd34677 100644 --- a/test/lspmock.zig +++ b/test/lspmock.zig @@ -207,7 +207,7 @@ fn handle(a: std.mem.Allocator, raw: []const u8) void { \\"referencesProvider":true,"documentHighlightProvider":true, \\"hoverProvider":true,"documentSymbolProvider":true, \\"workspaceSymbolProvider":true,"renameProvider":true, - \\"documentFormattingProvider":true,"codeActionProvider":true, + \\"documentFormattingProvider":true,"codeActionProvider":{{"resolveProvider":true}}, \\"completionProvider":{{}}, \\"callHierarchyProvider":true,"typeHierarchyProvider":true, \\"diagnosticProvider":{{"interFileDependencies":false,"workspaceDiagnostics":false}}, @@ -283,7 +283,14 @@ fn handle(a: std.mem.Allocator, raw: []const u8) void { } else if (std.mem.eql(u8, method, "textDocument/formatting")) { reply(a, rid, "[{{\"range\":{s},\"newText\":\"// formatted by mock\\n\"}}]", .{range(a, 0, 0, 0)}); } else if (std.mem.eql(u8, method, "textDocument/codeAction")) { - reply(a, rid, "[{{\"title\":\"mock action: extract\"}}]", .{}); + // A title alone (a command's), one with its edit (a line put in + // at the top), and one whose edit is resolved when asked (its + // `data` the document's uri). + reply(a, rid, "[{{\"title\":\"mock action: extract\"}},{{\"title\":\"mock action: add a line\",\"edit\":{{\"changes\":{{\"{s}\":[{{\"range\":{s},\"newText\":\"// added by mock\\n\"}}]}}}}}},{{\"title\":\"mock action: rename add to sum\",\"data\":\"{s}\"}}]", .{ uri, range(a, 0, 0, 0), uri }); + } else if (std.mem.eql(u8, method, "codeAction/resolve")) { + // main.rs's two calls of `add` (L3, L4) renamed. + const doc = str(get(params, "data")) orelse uri; + reply(a, rid, "{{\"title\":\"mock action: rename add to sum\",\"edit\":{{\"changes\":{{\"{s}\":[{{\"range\":{s},\"newText\":\"sum\"}},{{\"range\":{s},\"newText\":\"sum\"}}]}}}}}}", .{ doc, range(a, 3, 12, 15), range(a, 4, 12, 15) }); } else if (std.mem.eql(u8, method, "textDocument/completion")) { reply(a, rid, "{{\"items\":[{{\"label\":\"alpha\",\"detail\":\"fn alpha()\"}},{{\"label\":\"beta\",\"detail\":\"fn beta()\"}}]}}", .{}); } else if (std.mem.eql(u8, method, "textDocument/diagnostic")) { |
