diff options
Diffstat (limited to 'src/host_io.zig')
| -rw-r--r-- | src/host_io.zig | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/host_io.zig b/src/host_io.zig index f944e1cb..9e9a37ed 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -143,12 +143,19 @@ pub const Lsp = struct { source: [:0]u8, arg: []u8, root: []u8, + /// The other open files, for a query that can reach them. + others: []pardes.lsp.Doc = &.{}, pub fn free(job: *Job, gpa: std.mem.Allocator) void { gpa.free(job.path); gpa.free(job.source); gpa.free(job.arg); gpa.free(job.root); + for (job.others) |doc| { + gpa.free(doc.path); + gpa.free(doc.source); + } + gpa.free(job.others); gpa.destroy(job); } }; @@ -169,6 +176,7 @@ pub const Lsp = struct { errdefer gpa.free(arg); const declared_root = if (file) |f| std.fs.path.dirname(f.path) orelse "/" else pane.cwdSlice(); const root = try gpa.dupe(u8, filesystem.localPath(declared_root) orelse declared_root); + errdefer gpa.free(root); job.* = .{ .id = req.id, .kind = req.kind, @@ -178,6 +186,32 @@ pub const Lsp = struct { .arg = arg, .root = root, }; + // ponytail: a copy of every open file per such query; a server + // already told of one is sent nothing more (syncDoc). + if (pardes.lsp.reachesOtherFiles(req.kind)) { + var others: std.ArrayList(pardes.lsp.Doc) = .empty; + errdefer { + for (others.items) |doc| { + gpa.free(doc.path); + gpa.free(doc.source); + } + others.deinit(gpa); + } + for (core.panes, 0..) |slot, i| { + const other = slot orelse continue; + if (i == req.pane) continue; + const f = other.file orelse continue; + if (f.output != null) continue; + const local = filesystem.localPath(f.path) orelse continue; + const other_path = try gpa.dupe(u8, local); + const other_source = gpa.dupeZ(u8, f.content) catch |err| { + gpa.free(other_path); + return err; + }; + try others.append(gpa, .{ .path = other_path, .source = other_source }); + } + job.others = try others.toOwnedSlice(gpa); + } return job; } @@ -197,6 +231,7 @@ pub const Lsp = struct { .offset = job.offset, .arg = job.arg, .root = job.root, + .others = job.others, }, &out.writer) catch { deliver(ctx, job.id, null); return; |
