Compare commits
3 commits
a288945609
...
048ef98c8d
Author | SHA1 | Date | |
---|---|---|---|
048ef98c8d | |||
7747dd3acf | |||
6ffa2a8991 |
4 changed files with 52 additions and 13 deletions
|
@ -389,7 +389,7 @@ pub const php = .{
|
||||||
.extensions = .{"php"},
|
.extensions = .{"php"},
|
||||||
.comment = "//",
|
.comment = "//",
|
||||||
.injections = "tree-sitter-php/queries/injections.scm",
|
.injections = "tree-sitter-php/queries/injections.scm",
|
||||||
.language_server = .{"intelephense", "--stdio"},
|
.language_server = .{ "intelephense", "--stdio" },
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const purescript = .{
|
pub const purescript = .{
|
||||||
|
|
|
@ -524,14 +524,26 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open(self: *Self, file_path: []const u8) !void {
|
fn open(self: *Self, file_path: []const u8) !void {
|
||||||
return self.open_buffer(file_path, try self.buffer_manager.open_file(file_path), null);
|
const buffer: *Buffer = blk: {
|
||||||
|
const frame = tracy.initZone(@src(), .{ .name = "open_file" });
|
||||||
|
defer frame.deinit();
|
||||||
|
break :blk try self.buffer_manager.open_file(file_path);
|
||||||
|
};
|
||||||
|
return self.open_buffer(file_path, buffer, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_scratch(self: *Self, file_path: []const u8, content: []const u8, file_type: ?[]const u8) !void {
|
fn open_scratch(self: *Self, file_path: []const u8, content: []const u8, file_type: ?[]const u8) !void {
|
||||||
return self.open_buffer(file_path, try self.buffer_manager.open_scratch(file_path, content), file_type);
|
const buffer: *Buffer = blk: {
|
||||||
|
const frame = tracy.initZone(@src(), .{ .name = "open_scratch" });
|
||||||
|
defer frame.deinit();
|
||||||
|
break :blk try self.buffer_manager.open_scratch(file_path, content);
|
||||||
|
};
|
||||||
|
return self.open_buffer(file_path, buffer, file_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_buffer(self: *Self, file_path: []const u8, new_buf: *Buffer, file_type_: ?[]const u8) !void {
|
fn open_buffer(self: *Self, file_path: []const u8, new_buf: *Buffer, file_type_: ?[]const u8) !void {
|
||||||
|
const frame = tracy.initZone(@src(), .{ .name = "open_buffer" });
|
||||||
|
defer frame.deinit();
|
||||||
errdefer self.buffer_manager.retire(new_buf, null);
|
errdefer self.buffer_manager.retire(new_buf, null);
|
||||||
self.cancel_all_selections();
|
self.cancel_all_selections();
|
||||||
self.get_primary().reset();
|
self.get_primary().reset();
|
||||||
|
@ -552,12 +564,33 @@ pub const Editor = struct {
|
||||||
const lang_override = file_type orelse tp.env.get().str("language");
|
const lang_override = file_type orelse tp.env.get().str("language");
|
||||||
var content = std.ArrayList(u8).init(self.allocator);
|
var content = std.ArrayList(u8).init(self.allocator);
|
||||||
defer content.deinit();
|
defer content.deinit();
|
||||||
try new_buf.root.store(content.writer(), new_buf.file_eol_mode);
|
{
|
||||||
const syn = if (lang_override.len > 0)
|
const frame_ = tracy.initZone(@src(), .{ .name = "store" });
|
||||||
syntax.create_file_type(self.allocator, lang_override) catch null
|
defer frame_.deinit();
|
||||||
else
|
try new_buf.root.store(content.writer(), new_buf.file_eol_mode);
|
||||||
syntax.create_guess_file_type(self.allocator, content.items, self.file_path) catch null;
|
}
|
||||||
if (syn) |syn_|
|
|
||||||
|
const syn_file_type = blk: {
|
||||||
|
const frame_ = tracy.initZone(@src(), .{ .name = "guess" });
|
||||||
|
defer frame_.deinit();
|
||||||
|
break :blk if (lang_override.len > 0)
|
||||||
|
syntax.FileType.get_by_name(lang_override)
|
||||||
|
else
|
||||||
|
syntax.FileType.guess(self.file_path, content.items);
|
||||||
|
};
|
||||||
|
|
||||||
|
const syn = blk: {
|
||||||
|
const frame_ = tracy.initZone(@src(), .{ .name = "create" });
|
||||||
|
defer frame_.deinit();
|
||||||
|
break :blk if (syn_file_type) |ft|
|
||||||
|
syntax.create(ft, self.allocator) catch null
|
||||||
|
else
|
||||||
|
null;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (syn) |syn_| {
|
||||||
|
const frame_ = tracy.initZone(@src(), .{ .name = "did_open" });
|
||||||
|
defer frame_.deinit();
|
||||||
project_manager.did_open(
|
project_manager.did_open(
|
||||||
file_path,
|
file_path,
|
||||||
syn_.file_type,
|
syn_.file_type,
|
||||||
|
@ -566,6 +599,7 @@ pub const Editor = struct {
|
||||||
new_buf.is_ephemeral(),
|
new_buf.is_ephemeral(),
|
||||||
) catch |e|
|
) catch |e|
|
||||||
self.logger.print("project_manager.did_open failed: {any}", .{e});
|
self.logger.print("project_manager.did_open failed: {any}", .{e});
|
||||||
|
}
|
||||||
break :syntax syn;
|
break :syntax syn;
|
||||||
};
|
};
|
||||||
self.syntax_no_render = tp.env.get().is("no-syntax");
|
self.syntax_no_render = tp.env.get().is("no-syntax");
|
||||||
|
@ -580,8 +614,11 @@ pub const Editor = struct {
|
||||||
buffer.file_type_color = ftc;
|
buffer.file_type_color = ftc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.buffer) |buffer| if (buffer.get_meta()) |meta|
|
if (self.buffer) |buffer| if (buffer.get_meta()) |meta| {
|
||||||
|
const frame_ = tracy.initZone(@src(), .{ .name = "extract_state" });
|
||||||
|
defer frame_.deinit();
|
||||||
try self.extract_state(meta, .none);
|
try self.extract_state(meta, .none);
|
||||||
|
};
|
||||||
try self.send_editor_open(file_path, new_buf.file_exists, ftn, fti, ftc);
|
try self.send_editor_open(file_path, new_buf.file_exists, ftn, fti, ftc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4187,6 +4224,8 @@ pub const Editor = struct {
|
||||||
pub const redo_meta = .{ .description = "Redo" };
|
pub const redo_meta = .{ .description = "Redo" };
|
||||||
|
|
||||||
pub fn open_buffer_from_file(self: *Self, ctx: Context) Result {
|
pub fn open_buffer_from_file(self: *Self, ctx: Context) Result {
|
||||||
|
const frame = tracy.initZone(@src(), .{ .name = "open_buffer_from_file" });
|
||||||
|
defer frame.deinit();
|
||||||
var file_path: []const u8 = undefined;
|
var file_path: []const u8 = undefined;
|
||||||
if (ctx.args.match(.{tp.extract(&file_path)}) catch false) {
|
if (ctx.args.match(.{tp.extract(&file_path)}) catch false) {
|
||||||
try self.open(file_path);
|
try self.open(file_path);
|
||||||
|
|
|
@ -572,7 +572,7 @@ const cmds = struct {
|
||||||
|
|
||||||
pub fn gutter_mode_next(self: *Self, _: Ctx) Result {
|
pub fn gutter_mode_next(self: *Self, _: Ctx) Result {
|
||||||
const config = tui.config_mut();
|
const config = tui.config_mut();
|
||||||
const mode: ?@import("config").LineNumberMode = if (config.gutter_line_numbers_mode) |mode| switch(mode) {
|
const mode: ?@import("config").LineNumberMode = if (config.gutter_line_numbers_mode) |mode| switch (mode) {
|
||||||
.absolute => .relative,
|
.absolute => .relative,
|
||||||
.relative => .none,
|
.relative => .none,
|
||||||
.none => null,
|
.none => null,
|
||||||
|
@ -1053,6 +1053,8 @@ fn replace_active_view(self: *Self, widget: Widget) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_editor(self: *Self) !void {
|
fn create_editor(self: *Self) !void {
|
||||||
|
const frame = tracy.initZone(@src(), .{ .name = "create_editor" });
|
||||||
|
defer frame.deinit();
|
||||||
try self.delete_active_view();
|
try self.delete_active_view();
|
||||||
command.executeName("enter_mode_default", .{}) catch {};
|
command.executeName("enter_mode_default", .{}) catch {};
|
||||||
var editor_widget = try ed.create(self.allocator, self.plane, &self.buffer_manager);
|
var editor_widget = try ed.create(self.allocator, self.plane, &self.buffer_manager);
|
||||||
|
|
|
@ -147,14 +147,12 @@ fn init(allocator: Allocator) !*Self {
|
||||||
self.mainview = try MainView.create(allocator);
|
self.mainview = try MainView.create(allocator);
|
||||||
resize();
|
resize();
|
||||||
self.set_terminal_style();
|
self.set_terminal_style();
|
||||||
try self.rdr.render();
|
|
||||||
try save_config();
|
try save_config();
|
||||||
try self.init_input_namespace();
|
try self.init_input_namespace();
|
||||||
if (tp.env.get().is("restore-session")) {
|
if (tp.env.get().is("restore-session")) {
|
||||||
command.executeName("restore_session", .{}) catch |e| self.logger.err("restore_session", e);
|
command.executeName("restore_session", .{}) catch |e| self.logger.err("restore_session", e);
|
||||||
self.logger.print("session restored", .{});
|
self.logger.print("session restored", .{});
|
||||||
}
|
}
|
||||||
need_render();
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue