only include snippet completions when enable_snippet is set

This commit is contained in:
Techatrix 2023-03-25 21:10:30 +01:00 committed by Lee Cannon
parent 90b468ac9f
commit 9a7d262e6c

View File

@ -436,14 +436,11 @@ fn populateSnippedCompletions(
completions: *std.ArrayListUnmanaged(types.CompletionItem), completions: *std.ArrayListUnmanaged(types.CompletionItem),
snippets: []const snipped_data.Snipped, snippets: []const snipped_data.Snipped,
config: Config, config: Config,
start_with: ?[]const u8,
) error{OutOfMemory}!void { ) error{OutOfMemory}!void {
try completions.ensureUnusedCapacity(allocator, snippets.len); try completions.ensureUnusedCapacity(allocator, snippets.len);
for (snippets) |snipped| { for (snippets) |snipped| {
if (start_with) |needle| { if (!config.enable_snippets and snipped.kind == .Snippet) continue;
if (!std.mem.startsWith(u8, snipped.label, needle)) continue;
}
completions.appendAssumeCapacity(.{ completions.appendAssumeCapacity(.{
.label = snipped.label, .label = snipped.label,
@ -511,7 +508,7 @@ fn completeGlobal(server: *Server, pos_index: usize, handle: *const DocumentStor
.orig_handle = handle, .orig_handle = handle,
}; };
try server.analyser.iterateSymbolsGlobal(handle, pos_index, declToCompletion, context); try server.analyser.iterateSymbolsGlobal(handle, pos_index, declToCompletion, context);
try populateSnippedCompletions(server.arena.allocator(), &completions, &snipped_data.generic, server.config.*, null); try populateSnippedCompletions(server.arena.allocator(), &completions, &snipped_data.generic, server.config.*);
if (server.client_capabilities.label_details_support) { if (server.client_capabilities.label_details_support) {
for (completions.items) |*item| { for (completions.items) |*item| {
@ -1021,7 +1018,7 @@ pub fn completionAtIndex(server: *Server, source_index: usize, handle: *const Do
const at_line_start = offsets.lineSliceUntilIndex(handle.tree.source, source_index).len == 0; const at_line_start = offsets.lineSliceUntilIndex(handle.tree.source, source_index).len == 0;
if (at_line_start) { if (at_line_start) {
var completions = std.ArrayListUnmanaged(types.CompletionItem){}; var completions = std.ArrayListUnmanaged(types.CompletionItem){};
try populateSnippedCompletions(server.arena.allocator(), &completions, &snipped_data.top_level_decl_data, server.config.*, null); try populateSnippedCompletions(server.arena.allocator(), &completions, &snipped_data.top_level_decl_data, server.config.*);
return .{ .isIncomplete = false, .items = completions.items }; return .{ .isIncomplete = false, .items = completions.items };
} }