summaryrefslogtreecommitdiff
path: root/src/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lsp')
-rw-r--r--src/lsp/lsp.zig15
-rw-r--r--src/lsp/lsp_client.zig8
2 files changed, 23 insertions, 0 deletions
diff --git a/src/lsp/lsp.zig b/src/lsp/lsp.zig
index 33e95570..8dc4da4f 100644
--- a/src/lsp/lsp.zig
+++ b/src/lsp/lsp.zig
@@ -31,11 +31,26 @@ pub const Req = struct {
offset: u32,
arg: []const u8 = "",
root: []const u8 = "",
+ /// The other files open in the editor, for a query whose answer can
+ /// reach them (a rename, references): the server is told of each first,
+ /// or it answers from what it has seen and misses the rest.
+ others: []const Doc = &.{},
/// For `explain`: the query it narrates, read from `arg` (`<kind>
/// <arg>`) by `explaining`; a definition when none was asked before.
explains: Kind = .definition,
};
+pub const Doc = struct { path: []const u8, source: [:0]const u8 };
+
+/// Whether a query's answer can name places in other files, so every open
+/// file of the server's language is synced before it is asked.
+pub fn reachesOtherFiles(kind: Kind) bool {
+ return switch (kind) {
+ .rename, .references, .implementation, .workspace_symbols, .incoming_calls, .outgoing_calls, .supertypes, .subtypes => true,
+ else => false,
+ };
+}
+
/// An `explain` request made the one it narrates: `explains` and `arg` set
/// from its `<kind> <arg>`; any other request as it is.
pub fn explaining(req: Req) Req {
diff --git a/src/lsp/lsp_client.zig b/src/lsp/lsp_client.zig
index 0c5e3b7e..b57b348e 100644
--- a/src/lsp/lsp_client.zig
+++ b/src/lsp/lsp_client.zig
@@ -501,6 +501,14 @@ fn run(c: *Conn, si: usize, arena: std.mem.Allocator, req: lsp.Req, out: *std.Io
var uri: std.ArrayList(u8) = .empty;
try uriOf(&uri, arena, req.path);
try syncDoc(c, si, arena, uri.items, req.source);
+ // Every other open file this server answers for, before a query whose
+ // answer reaches them: zls renames only in the documents it has.
+ for (req.others) |doc| if (specFor(doc.path) == si and !std.mem.eql(u8, doc.path, req.path)) {
+ var other: std.ArrayList(u8) = .empty;
+ try uriOf(&other, arena, doc.path);
+ try syncDoc(c, si, arena, other.items, doc.source);
+ tr.note("synced {s} first", .{std.fs.path.basename(doc.path)});
+ };
const pos = posOf(req.source, req.offset, c.caps.enc);
var cx: Cx = .{ .arena = arena, .base = req.root, .cur_path = req.path, .cur_src = req.source, .out = out };