Merge branch 'master' into zig-0.15.0
This commit is contained in:
		
						commit
						eece7202b1
					
				
					 8 changed files with 82 additions and 33 deletions
				
			
		
							
								
								
									
										19
									
								
								src/main.zig
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								src/main.zig
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -968,22 +968,3 @@ 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];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -413,6 +413,8 @@ 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));
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -478,7 +480,9 @@ 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;
 | 
			
		||||
        try request_path_files_async(self.allocator, from, project, max, path);
 | 
			
		||||
        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));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn request_tasks(self: *Process, from: tp.pid_ref, project_directory: []const u8) (ProjectError || Project.ClientError)!void {
 | 
			
		||||
| 
						 | 
				
			
			@ -809,3 +813,34 @@ 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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,7 @@
 | 
			
		|||
const vaxis = @import("vaxis");
 | 
			
		||||
 | 
			
		||||
const meta = @import("std").meta;
 | 
			
		||||
const utf8Encode = @import("std").unicode.utf8Encode;
 | 
			
		||||
const utf8Decode = @import("std").unicode.utf8Decode;
 | 
			
		||||
const utf8ValidateSlice = @import("std").unicode.utf8ValidateSlice;
 | 
			
		||||
const unicode = @import("std").unicode;
 | 
			
		||||
const FormatOptions = @import("std").fmt.FormatOptions;
 | 
			
		||||
 | 
			
		||||
pub const key = vaxis.Key;
 | 
			
		||||
| 
						 | 
				
			
			@ -133,8 +131,8 @@ pub const KeyEvent = struct {
 | 
			
		|||
        };
 | 
			
		||||
 | 
			
		||||
        var keypress_shifted: Key = keypress_shifted_;
 | 
			
		||||
        if (text.len > 0 and text.len < 5 and utf8ValidateSlice(text)) blk: {
 | 
			
		||||
            keypress_shifted = utf8Decode(text) catch break :blk;
 | 
			
		||||
        if (text.len > 0) blk: {
 | 
			
		||||
            keypress_shifted = tryUtf8Decode(text) catch break :blk;
 | 
			
		||||
        }
 | 
			
		||||
        const keypress, const mods = if (keypress_shifted == keypress_)
 | 
			
		||||
            map_key_to_unshifed_legacy(keypress_shifted, mods_)
 | 
			
		||||
| 
						 | 
				
			
			@ -151,8 +149,27 @@ 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 utf8Encode(@intCast(ucs32[0]), utf8));
 | 
			
		||||
    return @intCast(try unicode.utf8Encode(@intCast(ucs32[0]), utf8));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub const utils = struct {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -53,6 +53,7 @@ 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");
 | 
			
		||||
| 
						 | 
				
			
			@ -107,6 +108,7 @@ 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");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,8 +6,8 @@
 | 
			
		|||
 | 
			
		||||
    .dependencies = .{
 | 
			
		||||
        .tree_sitter = .{
 | 
			
		||||
            .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-db95c4c19db807fa9acd6853dbd5fb7011906b7d/source.tar.gz",
 | 
			
		||||
            .hash = "N-V-__8AAHgNBifXb56e2xqWSBTJj5bN4jAtfyP3T9GYr8Oc",
 | 
			
		||||
            .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-c743c35222243cf4d0214a07671536977b0c4d48/source.tar.gz",
 | 
			
		||||
            .hash = "N-V-__8AAB_jECdTCYsQ5_pF_9rUtyWAqA-wxLPz3evWkLpC",
 | 
			
		||||
        },
 | 
			
		||||
        .cbor = .{
 | 
			
		||||
            .url = "https://github.com/neurocyte/cbor/archive/1fccb83c70cd84e1dff57cc53f7db8fb99909a94.tar.gz",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,6 +42,7 @@ pub const @"c-sharp" = .{
 | 
			
		|||
    .extensions = .{"cs"},
 | 
			
		||||
    .comment = "//",
 | 
			
		||||
    .language_server = .{ "omnisharp", "-lsp" },
 | 
			
		||||
    .formatter = .{ "csharpier", "format" },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
pub const conf = .{
 | 
			
		||||
| 
						 | 
				
			
			@ -205,6 +206,15 @@ 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,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -380,7 +380,10 @@ const cmds = struct {
 | 
			
		|||
            try open_project_cwd(self, .{});
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const f = project_manager.normalize_file_path(file orelse return);
 | 
			
		||||
        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 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;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@ 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;
 | 
			
		||||
| 
						 | 
				
			
			@ -177,7 +178,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 = root.abbreviate_home(&project_name_buf, project_path);
 | 
			
		||||
    const project_name = project_manager.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 "";
 | 
			
		||||
| 
						 | 
				
			
			@ -210,7 +211,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 = root.abbreviate_home(&self.name_buf, self.name);
 | 
			
		||||
        self.name = project_manager.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);
 | 
			
		||||
| 
						 | 
				
			
			@ -221,7 +222,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 = root.abbreviate_home(&self.name_buf, self.name);
 | 
			
		||||
        self.name = project_manager.abbreviate_home(&self.name_buf, self.name);
 | 
			
		||||
        self.file = true;
 | 
			
		||||
    } else if (try m.match(.{ "E", "close" })) {
 | 
			
		||||
        self.name = "";
 | 
			
		||||
| 
						 | 
				
			
			@ -256,5 +257,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 = root.abbreviate_home(&self.name_buf, self.name);
 | 
			
		||||
    self.name = project_manager.abbreviate_home(&self.name_buf, self.name);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue