feat: lsp symbols with parent in mainview
This commit is contained in:
parent
368b139688
commit
cfb208f3d8
2 changed files with 7 additions and 10 deletions
|
|
@ -1229,7 +1229,7 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const
|
||||||
var location: ?Location = null;
|
var location: ?Location = null;
|
||||||
var containerName: ?[]const u8 = "";
|
var containerName: ?[]const u8 = "";
|
||||||
var len_tags_: usize = 0;
|
var len_tags_: usize = 0;
|
||||||
var children_count: usize = 0;
|
var descendant_count: usize = 0;
|
||||||
var symbolKind: SymbolType = undefined;
|
var symbolKind: SymbolType = undefined;
|
||||||
const logger_t = log.logger("lsp");
|
const logger_t = log.logger("lsp");
|
||||||
defer logger_t.deinit();
|
defer logger_t.deinit();
|
||||||
|
|
@ -1239,10 +1239,8 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const
|
||||||
while (len > 0) : (len -= 1) {
|
while (len > 0) : (len -= 1) {
|
||||||
var field_name: []const u8 = undefined;
|
var field_name: []const u8 = undefined;
|
||||||
if (!(try cbor.matchString(&iter, &field_name))) return error.InvalidMessage;
|
if (!(try cbor.matchString(&iter, &field_name))) return error.InvalidMessage;
|
||||||
logger_t.print("{s}", .{field_name});
|
|
||||||
if (std.mem.eql(u8, field_name, "name")) {
|
if (std.mem.eql(u8, field_name, "name")) {
|
||||||
if (!(try cbor.matchValue(&iter, cbor.extract(&name)))) return invalid_field("name");
|
if (!(try cbor.matchValue(&iter, cbor.extract(&name)))) return invalid_field("name");
|
||||||
logger_t.print("->> {s}", .{name});
|
|
||||||
} else if (std.mem.eql(u8, field_name, "detail")) {
|
} else if (std.mem.eql(u8, field_name, "detail")) {
|
||||||
if (!(try cbor.matchValue(&iter, cbor.extract(&detail)))) return invalid_field("detail");
|
if (!(try cbor.matchValue(&iter, cbor.extract(&detail)))) return invalid_field("detail");
|
||||||
} else if (std.mem.eql(u8, field_name, "kind")) {
|
} else if (std.mem.eql(u8, field_name, "kind")) {
|
||||||
|
|
@ -1271,12 +1269,11 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const
|
||||||
selectionRange = try read_range(range_);
|
selectionRange = try read_range(range_);
|
||||||
} else if (std.mem.eql(u8, field_name, "children")) {
|
} else if (std.mem.eql(u8, field_name, "children")) {
|
||||||
var len_ = cbor.decodeArrayHeader(&iter) catch return 0;
|
var len_ = cbor.decodeArrayHeader(&iter) catch return 0;
|
||||||
|
var descendant: []const u8 = "";
|
||||||
while (len_ > 0) : (len_ -= 1) {
|
while (len_ > 0) : (len_ -= 1) {
|
||||||
children_count += try send_symbol_information(to, file_path, iter, name);
|
if (!(try cbor.matchValue(&iter, cbor.extract_cbor(&descendant)))) return error.InvalidMessageField;
|
||||||
|
descendant_count += try send_symbol_information(to, file_path, descendant, name);
|
||||||
}
|
}
|
||||||
logger_t.print("children: {d}", .{len_});
|
|
||||||
try cbor.skipValue(&iter);
|
|
||||||
logger_t.print("Skipped thing: {d}", .{len_});
|
|
||||||
} else if (std.mem.eql(u8, field_name, "location")) {} else if (std.mem.eql(u8, field_name, "location")) {
|
} else if (std.mem.eql(u8, field_name, "location")) {} else if (std.mem.eql(u8, field_name, "location")) {
|
||||||
var location_: []const u8 = undefined;
|
var location_: []const u8 = undefined;
|
||||||
if (!(try cbor.matchValue(&iter, cbor.extract_cbor(&location_)))) return invalid_field("selectionRange");
|
if (!(try cbor.matchValue(&iter, cbor.extract_cbor(&location_)))) return invalid_field("selectionRange");
|
||||||
|
|
@ -1288,7 +1285,7 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const
|
||||||
try cbor.skipValue(&iter);
|
try cbor.skipValue(&iter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger_t.print("Processed: {s}", .{name});
|
logger_t.print("Processed: {s} with {d} descendants", .{ name, descendant_count });
|
||||||
|
|
||||||
try switch (symbolKind) {
|
try switch (symbolKind) {
|
||||||
SymbolType.document_symbol => {
|
SymbolType.document_symbol => {
|
||||||
|
|
@ -1309,7 +1306,7 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const
|
||||||
deprecated,
|
deprecated,
|
||||||
detail,
|
detail,
|
||||||
} }) catch return error.ClientFailed;
|
} }) catch return error.ClientFailed;
|
||||||
return children_count + 1;
|
return descendant_count + 1;
|
||||||
},
|
},
|
||||||
SymbolType.symbol_information => {
|
SymbolType.symbol_information => {
|
||||||
var fp = file_path;
|
var fp = file_path;
|
||||||
|
|
|
||||||
|
|
@ -985,7 +985,7 @@ const cmds = struct {
|
||||||
})) return error.InvalidAddDiagnosticArgument;
|
})) return error.InvalidAddDiagnosticArgument;
|
||||||
file_path = project_manager.normalize_file_path(file_path);
|
file_path = project_manager.normalize_file_path(file_path);
|
||||||
if (self.get_active_editor()) |editor| if (std.mem.eql(u8, file_path, editor.file_path orelse "")) {
|
if (self.get_active_editor()) |editor| if (std.mem.eql(u8, file_path, editor.file_path orelse "")) {
|
||||||
logger.print("received symbol '{s}'", .{name});
|
logger.print("received symbol '{s}', '{s}'", .{ name, parent });
|
||||||
self.symbols_complete = false;
|
self.symbols_complete = false;
|
||||||
try self.symbols.appendSlice(self.allocator, ctx.args.buf);
|
try self.symbols.appendSlice(self.allocator, ctx.args.buf);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue