refactor: send file path in highlight reference messages
This commit is contained in:
parent
6a2228e19d
commit
021dfa8d4c
2 changed files with 11 additions and 7 deletions
|
|
@ -1132,8 +1132,10 @@ pub fn highlight_references(self: *Self, from: tp.pid_ref, file_path: []const u8
|
||||||
|
|
||||||
const handler: struct {
|
const handler: struct {
|
||||||
from: tp.pid,
|
from: tp.pid,
|
||||||
|
file_path: []const u8,
|
||||||
|
|
||||||
pub fn deinit(self_: *@This()) void {
|
pub fn deinit(self_: *@This()) void {
|
||||||
|
std.heap.c_allocator.free(self_.file_path);
|
||||||
self_.from.deinit();
|
self_.from.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1142,11 +1144,12 @@ pub fn highlight_references(self: *Self, from: tp.pid_ref, file_path: []const u8
|
||||||
if (try cbor.match(response.buf, .{ "child", tp.string, "result", tp.null_ })) {
|
if (try cbor.match(response.buf, .{ "child", tp.string, "result", tp.null_ })) {
|
||||||
return;
|
return;
|
||||||
} else if (try cbor.match(response.buf, .{ "child", tp.string, "result", tp.extract_cbor(&highlights) })) {
|
} else if (try cbor.match(response.buf, .{ "child", tp.string, "result", tp.extract_cbor(&highlights) })) {
|
||||||
_ = try send_highlight_list(self_.from.ref(), highlights);
|
_ = try send_highlight_list(self_.from.ref(), highlights, self_.file_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} = .{
|
} = .{
|
||||||
.from = from.clone(),
|
.from = from.clone(),
|
||||||
|
.file_path = try std.heap.c_allocator.dupe(u8, file_path),
|
||||||
};
|
};
|
||||||
|
|
||||||
lsp.send_request(self.allocator, "textDocument/documentHighlight", .{
|
lsp.send_request(self.allocator, "textDocument/documentHighlight", .{
|
||||||
|
|
@ -1156,24 +1159,25 @@ pub fn highlight_references(self: *Self, from: tp.pid_ref, file_path: []const u8
|
||||||
}, handler) catch return error.LspFailed;
|
}, handler) catch return error.LspFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_highlight_list(to: tp.pid_ref, highlights: []const u8) (error{InvalidDocumentHighlightList} || DocumentHighlightError)!usize {
|
fn send_highlight_list(to: tp.pid_ref, highlights: []const u8, file_path: []const u8) (error{InvalidDocumentHighlightList} || DocumentHighlightError)!usize {
|
||||||
defer to.send(.{ "HREF", "done" }) catch {};
|
defer to.send(.{ "HREF", file_path, "done" }) catch {};
|
||||||
var iter = highlights;
|
var iter = highlights;
|
||||||
var len = try cbor.decodeArrayHeader(&iter);
|
var len = try cbor.decodeArrayHeader(&iter);
|
||||||
const count = len;
|
const count = len;
|
||||||
while (len > 0) : (len -= 1) {
|
while (len > 0) : (len -= 1) {
|
||||||
var highlight: []const u8 = undefined;
|
var highlight: []const u8 = undefined;
|
||||||
if (try cbor.matchValue(&iter, cbor.extract_cbor(&highlight))) {
|
if (try cbor.matchValue(&iter, cbor.extract_cbor(&highlight))) {
|
||||||
try send_highlight(to, highlight);
|
try send_highlight(to, highlight, file_path);
|
||||||
} else return error.InvalidDocumentHighlightList;
|
} else return error.InvalidDocumentHighlightList;
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_highlight(to: tp.pid_ref, highlight_: []const u8) DocumentHighlightError!void {
|
fn send_highlight(to: tp.pid_ref, highlight_: []const u8, file_path: []const u8) DocumentHighlightError!void {
|
||||||
const highlight = try read_document_highlight(highlight_);
|
const highlight = try read_document_highlight(highlight_);
|
||||||
to.send(.{
|
to.send(.{
|
||||||
"HREF",
|
"HREF",
|
||||||
|
file_path,
|
||||||
highlight.range.start.line + 1,
|
highlight.range.start.line + 1,
|
||||||
highlight.range.start.character,
|
highlight.range.start.character,
|
||||||
highlight.range.end.line + 1,
|
highlight.range.end.line + 1,
|
||||||
|
|
|
||||||
|
|
@ -165,13 +165,13 @@ pub fn receive(self: *Self, from_: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||||
}
|
}
|
||||||
self.find_in_files_state = .done;
|
self.find_in_files_state = .done;
|
||||||
return true;
|
return true;
|
||||||
} else if (try m.match(.{ "HREF", tp.extract(&begin_line), tp.extract(&begin_pos), tp.extract(&end_line), tp.extract(&end_pos) })) {
|
} else if (try m.match(.{ "HREF", tp.extract(&path), tp.extract(&begin_line), tp.extract(&begin_pos), tp.extract(&end_line), tp.extract(&end_pos) })) {
|
||||||
if (self.get_active_editor()) |editor| editor.add_highlight_reference(.{
|
if (self.get_active_editor()) |editor| editor.add_highlight_reference(.{
|
||||||
.begin = .{ .row = begin_line, .col = begin_pos },
|
.begin = .{ .row = begin_line, .col = begin_pos },
|
||||||
.end = .{ .row = end_line, .col = end_pos },
|
.end = .{ .row = end_line, .col = end_pos },
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
} else if (try m.match(.{ "HREF", "done" })) {
|
} else if (try m.match(.{ "HREF", tp.extract(&path), "done" })) {
|
||||||
if (self.get_active_editor()) |editor| editor.done_highlight_reference();
|
if (self.get_active_editor()) |editor| editor.done_highlight_reference();
|
||||||
return true;
|
return true;
|
||||||
} else if (try m.match(.{ "hover", tp.extract(&path), tp.string, tp.extract(&lines), tp.extract(&begin_line), tp.extract(&begin_pos), tp.extract(&end_line), tp.extract(&end_pos) })) {
|
} else if (try m.match(.{ "hover", tp.extract(&path), tp.string, tp.extract(&lines), tp.extract(&begin_line), tp.extract(&begin_pos), tp.extract(&end_line), tp.extract(&end_pos) })) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue