refactor: prefer orelse to if(pred) |x| x else y
This commit is contained in:
parent
1caf2aa0f6
commit
c01576412a
15 changed files with 43 additions and 43 deletions
|
@ -735,7 +735,7 @@ pub fn show_message(_: *Self, _: tp.pid_ref, params_cb: []const u8) !void {
|
||||||
try cbor.skipValue(&iter);
|
try cbor.skipValue(&iter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const msg = if (message) |m| m else return;
|
const msg = message orelse return;
|
||||||
const logger = log.logger("lsp");
|
const logger = log.logger("lsp");
|
||||||
defer logger.deinit();
|
defer logger.deinit();
|
||||||
if (type_ <= 2)
|
if (type_ <= 2)
|
||||||
|
|
|
@ -115,8 +115,8 @@ pub const Branch = struct {
|
||||||
var result = WalkerMut{};
|
var result = WalkerMut{};
|
||||||
result.err = if (left.err) |_| left.err else right.err;
|
result.err = if (left.err) |_| left.err else right.err;
|
||||||
if (left.replace != null or right.replace != null) {
|
if (left.replace != null or right.replace != null) {
|
||||||
const new_left = if (left.replace) |p| p else self.left;
|
const new_left = left.replace orelse self.left;
|
||||||
const new_right = if (right.replace) |p| p else self.right;
|
const new_right = right.replace orelse self.right;
|
||||||
result.replace = if (new_left.is_empty())
|
result.replace = if (new_left.is_empty())
|
||||||
new_right
|
new_right
|
||||||
else if (new_right.is_empty())
|
else if (new_right.is_empty())
|
||||||
|
@ -693,7 +693,7 @@ const Node = union(enum) {
|
||||||
};
|
};
|
||||||
var ctx: Ctx = .{ .a = a, .col = col, .count = count };
|
var ctx: Ctx = .{ .a = a, .col = col, .count = count };
|
||||||
const found, const root = try self.walk_from_line_begin(a, line, Ctx.walker, &ctx, metrics_);
|
const found, const root = try self.walk_from_line_begin(a, line, Ctx.walker, &ctx, metrics_);
|
||||||
return if (found) (if (root) |r| r else error.Stop) else error.NotFound;
|
return if (found) (root orelse error.Stop) else error.NotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn merge_in_place(leaves: []const Node, a: Allocator) !Root {
|
fn merge_in_place(leaves: []const Node, a: Allocator) !Root {
|
||||||
|
|
|
@ -326,13 +326,13 @@ const Process = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_most_recent_file(self: *Process, from: tp.pid_ref, project_directory: []const u8) error{ OutOfMemory, Exit }!void {
|
fn request_most_recent_file(self: *Process, from: tp.pid_ref, project_directory: []const u8) error{ OutOfMemory, Exit }!void {
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
project.sort_files_by_mtime();
|
project.sort_files_by_mtime();
|
||||||
return project.request_most_recent_file(from);
|
return project.request_most_recent_file(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_recent_files(self: *Process, from: tp.pid_ref, project_directory: []const u8, max: usize) error{ OutOfMemory, Exit }!void {
|
fn request_recent_files(self: *Process, from: tp.pid_ref, project_directory: []const u8, max: usize) error{ OutOfMemory, Exit }!void {
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
project.sort_files_by_mtime();
|
project.sort_files_by_mtime();
|
||||||
return project.request_recent_files(from, max);
|
return project.request_recent_files(from, max);
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ const Process = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn query_recent_files(self: *Process, from: tp.pid_ref, project_directory: []const u8, max: usize, query: []const u8) error{ OutOfMemory, Exit }!void {
|
fn query_recent_files(self: *Process, from: tp.pid_ref, project_directory: []const u8, max: usize, query: []const u8) error{ OutOfMemory, Exit }!void {
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
const start_time = std.time.milliTimestamp();
|
const start_time = std.time.milliTimestamp();
|
||||||
const matched = try project.query_recent_files(from, max, query);
|
const matched = try project.query_recent_files(from, max, query);
|
||||||
const query_time = std.time.milliTimestamp() - start_time;
|
const query_time = std.time.milliTimestamp() - start_time;
|
||||||
|
@ -362,88 +362,88 @@ const Process = struct {
|
||||||
fn did_open(self: *Process, project_directory: []const u8, file_path: []const u8, file_type: []const u8, language_server: []const u8, version: usize, text: []const u8) !void {
|
fn did_open(self: *Process, project_directory: []const u8, file_path: []const u8, file_type: []const u8, language_server: []const u8, version: usize, text: []const u8) !void {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".did_open" });
|
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".did_open" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return project.did_open(file_path, file_type, language_server, version, text);
|
return project.did_open(file_path, file_type, language_server, version, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn did_change(self: *Process, project_directory: []const u8, file_path: []const u8, version: usize, root_dst: usize, root_src: usize) !void {
|
fn did_change(self: *Process, project_directory: []const u8, file_path: []const u8, version: usize, root_dst: usize, root_src: usize) !void {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".did_change" });
|
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".did_change" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return project.did_change(file_path, version, root_dst, root_src);
|
return project.did_change(file_path, version, root_dst, root_src);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn did_save(self: *Process, project_directory: []const u8, file_path: []const u8) !void {
|
fn did_save(self: *Process, project_directory: []const u8, file_path: []const u8) !void {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".did_save" });
|
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".did_save" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return project.did_save(file_path);
|
return project.did_save(file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn did_close(self: *Process, project_directory: []const u8, file_path: []const u8) !void {
|
fn did_close(self: *Process, project_directory: []const u8, file_path: []const u8) !void {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".did_close" });
|
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".did_close" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return project.did_close(file_path);
|
return project.did_close(file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_definition(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
fn goto_definition(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".goto_definition" });
|
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".goto_definition" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return project.goto_definition(from, file_path, row, col);
|
return project.goto_definition(from, file_path, row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_declaration(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
fn goto_declaration(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".goto_declaration" });
|
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".goto_declaration" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return project.goto_declaration(from, file_path, row, col);
|
return project.goto_declaration(from, file_path, row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_implementation(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
fn goto_implementation(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".goto_implementation" });
|
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".goto_implementation" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return project.goto_implementation(from, file_path, row, col);
|
return project.goto_implementation(from, file_path, row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_type_definition(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
fn goto_type_definition(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".goto_type_definition" });
|
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".goto_type_definition" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return project.goto_type_definition(from, file_path, row, col);
|
return project.goto_type_definition(from, file_path, row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn references(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
fn references(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".references" });
|
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".references" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return project.references(from, file_path, row, col);
|
return project.references(from, file_path, row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn completion(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
fn completion(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".completion" });
|
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".completion" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return project.completion(from, file_path, row, col);
|
return project.completion(from, file_path, row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_mru_position(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8) !void {
|
fn get_mru_position(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8) !void {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".get_mru_position" });
|
const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".get_mru_position" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return project.get_mru_position(from, file_path);
|
return project.get_mru_position(from, file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_mru(self: *Process, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
fn update_mru(self: *Process, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) !void {
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return project.update_mru(file_path, row, col);
|
return project.update_mru(file_path, row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_notify(self: *Process, project_directory: []const u8, language_server: []const u8, method: []const u8, params_cb: []const u8) !void {
|
fn dispatch_notify(self: *Process, project_directory: []const u8, language_server: []const u8, method: []const u8, params_cb: []const u8) !void {
|
||||||
_ = language_server;
|
_ = language_server;
|
||||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
const project = self.projects.get(project_directory) orelse return tp.exit("No project");
|
||||||
return if (std.mem.eql(u8, method, "textDocument/publishDiagnostics"))
|
return if (std.mem.eql(u8, method, "textDocument/publishDiagnostics"))
|
||||||
project.publish_diagnostics(self.parent.ref(), params_cb)
|
project.publish_diagnostics(self.parent.ref(), params_cb)
|
||||||
else if (std.mem.eql(u8, method, "window/showMessage"))
|
else if (std.mem.eql(u8, method, "window/showMessage"))
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub fn write(self: *Self, bytes: []const u8) !usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn input(self: *const Self, bytes: []const u8) !void {
|
pub fn input(self: *const Self, bytes: []const u8) !void {
|
||||||
const pid = if (self.pid) |pid| pid else return error.Closed;
|
const pid = self.pid orelse return error.Closed;
|
||||||
var remaining = bytes;
|
var remaining = bytes;
|
||||||
while (remaining.len > 0)
|
while (remaining.len > 0)
|
||||||
remaining = loop: {
|
remaining = loop: {
|
||||||
|
@ -131,7 +131,7 @@ const Process = struct {
|
||||||
var bytes: []u8 = "";
|
var bytes: []u8 = "";
|
||||||
|
|
||||||
if (try m.match(.{ "input", tp.extract(&bytes) })) {
|
if (try m.match(.{ "input", tp.extract(&bytes) })) {
|
||||||
const sp = if (self.sp) |sp| sp else return tp.exit_error(error.Closed, null);
|
const sp = self.sp orelse return tp.exit_error(error.Closed, null);
|
||||||
try sp.send(bytes);
|
try sp.send(bytes);
|
||||||
} else if (try m.match(.{"close"})) {
|
} else if (try m.match(.{"close"})) {
|
||||||
try self.close();
|
try self.close();
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub fn shutdown(self: *Self) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn send(self: *Self, m: tp.message) tp.result {
|
// pub fn send(self: *Self, m: tp.message) tp.result {
|
||||||
// const pid = if (self.pid) |pid| pid else return tp.exit_error(error.Shutdown);
|
// const pid = self.pid orelse return tp.exit_error(error.Shutdown);
|
||||||
// try pid.send(m);
|
// try pid.send(m);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ fn CallBack(comptime T: type) type {
|
||||||
pub fn render(self: *const Self, ctx: anytype, comptime cb: CallBack(@TypeOf(ctx)), range: ?Range) !void {
|
pub fn render(self: *const Self, ctx: anytype, comptime cb: CallBack(@TypeOf(ctx)), range: ?Range) !void {
|
||||||
const cursor = try Query.Cursor.create();
|
const cursor = try Query.Cursor.create();
|
||||||
defer cursor.destroy();
|
defer cursor.destroy();
|
||||||
const tree = if (self.tree) |p| p else return;
|
const tree = self.tree orelse return;
|
||||||
cursor.execute(self.query, tree.getRootNode());
|
cursor.execute(self.query, tree.getRootNode());
|
||||||
if (range) |r| cursor.setPointRange(r.start_point, r.end_point);
|
if (range) |r| cursor.setPointRange(r.start_point, r.end_point);
|
||||||
while (cursor.nextMatch()) |match| {
|
while (cursor.nextMatch()) |match| {
|
||||||
|
@ -127,7 +127,7 @@ pub fn render(self: *const Self, ctx: anytype, comptime cb: CallBack(@TypeOf(ctx
|
||||||
pub fn highlights_at_point(self: *const Self, ctx: anytype, comptime cb: CallBack(@TypeOf(ctx)), point: Point) void {
|
pub fn highlights_at_point(self: *const Self, ctx: anytype, comptime cb: CallBack(@TypeOf(ctx)), point: Point) void {
|
||||||
const cursor = Query.Cursor.create() catch return;
|
const cursor = Query.Cursor.create() catch return;
|
||||||
defer cursor.destroy();
|
defer cursor.destroy();
|
||||||
const tree = if (self.tree) |p| p else return;
|
const tree = self.tree orelse return;
|
||||||
cursor.execute(self.query, tree.getRootNode());
|
cursor.execute(self.query, tree.getRootNode());
|
||||||
cursor.setPointRange(.{ .row = point.row, .column = 0 }, .{ .row = point.row + 1, .column = 0 });
|
cursor.setPointRange(.{ .row = point.row, .column = 0 }, .{ .row = point.row + 1, .column = 0 });
|
||||||
while (cursor.nextMatch()) |match| {
|
while (cursor.nextMatch()) |match| {
|
||||||
|
|
|
@ -136,6 +136,6 @@ pub const List = struct {
|
||||||
if (consume)
|
if (consume)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return if (e) |e_| e_ else false;
|
return e orelse false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -356,7 +356,7 @@ pub const Editor = struct {
|
||||||
fn buf_for_update(self: *Self) !*const Buffer {
|
fn buf_for_update(self: *Self) !*const Buffer {
|
||||||
self.cursels_saved.clearAndFree();
|
self.cursels_saved.clearAndFree();
|
||||||
self.cursels_saved = try self.cursels.clone();
|
self.cursels_saved = try self.cursels.clone();
|
||||||
return if (self.buffer) |p| p else error.Stop;
|
return self.buffer orelse error.Stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn buf_root(self: *const Self) !Buffer.Root {
|
fn buf_root(self: *const Self) !Buffer.Root {
|
||||||
|
@ -379,7 +379,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_dirty(self: *Self) bool {
|
pub fn is_dirty(self: *Self) bool {
|
||||||
const b = if (self.buffer) |p| p else return false;
|
const b = self.buffer orelse return false;
|
||||||
return b.is_dirty();
|
return b.is_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,7 +437,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close_internal(self: *Self, allow_dirty_close: bool) !void {
|
fn close_internal(self: *Self, allow_dirty_close: bool) !void {
|
||||||
const b = if (self.buffer) |p| p else return error.Stop;
|
const b = self.buffer orelse return error.Stop;
|
||||||
if (!allow_dirty_close and b.is_dirty()) return tp.exit("unsaved changes");
|
if (!allow_dirty_close and b.is_dirty()) return tp.exit("unsaved changes");
|
||||||
if (self.buffer) |b_mut| b_mut.deinit();
|
if (self.buffer) |b_mut| b_mut.deinit();
|
||||||
self.buffer = null;
|
self.buffer = null;
|
||||||
|
@ -450,7 +450,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save(self: *Self) !void {
|
fn save(self: *Self) !void {
|
||||||
const b = if (self.buffer) |p| p else return error.Stop;
|
const b = self.buffer orelse return error.Stop;
|
||||||
if (!b.is_dirty()) return self.logger.print("no changes to save", .{});
|
if (!b.is_dirty()) return self.logger.print("no changes to save", .{});
|
||||||
if (self.file_path) |file_path| {
|
if (self.file_path) |file_path| {
|
||||||
if (self.buffer) |b_mut| try b_mut.store_to_file_and_clean(file_path);
|
if (self.buffer) |b_mut| try b_mut.store_to_file_and_clean(file_path);
|
||||||
|
@ -460,7 +460,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_cursor(self: *Self) !void {
|
pub fn push_cursor(self: *Self) !void {
|
||||||
const primary = if (self.cursels.getLastOrNull()) |c| c orelse CurSel{} else CurSel{};
|
const primary = self.cursels.getLastOrNull() orelse CurSel{} orelse CurSel{};
|
||||||
(try self.cursels.addOne()).* = primary;
|
(try self.cursels.addOne()).* = primary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,7 +505,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_buf(self: *Self, root: Buffer.Root) !void {
|
fn update_buf(self: *Self, root: Buffer.Root) !void {
|
||||||
const b = if (self.buffer) |p| p else return error.Stop;
|
const b = self.buffer orelse return error.Stop;
|
||||||
var sfa = std.heap.stackFallback(512, self.a);
|
var sfa = std.heap.stackFallback(512, self.a);
|
||||||
const a = sfa.get();
|
const a = sfa.get();
|
||||||
const meta = try self.store_undo_meta(a);
|
const meta = try self.store_undo_meta(a);
|
||||||
|
@ -999,7 +999,7 @@ pub const Editor = struct {
|
||||||
fn render_syntax(self: *Self, theme: *const Widget.Theme, cache: *StyleCache, root: Buffer.Root) !void {
|
fn render_syntax(self: *Self, theme: *const Widget.Theme, cache: *StyleCache, root: Buffer.Root) !void {
|
||||||
const frame = tracy.initZone(@src(), .{ .name = "editor render syntax" });
|
const frame = tracy.initZone(@src(), .{ .name = "editor render syntax" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
const syn = if (self.syntax) |syn| syn else return;
|
const syn = self.syntax orelse return;
|
||||||
const Ctx = struct {
|
const Ctx = struct {
|
||||||
self: *Self,
|
self: *Self,
|
||||||
theme: *const Widget.Theme,
|
theme: *const Widget.Theme,
|
||||||
|
@ -1275,7 +1275,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cancel_all_selections(self: *Self) void {
|
fn cancel_all_selections(self: *Self) void {
|
||||||
var primary = if (self.cursels.getLast()) |p| p else CurSel{};
|
var primary = self.cursels.getLast() orelse CurSel{};
|
||||||
primary.selection = null;
|
primary.selection = null;
|
||||||
self.cursels.clearRetainingCapacity();
|
self.cursels.clearRetainingCapacity();
|
||||||
self.cursels.addOneAssumeCapacity().* = primary;
|
self.cursels.addOneAssumeCapacity().* = primary;
|
||||||
|
@ -1490,7 +1490,7 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_selection(self: *Self, root: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root {
|
fn delete_selection(self: *Self, root: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root {
|
||||||
var sel: Selection = if (cursel.selection) |sel| sel else return error.Stop;
|
var sel: Selection = cursel.selection orelse return error.Stop;
|
||||||
sel.normalize();
|
sel.normalize();
|
||||||
cursel.cursor = sel.begin;
|
cursel.cursor = sel.begin;
|
||||||
cursel.selection = null;
|
cursel.selection = null;
|
||||||
|
|
|
@ -305,8 +305,8 @@ fn diff_update(self: *Self) !void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const editor = self.editor;
|
const editor = self.editor;
|
||||||
const new = if (editor.get_current_root()) |new| new else return;
|
const new = editor.get_current_root() orelse return;
|
||||||
const old = if (editor.buffer) |buffer| if (buffer.last_save) |old| old else return else return;
|
const old = if (editor.buffer) |buffer| buffer.last_save orelse return else return;
|
||||||
return self.diff.diff(diff_result, new, old);
|
return self.diff.diff(diff_result, new, old);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ fn clear(self: *Self) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inspect_location(self: *Self, row: usize, col: usize) void {
|
fn inspect_location(self: *Self, row: usize, col: usize) void {
|
||||||
const syn = if (self.editor.syntax) |p| p else return;
|
const syn = self.editor.syntax orelse return;
|
||||||
syn.highlights_at_point(self, dump_highlight, .{ .row = @intCast(row), .column = @intCast(col) });
|
syn.highlights_at_point(self, dump_highlight, .{ .row = @intCast(row), .column = @intCast(col) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -422,7 +422,7 @@ const cmds = struct {
|
||||||
tui_.config.gutter_line_numbers_relative = lnr;
|
tui_.config.gutter_line_numbers_relative = lnr;
|
||||||
try tui_.save_config();
|
try tui_.save_config();
|
||||||
if (self.widgets.get("editor_gutter")) |gutter_widget| {
|
if (self.widgets.get("editor_gutter")) |gutter_widget| {
|
||||||
const gutter = if (gutter_widget.dynamic_cast(@import("editor_gutter.zig"))) |p| p else return;
|
const gutter = gutter_widget.dynamic_cast(@import("editor_gutter.zig")) orelse return;
|
||||||
gutter.linenum = ln;
|
gutter.linenum = ln;
|
||||||
gutter.relative = lnr;
|
gutter.relative = lnr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ longest: usize = 0,
|
||||||
commands: Commands = undefined,
|
commands: Commands = undefined,
|
||||||
|
|
||||||
pub fn create(a: std.mem.Allocator) !tui.Mode {
|
pub fn create(a: std.mem.Allocator) !tui.Mode {
|
||||||
const mv = if (tui.current().mainview.dynamic_cast(mainview)) |mv_| mv_ else return error.NotFound;
|
const mv = tui.current().mainview.dynamic_cast(mainview) orelse return error.NotFound;
|
||||||
const self: *Self = try a.create(Self);
|
const self: *Self = try a.create(Self);
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.a = a,
|
.a = a,
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub fn Create(options: type) type {
|
||||||
pub const ButtonState = Button.State(*Menu.State(*Self));
|
pub const ButtonState = Button.State(*Menu.State(*Self));
|
||||||
|
|
||||||
pub fn create(a: std.mem.Allocator) !tui.Mode {
|
pub fn create(a: std.mem.Allocator) !tui.Mode {
|
||||||
const mv = if (tui.current().mainview.dynamic_cast(mainview)) |mv_| mv_ else return error.NotFound;
|
const mv = tui.current().mainview.dynamic_cast(mainview) orelse return error.NotFound;
|
||||||
const self: *Self = try a.create(Self);
|
const self: *Self = try a.create(Self);
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.a = a,
|
.a = a,
|
||||||
|
|
|
@ -91,7 +91,7 @@ pub fn render(self: *Self, btn: *Button.State(Self), theme: *const Widget.Theme)
|
||||||
|
|
||||||
fn render_mini_mode(plane: *Plane, theme: *const Widget.Theme) void {
|
fn render_mini_mode(plane: *Plane, theme: *const Widget.Theme) void {
|
||||||
plane.off_styles(style.italic);
|
plane.off_styles(style.italic);
|
||||||
const mini_mode = if (tui.current().mini_mode) |m| m else return;
|
const mini_mode = tui.current().mini_mode orelse return;
|
||||||
_ = plane.print(" {s}", .{mini_mode.text}) catch {};
|
_ = plane.print(" {s}", .{mini_mode.text}) catch {};
|
||||||
if (mini_mode.cursor) |cursor| {
|
if (mini_mode.cursor) |cursor| {
|
||||||
const pos: c_int = @intCast(cursor);
|
const pos: c_int = @intCast(cursor);
|
||||||
|
|
|
@ -747,7 +747,7 @@ pub const KeybindHints = std.static_string_map.StaticStringMap([]const u8);
|
||||||
threadlocal var instance_: ?*Self = null;
|
threadlocal var instance_: ?*Self = null;
|
||||||
|
|
||||||
pub fn current() *Self {
|
pub fn current() *Self {
|
||||||
return if (instance_) |p| p else @panic("tui call out of context");
|
return instance_ orelse @panic("tui call out of context");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_mode() []const u8 {
|
pub fn get_mode() []const u8 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue