Merge pull request #648 from Techatrix/dev
Refactor builtin_completions
This commit is contained in:
commit
eaa19d8a13
@ -26,6 +26,7 @@ config: Config,
|
|||||||
allocator: std.mem.Allocator = undefined,
|
allocator: std.mem.Allocator = undefined,
|
||||||
arena: std.heap.ArenaAllocator = undefined,
|
arena: std.heap.ArenaAllocator = undefined,
|
||||||
document_store: DocumentStore = undefined,
|
document_store: DocumentStore = undefined,
|
||||||
|
builtin_completions: ?std.ArrayListUnmanaged(types.CompletionItem) = null,
|
||||||
client_capabilities: ClientCapabilities = .{},
|
client_capabilities: ClientCapabilities = .{},
|
||||||
offset_encoding: offsets.Encoding = .utf16,
|
offset_encoding: offsets.Encoding = .utf16,
|
||||||
keep_running: bool = true,
|
keep_running: bool = true,
|
||||||
@ -1387,39 +1388,33 @@ fn completeLabel(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var builtin_completions: ?[]types.CompletionItem = null;
|
fn populateBuiltinCompletions(builtin_completions: *std.ArrayListUnmanaged(types.CompletionItem), config: Config) !void {
|
||||||
fn completeBuiltin(server: *Server, writer: anytype, id: types.RequestId) !void {
|
for (data.builtins) |builtin| {
|
||||||
const tracy_zone = tracy.trace(@src());
|
const insert_text = if (config.enable_snippets) builtin.snippet else builtin.name;
|
||||||
defer tracy_zone.end();
|
builtin_completions.appendAssumeCapacity(.{
|
||||||
|
|
||||||
if (builtin_completions == null) {
|
|
||||||
builtin_completions = try server.allocator.alloc(types.CompletionItem, data.builtins.len);
|
|
||||||
for (data.builtins) |builtin, idx| {
|
|
||||||
builtin_completions.?[idx] = types.CompletionItem{
|
|
||||||
.label = builtin.name,
|
.label = builtin.name,
|
||||||
.kind = .Function,
|
.kind = .Function,
|
||||||
.filterText = builtin.name[1..],
|
.filterText = builtin.name[1..],
|
||||||
.detail = builtin.signature,
|
.detail = builtin.signature,
|
||||||
|
.insertText = if (config.include_at_in_builtins) insert_text else insert_text[1..],
|
||||||
|
.insertTextFormat = if (config.enable_snippets) .Snippet else .PlainText,
|
||||||
.documentation = .{
|
.documentation = .{
|
||||||
.kind = .Markdown,
|
.kind = .Markdown,
|
||||||
.value = builtin.documentation,
|
.value = builtin.documentation,
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var insert_text: []const u8 = undefined;
|
truncateCompletions(builtin_completions.items, config.max_detail_length);
|
||||||
if (server.config.enable_snippets) {
|
}
|
||||||
insert_text = builtin.snippet;
|
|
||||||
builtin_completions.?[idx].insertTextFormat = .Snippet;
|
fn completeBuiltin(server: *Server, writer: anytype, id: types.RequestId) !void {
|
||||||
} else {
|
const tracy_zone = tracy.trace(@src());
|
||||||
insert_text = builtin.name;
|
defer tracy_zone.end();
|
||||||
}
|
|
||||||
builtin_completions.?[idx].insertText =
|
if (server.builtin_completions == null) {
|
||||||
if (server.config.include_at_in_builtins)
|
server.builtin_completions = try std.ArrayListUnmanaged(types.CompletionItem).initCapacity(server.allocator, data.builtins.len);
|
||||||
insert_text
|
try populateBuiltinCompletions(&server.builtin_completions.?, server.config);
|
||||||
else
|
|
||||||
insert_text[1..];
|
|
||||||
}
|
|
||||||
truncateCompletions(builtin_completions.?, server.config.max_detail_length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try send(writer, server.arena.allocator(), types.Response{
|
try send(writer, server.arena.allocator(), types.Response{
|
||||||
@ -1427,7 +1422,7 @@ fn completeBuiltin(server: *Server, writer: anytype, id: types.RequestId) !void
|
|||||||
.result = .{
|
.result = .{
|
||||||
.CompletionList = .{
|
.CompletionList = .{
|
||||||
.isIncomplete = false,
|
.isIncomplete = false,
|
||||||
.items = builtin_completions.?,
|
.items = server.builtin_completions.?.items,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -2642,7 +2637,7 @@ pub fn deinit(server: *Server) void {
|
|||||||
const config_parse_options = std.json.ParseOptions{ .allocator = server.allocator };
|
const config_parse_options = std.json.ParseOptions{ .allocator = server.allocator };
|
||||||
defer std.json.parseFree(Config, server.config, config_parse_options);
|
defer std.json.parseFree(Config, server.config, config_parse_options);
|
||||||
|
|
||||||
if (builtin_completions) |compls| {
|
if (server.builtin_completions) |*compls| {
|
||||||
server.allocator.free(compls);
|
compls.deinit(server.allocator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user