diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/Lsp.zig | 14 | ||||
| -rw-r--r-- | dev/file_watch.zig | 6 |
2 files changed, 15 insertions, 5 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; }; diff --git a/dev/file_watch.zig b/dev/file_watch.zig index a0a500d7..d97e1d3d 100644 --- a/dev/file_watch.zig +++ b/dev/file_watch.zig @@ -471,7 +471,7 @@ pub fn reloadPane( } // The pane holds the disk's text already (a Zerox twin saved, its // other twin watching the same file): nothing reloaded, nothing said. - if (std.mem.eql(u8, file.content, bytes)) { + if (pardes.panes.File.fileEql(&file, bytes)) { if (watches[id]) |*live| if (live.serial == watched.serial) { live.generation = .{ .text = hash }; }; @@ -481,7 +481,7 @@ pub fn reloadPane( const current = core.panes[id] orelse return false; if (current.serial != watched.serial) return false; const current_file = current.file orelse return false; - if (!std.mem.eql(u8, current_file.content, bytes)) return false; + if (!pardes.panes.File.fileEql(¤t_file, bytes)) return false; if (watches[id]) |*live| { if (live.serial == watched.serial) live.generation = .{ .text = hash }; @@ -545,7 +545,7 @@ pub fn applyEffect( serial = pane.serial; if (pane.file) |file| { path = file.path; - generation = .{ .text = std.hash.Wyhash.hash(0, file.content) }; + generation = .{ .text = pardes.panes.File.fileHash(&file) }; } else if (kindPath(pane)) |kind_path| { path = kind_path; generation = .{ .kind = null }; |
