Compare commits
6 commits
1be41aff8b
...
eae28536d2
| Author | SHA1 | Date | |
|---|---|---|---|
| eae28536d2 | |||
| 85f5e5ab2e | |||
| 0e3f7c8c1c | |||
| 865ec97c16 | |||
| dc0d5dda80 | |||
| 0a8a8188cd |
2 changed files with 33 additions and 33 deletions
|
|
@ -348,16 +348,27 @@ fn make_URI(self: *Self, file_path: ?[]const u8) LspError![]const u8 {
|
||||||
var buf: std.Io.Writer.Allocating = .init(self.allocator);
|
var buf: std.Io.Writer.Allocating = .init(self.allocator);
|
||||||
defer buf.deinit();
|
defer buf.deinit();
|
||||||
const writer = &buf.writer;
|
const writer = &buf.writer;
|
||||||
|
try writer.writeAll("file://");
|
||||||
if (file_path) |path| {
|
if (file_path) |path| {
|
||||||
if (std.fs.path.isAbsolute(path)) {
|
if (std.fs.path.isAbsolute(path)) {
|
||||||
try writer.print("file://{s}", .{path});
|
try write_URI_path(writer, path);
|
||||||
} else {
|
} else {
|
||||||
try writer.print("file://{s}{c}{s}", .{ self.name, std.fs.path.sep, path });
|
try write_URI_path(writer, self.name);
|
||||||
|
try writer.writeByte('/');
|
||||||
|
try write_URI_path(writer, path);
|
||||||
}
|
}
|
||||||
} else try writer.print("file://{s}", .{self.name});
|
} else try write_URI_path(writer, self.name);
|
||||||
return buf.toOwnedSlice();
|
return buf.toOwnedSlice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_URI_path(writer: *std.Io.Writer, path: []const u8) std.Io.Writer.Error!void {
|
||||||
|
for (path) |c| try switch (c) {
|
||||||
|
std.fs.path.sep => writer.writeByte('/'),
|
||||||
|
// ':' => writer.writeAll("%3A"),
|
||||||
|
else => writer.writeByte(c),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn sort_files_by_mtime(self: *Self) void {
|
fn sort_files_by_mtime(self: *Self) void {
|
||||||
sort_by_mtime(File, self.files.items);
|
sort_by_mtime(File, self.files.items);
|
||||||
}
|
}
|
||||||
|
|
@ -979,25 +990,31 @@ fn send_goto_request(self: *Self, from: tp.pid_ref, file_path: []const u8, row:
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_uri_to_path(uri: []const u8, file_path_buf: []u8) error{InvalidTargetURI}![]u8 {
|
fn file_uri_to_path(uri: []const u8, file_path_buf: []u8) error{InvalidTargetURI}![]u8 {
|
||||||
return std.Uri.percentDecodeBackwards(file_path_buf, if (std.mem.eql(u8, uri[0..7], "file://"))
|
const file_path = std.Uri.percentDecodeBackwards(file_path_buf, if (std.mem.eql(u8, uri[0..7], "file://"))
|
||||||
uri[7..]
|
uri[7..]
|
||||||
else if (std.mem.eql(u8, uri[0..5], "file:"))
|
else if (std.mem.eql(u8, uri[0..5], "file:"))
|
||||||
uri[5..]
|
uri[5..]
|
||||||
else
|
else
|
||||||
return error.InvalidTargetURI);
|
return error.InvalidTargetURI);
|
||||||
|
return convert_path(file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigate_to_location_link(from: tp.pid_ref, location_link: []const u8) (error{InvalidTargetURI} || LocationLinkError)!void {
|
fn convert_path(file_path_: []u8) []u8 {
|
||||||
const location: LocationLink = try read_locationlink(location_link);
|
var file_path = file_path_;
|
||||||
if (location.targetUri == null or location.targetRange == null) return error.InvalidLocationLink;
|
|
||||||
var file_path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
|
||||||
var file_path = try file_uri_to_path(location.targetUri.?, &file_path_buf);
|
|
||||||
if (builtin.os.tag == .windows) {
|
if (builtin.os.tag == .windows) {
|
||||||
if (file_path[0] == '/') file_path = file_path[1..];
|
if (file_path[0] == '/') file_path = file_path[1..];
|
||||||
for (file_path, 0..) |c, i| if (c == '/') {
|
for (file_path, 0..) |c, i| if (c == '/') {
|
||||||
file_path[i] = '\\';
|
file_path[i] = '\\';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
return file_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn navigate_to_location_link(from: tp.pid_ref, location_link: []const u8) (error{InvalidTargetURI} || LocationLinkError)!void {
|
||||||
|
const location: LocationLink = try read_locationlink(location_link);
|
||||||
|
if (location.targetUri == null or location.targetRange == null) return error.InvalidLocationLink;
|
||||||
|
var file_path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||||
|
const file_path = try file_uri_to_path(location.targetUri.?, &file_path_buf);
|
||||||
if (location.targetSelectionRange) |sel| {
|
if (location.targetSelectionRange) |sel| {
|
||||||
from.send(.{ "cmd", "navigate", .{
|
from.send(.{ "cmd", "navigate", .{
|
||||||
.file = file_path,
|
.file = file_path,
|
||||||
|
|
@ -1123,13 +1140,7 @@ fn send_reference(tag: []const u8, to: tp.pid_ref, location_: []const u8, name:
|
||||||
const location: LocationLink = try read_locationlink(location_);
|
const location: LocationLink = try read_locationlink(location_);
|
||||||
if (location.targetUri == null or location.targetRange == null) return error.InvalidLocationLink;
|
if (location.targetUri == null or location.targetRange == null) return error.InvalidLocationLink;
|
||||||
var file_path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
var file_path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||||
var file_path = try file_uri_to_path(location.targetUri.?, &file_path_buf);
|
const file_path = try file_uri_to_path(location.targetUri.?, &file_path_buf);
|
||||||
if (builtin.os.tag == .windows) {
|
|
||||||
if (file_path[0] == '/') file_path = file_path[1..];
|
|
||||||
for (file_path, 0..) |c, i| if (c == '/') {
|
|
||||||
file_path[i] = '\\';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const line = try get_line_of_file(allocator, file_path, location.targetRange.?.start.line);
|
const line = try get_line_of_file(allocator, file_path, location.targetRange.?.start.line);
|
||||||
defer allocator.free(line);
|
defer allocator.free(line);
|
||||||
const file_path_ = if (file_path.len > name.len and std.mem.eql(u8, name, file_path[0..name.len]))
|
const file_path_ = if (file_path.len > name.len and std.mem.eql(u8, name, file_path[0..name.len]))
|
||||||
|
|
@ -1396,13 +1407,7 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const
|
||||||
if (location) |location_| {
|
if (location) |location_| {
|
||||||
if (location_.targetUri == null or location_.targetRange == null) return error.InvalidSymbolInformationField;
|
if (location_.targetUri == null or location_.targetRange == null) return error.InvalidSymbolInformationField;
|
||||||
var file_path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
var file_path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||||
var file_path_ = try file_uri_to_path(location_.targetUri.?, &file_path_buf);
|
const file_path_ = try file_uri_to_path(location_.targetUri.?, &file_path_buf);
|
||||||
if (builtin.os.tag == .windows) {
|
|
||||||
if (file_path_[0] == '/') file_path_ = file_path_[1..];
|
|
||||||
for (file_path_, 0..) |c, i| if (c == '/') {
|
|
||||||
file_path_[i] = '\\';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
fp = file_path_;
|
fp = file_path_;
|
||||||
to.send(.{ "cmd", "add_symbol_information", .{ fp, name, parent_name, kind, location_.targetRange.?.start.line, location_.targetRange.?.start.character, location_.targetRange.?.end.line, location_.targetRange.?.end.character, tags[0..len_tags_], location_.targetSelectionRange.?.start.line, location_.targetSelectionRange.?.start.character, location_.targetSelectionRange.?.end.line, location_.targetSelectionRange.?.end.character, deprecated, location_.targetUri } }) catch |e| {
|
to.send(.{ "cmd", "add_symbol_information", .{ fp, name, parent_name, kind, location_.targetRange.?.start.line, location_.targetRange.?.start.character, location_.targetRange.?.end.line, location_.targetRange.?.end.character, tags[0..len_tags_], location_.targetSelectionRange.?.start.line, location_.targetSelectionRange.?.start.character, location_.targetSelectionRange.?.end.line, location_.targetSelectionRange.?.end.character, deprecated, location_.targetUri } }) catch |e| {
|
||||||
std.log.err("send add_symbol_information failed: {t}", .{e});
|
std.log.err("send add_symbol_information failed: {t}", .{e});
|
||||||
|
|
@ -1611,13 +1616,7 @@ pub fn rename_symbol(self: *Self, from: tp.pid_ref, file_path: []const u8, row:
|
||||||
try cbor.writeArrayHeader(w, renames.items.len);
|
try cbor.writeArrayHeader(w, renames.items.len);
|
||||||
for (renames.items) |rename| {
|
for (renames.items) |rename| {
|
||||||
var file_path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
var file_path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||||
var file_path_ = try file_uri_to_path(rename.uri, &file_path_buf);
|
const file_path_ = try file_uri_to_path(rename.uri, &file_path_buf);
|
||||||
if (builtin.os.tag == .windows) {
|
|
||||||
if (file_path_[0] == '/') file_path_ = file_path_[1..];
|
|
||||||
for (file_path_, 0..) |c, i| if (c == '/') {
|
|
||||||
file_path_[i] = '\\';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const line = try get_line_of_file(allocator, self_.file_path, rename.range.start.line);
|
const line = try get_line_of_file(allocator, self_.file_path, rename.range.start.line);
|
||||||
try cbor.writeValue(w, .{
|
try cbor.writeValue(w, .{
|
||||||
file_path_,
|
file_path_,
|
||||||
|
|
@ -2634,7 +2633,7 @@ pub fn process_git(self: *Self, parent: tp.pid_ref, m: tp.message) (OutOfMemoryE
|
||||||
try self.loaded(parent);
|
try self.loaded(parent);
|
||||||
} else if (try m.match(.{ tp.any, tp.any, "workspace_path", tp.extract(&value) })) {
|
} else if (try m.match(.{ tp.any, tp.any, "workspace_path", tp.extract(&value) })) {
|
||||||
if (self.workspace) |p| self.allocator.free(p);
|
if (self.workspace) |p| self.allocator.free(p);
|
||||||
self.workspace = try self.allocator.dupe(u8, value);
|
self.workspace = convert_path(try self.allocator.dupe(u8, value));
|
||||||
self.state.workspace_path = .done;
|
self.state.workspace_path = .done;
|
||||||
self.state.workspace_files = .running;
|
self.state.workspace_files = .running;
|
||||||
git.workspace_files(@intFromPtr(self)) catch {
|
git.workspace_files(@intFromPtr(self)) catch {
|
||||||
|
|
@ -2665,7 +2664,7 @@ pub fn process_git(self: *Self, parent: tp.pid_ref, m: tp.message) (OutOfMemoryE
|
||||||
};
|
};
|
||||||
const file_type: []const u8, const file_icon: []const u8, const file_color: u24 = guess_file_type(path);
|
const file_type: []const u8, const file_icon: []const u8, const file_color: u24 = guess_file_type(path);
|
||||||
(try self.pending.addOne(self.allocator)).* = .{
|
(try self.pending.addOne(self.allocator)).* = .{
|
||||||
.path = try self.allocator.dupe(u8, path),
|
.path = convert_path(try self.allocator.dupe(u8, path)),
|
||||||
.type = file_type,
|
.type = file_type,
|
||||||
.icon = file_icon,
|
.icon = file_icon,
|
||||||
.color = file_color,
|
.color = file_color,
|
||||||
|
|
@ -2681,7 +2680,7 @@ pub fn process_git(self: *Self, parent: tp.pid_ref, m: tp.message) (OutOfMemoryE
|
||||||
self.longest_new_or_modified_file_path = @max(self.longest_new_or_modified_file_path, path.len);
|
self.longest_new_or_modified_file_path = @max(self.longest_new_or_modified_file_path, path.len);
|
||||||
const file_type: []const u8, const file_icon: []const u8, const file_color: u24 = guess_file_type(path);
|
const file_type: []const u8, const file_icon: []const u8, const file_color: u24 = guess_file_type(path);
|
||||||
(try self.new_or_modified_files.addOne(self.allocator)).* = .{
|
(try self.new_or_modified_files.addOne(self.allocator)).* = .{
|
||||||
.path = try self.allocator.dupe(u8, path),
|
.path = convert_path(try self.allocator.dupe(u8, path)),
|
||||||
.type = file_type,
|
.type = file_type,
|
||||||
.icon = file_icon,
|
.icon = file_icon,
|
||||||
.color = file_color,
|
.color = file_color,
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@ pub fn start(a_: std.mem.Allocator, root_path_: []const u8, entry_handler: Entry
|
||||||
}
|
}
|
||||||
|
|
||||||
const filtered_dirs = [_][]const u8{
|
const filtered_dirs = [_][]const u8{
|
||||||
|
"AppData",
|
||||||
".cache",
|
".cache",
|
||||||
".cargo",
|
".cargo",
|
||||||
".git",
|
".git",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue