From 472e28ad5c14a885620e39759e241915116ab3ec Mon Sep 17 00:00:00 2001 From: ryuukk <44361234+ryuukk@users.noreply.github.com> Date: Fri, 14 Oct 2022 18:24:22 +0200 Subject: [PATCH] builtins also get their detailed label (#706) --- src/Server.zig | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Server.zig b/src/Server.zig index d1abe3b..9cb5517 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -1221,7 +1221,7 @@ fn formatDetailledLabel(item: *types.CompletionItem, alloc: std.mem.Allocator) ! // loggerger.info("## label: {s} it: {s} kind: {} isValue: {}", .{item.label, it, item.kind, isValue}); - if (std.mem.startsWith(u8, it, "fn ")) { + if (std.mem.startsWith(u8, it, "fn ") or std.mem.startsWith(u8, it, "@")) { var s: usize = std.mem.indexOf(u8, it, "(") orelse return; var e: usize = std.mem.lastIndexOf(u8, it, ")") orelse return; if (e < s) { @@ -1511,6 +1511,14 @@ fn initializeHandler(server: *Server, writer: anytype, id: types.RequestId, req: } } + // NOTE: everything is initialized, we got the client capabilities + // so we can now format the prebuilt builtins items for labelDetails + if (server.client_capabilities.label_details_support) { + for(server.builtin_completions.items) |*item| { + try formatDetailledLabel(item, std.heap.page_allocator); + } + } + try send(writer, server.arena.allocator(), types.Response{ .id = id, .result = .{ @@ -2568,7 +2576,7 @@ pub fn init( errdefer document_store.deinit(); var builtin_completions = try std.ArrayListUnmanaged(types.CompletionItem).initCapacity(allocator, data.builtins.len); - errdefer builtin_completions.deinit(); + errdefer builtin_completions.deinit(allocator); for (data.builtins) |builtin| { const insert_text = if (config.enable_snippets) builtin.snippet else builtin.name;