diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/Lsp.zig | 14 | ||||
| -rw-r--r-- | dev/file_watch.zig | 6 | ||||
| -rw-r--r-- | dev/gui/gui.zig | 17 |
3 files changed, 29 insertions, 8 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 }; diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 76af0ec8..2756f69b 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -809,9 +809,12 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di var want_w: c_int = 1120; var want_h: c_int = 720; var want_at: ?[2]c_int = null; - // ...or the size an Upgrade's exec says its window had (client.zig + // ...or the size an Upgrade's exec says its window had: a session's in + // its record (upgrade.zig `Record.size`), ahead of the `--geometry` it + // was started with, a client's in PARDES_JOIN_SIZE (client.zig // `execAgain`). - if (opts_in.geometry orelse if (std.c.getenv("PARDES_JOIN_SIZE")) |e| std.mem.span(e) else null) |spec| geometry: { + const kept = if (upgrade.resumed) |rec| rec.size else null; + if (kept orelse opts_in.geometry orelse if (std.c.getenv("PARDES_JOIN_SIZE")) |e| std.mem.span(e) else null) |spec| geometry: { const x_at = std.mem.indexOfScalar(u8, spec, 'x') orelse break :geometry; const plus = std.mem.indexOfAnyPos(u8, spec, x_at, "+-") orelse spec.len; want_w = std.math.clamp(std.fmt.parseInt(c_int, spec[0..x_at], 10) catch break :geometry, 200, 16384); @@ -881,7 +884,8 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di const cell_w: u32 = @intCast(@max(cw, 1)); const cell_h: u32 = @intCast(@max(chh, 1)); const tagline = taglineRaster(&atlas, px, cell_w, cell_h, config.gui_tagline_font_percent); - if (test_mode) { + // An upgraded window keeps its size in a test too. + if (test_mode and kept == null) { const cols = envU16(env, "PARDES_TEST_COLS") orelse 80; const rows = envU16(env, "PARDES_TEST_ROWS") orelse 24; // PARDES_TEST_PAD: extra pixels past the grid, as a real window has. @@ -2535,6 +2539,13 @@ const Shell = struct { // dials the session again once it is back. s.peers.refuseAll(core); var rec: upgrade.Record = .{ .link = daemon.link, .window = s.gui != null, .exe = path }; + // Its window's size now, the new one's (the user's since its start). + var size_buf: [32]u8 = undefined; + if (s.gui) |g| { + var w: c_int = 0; + var h: c_int = 0; + if (c.SDL_GetWindowSize(g.window, &w, &h)) rec.size = std.fmt.bufPrint(&size_buf, "{d}x{d}", .{ w, h }) catch null; + } s.ptys.record(&rec); var at_buf: [1024:0]u8 = undefined; const failed = upgrade.dumpInto(core, &rec, &at_buf, &why) orelse upgrade.execAs(s.gpa, path, &rec, &at_buf, s.fs, &why); |
