diff --git a/src/main.zig b/src/main.zig index d0be6df..a3b9931 100644 --- a/src/main.zig +++ b/src/main.zig @@ -968,3 +968,22 @@ pub fn shorten_path(buf: []u8, path: []const u8, removed_prefix: *usize, max_len @memcpy(buf[ellipsis.len .. max_len + ellipsis.len], path[prefix..]); return buf[0 .. max_len + ellipsis.len]; } + +pub fn abbreviate_home(buf: []u8, path: []const u8) []const u8 { + const a = std.heap.c_allocator; + if (builtin.os.tag == .windows) return path; + if (!std.fs.path.isAbsolute(path)) return path; + const homedir = std.posix.getenv("HOME") orelse return path; + const homerelpath = std.fs.path.relative(a, homedir, path) catch return path; + defer a.free(homerelpath); + if (homerelpath.len == 0) { + return "~"; + } else if (homerelpath.len > 3 and std.mem.eql(u8, homerelpath[0..3], "../")) { + return path; + } else { + buf[0] = '~'; + buf[1] = '/'; + @memcpy(buf[2 .. homerelpath.len + 2], homerelpath); + return buf[0 .. homerelpath.len + 2]; + } +} diff --git a/src/project_manager.zig b/src/project_manager.zig index a9c5466..b7937db 100644 --- a/src/project_manager.zig +++ b/src/project_manager.zig @@ -413,8 +413,6 @@ const Process = struct { return; } else if (try cbor.match(m.buf, .{ "exit", "error.FileNotFound", tp.more })) { return; - } else if (try cbor.match(m.buf, .{ "exit", "error.LspFailed", tp.more })) { - return; } else { self.logger.err("receive", tp.unexpected(m)); } @@ -480,9 +478,7 @@ const Process = struct { fn request_path_files(self: *Process, from: tp.pid_ref, project_directory: []const u8, max: usize, path: []const u8) (ProjectError || SpawnError || std.fs.Dir.OpenError)!void { const project = self.projects.get(project_directory) orelse return error.NoProject; - var buf = std.ArrayList(u8).init(self.allocator); - defer buf.deinit(); - try request_path_files_async(self.allocator, from, project, max, expand_home(&buf, path)); + try request_path_files_async(self.allocator, from, project, max, path); } fn request_tasks(self: *Process, from: tp.pid_ref, project_directory: []const u8) (ProjectError || Project.ClientError)!void { @@ -813,34 +809,3 @@ pub fn normalize_file_path(file_path: []const u8) []const u8 { return file_path[project.len + 1 ..]; return file_path; } - -pub fn abbreviate_home(buf: []u8, path: []const u8) []const u8 { - const a = std.heap.c_allocator; - if (builtin.os.tag == .windows) return path; - if (!std.fs.path.isAbsolute(path)) return path; - const homedir = std.posix.getenv("HOME") orelse return path; - const homerelpath = std.fs.path.relative(a, homedir, path) catch return path; - defer a.free(homerelpath); - if (homerelpath.len == 0) { - return "~"; - } else if (homerelpath.len > 3 and std.mem.eql(u8, homerelpath[0..3], "../")) { - return path; - } else { - buf[0] = '~'; - buf[1] = '/'; - @memcpy(buf[2 .. homerelpath.len + 2], homerelpath); - return buf[0 .. homerelpath.len + 2]; - } -} - -pub fn expand_home(buf: *std.ArrayList(u8), file_path: []const u8) []const u8 { - if (builtin.os.tag == .windows) return file_path; - if (file_path.len > 0 and file_path[0] == '~') { - if (file_path.len > 1 and file_path[1] != std.fs.path.sep) return file_path; - const homedir = std.posix.getenv("HOME") orelse return file_path; - buf.appendSlice(homedir) catch return file_path; - buf.append(std.fs.path.sep) catch return file_path; - buf.appendSlice(file_path[2..]) catch return file_path; - return buf.items; - } else return file_path; -} diff --git a/src/renderer/vaxis/input.zig b/src/renderer/vaxis/input.zig index c8bdcf2..3d4740f 100644 --- a/src/renderer/vaxis/input.zig +++ b/src/renderer/vaxis/input.zig @@ -1,7 +1,9 @@ const vaxis = @import("vaxis"); const meta = @import("std").meta; -const unicode = @import("std").unicode; +const utf8Encode = @import("std").unicode.utf8Encode; +const utf8Decode = @import("std").unicode.utf8Decode; +const utf8ValidateSlice = @import("std").unicode.utf8ValidateSlice; const FormatOptions = @import("std").fmt.FormatOptions; pub const key = vaxis.Key; @@ -131,8 +133,8 @@ pub const KeyEvent = struct { }; var keypress_shifted: Key = keypress_shifted_; - if (text.len > 0) blk: { - keypress_shifted = tryUtf8Decode(text) catch break :blk; + if (text.len > 0 and text.len < 5 and utf8ValidateSlice(text)) blk: { + keypress_shifted = utf8Decode(text) catch break :blk; } const keypress, const mods = if (keypress_shifted == keypress_) map_key_to_unshifed_legacy(keypress_shifted, mods_) @@ -149,27 +151,8 @@ pub const KeyEvent = struct { } }; -fn tryUtf8Decode(bytes: []const u8) !u21 { - return switch (bytes.len) { - 1 => bytes[0], - 2 => blk: { - if (bytes[0] & 0b11100000 != 0b11000000) break :blk error.Utf8Encoding2Invalid; - break :blk unicode.utf8Decode2(bytes[0..2].*); - }, - 3 => blk: { - if (bytes[0] & 0b11110000 != 0b11100000) break :blk error.Utf8Encoding3Invalid; - break :blk unicode.utf8Decode3(bytes[0..3].*); - }, - 4 => blk: { - if (bytes[0] & 0b11111000 != 0b11110000) break :blk error.Utf8Encoding4Invalid; - break :blk unicode.utf8Decode4(bytes[0..4].*); - }, - else => error.Utf8CodepointLengthInvalid, - }; -} - pub fn ucs32_to_utf8(ucs32: []const u32, utf8: []u8) !usize { - return @intCast(try unicode.utf8Encode(@intCast(ucs32[0]), utf8)); + return @intCast(try utf8Encode(@intCast(ucs32[0]), utf8)); } pub const utils = struct { diff --git a/src/syntax/build.zig b/src/syntax/build.zig index 0f11e87..15cae43 100644 --- a/src/syntax/build.zig +++ b/src/syntax/build.zig @@ -53,7 +53,6 @@ pub fn build(b: *std.Build) void { ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-haskell/queries/highlights.scm"); ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-hare/queries/highlights.scm"); ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-html/queries/highlights.scm"); - ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-hurl/queries/highlights.scm"); ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-java/queries/highlights.scm"); ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-javascript/queries/highlights.scm"); ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-jsdoc/queries/highlights.scm"); @@ -108,7 +107,6 @@ pub fn build(b: *std.Build) void { ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-gitcommit/queries/injections.scm"); ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-hare/queries/injections.scm"); ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-html/queries/injections.scm"); - ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-hurl/queries/injections.scm"); ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-javascript/queries/injections.scm"); ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-kdl/queries/injections.scm"); ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-lua/queries/injections.scm"); diff --git a/src/syntax/build.zig.zon b/src/syntax/build.zig.zon index 5bedd80..47da370 100644 --- a/src/syntax/build.zig.zon +++ b/src/syntax/build.zig.zon @@ -6,8 +6,8 @@ .dependencies = .{ .tree_sitter = .{ - .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-c743c35222243cf4d0214a07671536977b0c4d48/source.tar.gz", - .hash = "N-V-__8AAB_jECdTCYsQ5_pF_9rUtyWAqA-wxLPz3evWkLpC", + .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-db95c4c19db807fa9acd6853dbd5fb7011906b7d/source.tar.gz", + .hash = "N-V-__8AAHgNBifXb56e2xqWSBTJj5bN4jAtfyP3T9GYr8Oc", }, .cbor = .{ .url = "https://github.com/neurocyte/cbor/archive/1fccb83c70cd84e1dff57cc53f7db8fb99909a94.tar.gz", diff --git a/src/syntax/src/file_types.zig b/src/syntax/src/file_types.zig index c909f20..f1e4387 100644 --- a/src/syntax/src/file_types.zig +++ b/src/syntax/src/file_types.zig @@ -42,7 +42,6 @@ pub const @"c-sharp" = .{ .extensions = .{"cs"}, .comment = "//", .language_server = .{ "omnisharp", "-lsp" }, - .formatter = .{ "csharpier", "format" }, }; pub const conf = .{ @@ -206,15 +205,6 @@ pub const superhtml = .{ .formatter = .{ "superhtml", "fmt", "--stdin-super" }, }; -pub const hurl = .{ - .description = "Hurl", - .color = 0xff0087, - .icon = "", - .extensions = .{"hurl"}, - .comment = "#", - .injections = "tree-sitter-hurl/queries/injections.scm", -}; - pub const java = .{ .description = "Java", .color = 0xEA2D2E, diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index b94e64c..ed7d1d4 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -380,10 +380,7 @@ const cmds = struct { try open_project_cwd(self, .{}); } - const f_ = project_manager.normalize_file_path(file orelse return); - var buf = std.ArrayList(u8).init(self.allocator); - defer buf.deinit(); - const f = project_manager.expand_home(&buf, f_); + const f = project_manager.normalize_file_path(file orelse return); const same_file = if (self.get_active_file_path()) |fp| std.mem.eql(u8, fp, f) else false; const have_editor_metadata = if (self.buffer_manager.get_buffer_for_file(f)) |_| true else false; diff --git a/src/tui/status/filestate.zig b/src/tui/status/filestate.zig index 6c00088..5bd7f7e 100644 --- a/src/tui/status/filestate.zig +++ b/src/tui/status/filestate.zig @@ -4,7 +4,6 @@ const tp = @import("thespian"); const tracy = @import("tracy"); const Buffer = @import("Buffer"); const root = @import("root"); -const project_manager = @import("project_manager"); const Plane = @import("renderer").Plane; const style = @import("renderer").style; @@ -178,7 +177,7 @@ fn render_terminal_title(self: *Self) void { var new_title_buf: [512]u8 = undefined; const project_path = tp.env.get().str("project"); - const project_name = project_manager.abbreviate_home(&project_name_buf, project_path); + const project_name = root.abbreviate_home(&project_name_buf, project_path); const file_name = if (std.mem.lastIndexOfScalar(u8, self.name, '/')) |pos| self.name[pos + 1 ..] else self.name; const edit_state = if (!self.file_exists) "◌ " else if (self.file_dirty) " " else ""; @@ -211,7 +210,7 @@ pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message self.name = self.name_buf[0..file_path.len]; self.file_exists = true; self.file_dirty = false; - self.name = project_manager.abbreviate_home(&self.name_buf, self.name); + self.name = root.abbreviate_home(&self.name_buf, self.name); } else if (try m.match(.{ "E", "open", tp.extract(&file_path), tp.extract(&self.file_exists), tp.extract(&file_type), tp.extract(&file_icon), tp.extract(&self.file_color) })) { self.eol_mode = .lf; @memcpy(self.name_buf[0..file_path.len], file_path); @@ -222,7 +221,7 @@ pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message self.file_icon_buf[file_icon.len] = 0; self.file_icon = self.file_icon_buf[0..file_icon.len :0]; self.file_dirty = false; - self.name = project_manager.abbreviate_home(&self.name_buf, self.name); + self.name = root.abbreviate_home(&self.name_buf, self.name); self.file = true; } else if (try m.match(.{ "E", "close" })) { self.name = ""; @@ -257,5 +256,5 @@ fn show_project(self: *Self) void { const project_name = tp.env.get().str("project"); @memcpy(self.name_buf[0..project_name.len], project_name); self.name = self.name_buf[0..project_name.len]; - self.name = project_manager.abbreviate_home(&self.name_buf, self.name); + self.name = root.abbreviate_home(&self.name_buf, self.name); }