diff options
Diffstat (limited to 'dev/Lsp.zig')
| -rw-r--r-- | dev/Lsp.zig | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/dev/Lsp.zig b/dev/Lsp.zig index 4b8bfa03..b799c9f6 100644 --- a/dev/Lsp.zig +++ b/dev/Lsp.zig @@ -43,6 +43,14 @@ pub const Job = struct { } }; +/// A pane's file's text, `0`-ended, owned. +fn fileSource(gpa: std.mem.Allocator, f: ?*const pardes.panes.File.State) ![:0]u8 { + const file = f orelse return gpa.dupeSentinel(u8, "", 0); + const text = try pardes.panes.File.fileText(file, gpa); + defer if (text.ptr != file.content.ptr) gpa.free(text); + return gpa.dupeSentinel(u8, text, 0); +} + // Copy before starting a worker; the editor may replace any source slice afterward. pub fn snapshot(gpa: std.mem.Allocator, core: *const pardes.Pardes, req: Request) !*Job { if (req.pane.index() >= core.panes.len) return error.NoPane; @@ -53,7 +61,9 @@ pub fn snapshot(gpa: std.mem.Allocator, core: *const pardes.Pardes, req: Request const declared_path = if (file) |f| f.path else ""; const path = try gpa.dupe(u8, filesystem.localPath(declared_path) orelse declared_path); errdefer gpa.free(path); - const source = try gpa.dupeSentinel(u8, if (file) |f| f.content else "", 0); + // The file's text (File.fileText: the `Changes` layer's lines are none + // of it), as every position sent with it is. + const source = try fileSource(gpa, if (file) |*f| f else null); errdefer gpa.free(source); const arg = try gpa.dupe(u8, req.arg); errdefer gpa.free(arg); @@ -94,7 +104,7 @@ pub fn snapshot(gpa: std.mem.Allocator, core: *const pardes.Pardes, req: Request copied += f.content.len; const local = filesystem.localPath(f.path) orelse continue; const other_path = try gpa.dupe(u8, local); - const other_source = gpa.dupeSentinel(u8, f.content, 0) catch |err| { + const other_source = fileSource(gpa, &f) catch |err| { gpa.free(other_path); return err; }; |
