Skip to content

Commit

Permalink
don't add snippets when the client does not support it. (#1532)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsan901998 authored Oct 17, 2023
1 parent b18fd85 commit a781897
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/features/completions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -498,22 +498,23 @@ fn completeLabel(
}

fn populateSnippedCompletions(
server: *Server,
allocator: std.mem.Allocator,
completions: *std.ArrayListUnmanaged(types.CompletionItem),
snippets: []const snipped_data.Snipped,
config: Config,
) error{OutOfMemory}!void {
try completions.ensureUnusedCapacity(allocator, snippets.len);

const use_snippets = server.config.enable_snippets and server.client_capabilities.supports_snippets;
for (snippets) |snipped| {
if (!config.enable_snippets and snipped.kind == .Snippet) continue;
if (!use_snippets and snipped.kind == .Snippet) continue;

completions.appendAssumeCapacity(.{
.label = snipped.label,
.kind = snipped.kind,
.detail = if (config.enable_snippets) snipped.text else null,
.insertText = if (config.enable_snippets) snipped.text else null,
.insertTextFormat = if (config.enable_snippets and snipped.text != null) .Snippet else .PlainText,
.detail = if (use_snippets) snipped.text else null,
.insertText = if (use_snippets) snipped.text else null,
.insertTextFormat = if (use_snippets and snipped.text != null) .Snippet else .PlainText,
});
}
}
Expand Down Expand Up @@ -561,7 +562,7 @@ fn completeGlobal(server: *Server, analyser: *Analyser, arena: std.mem.Allocator
.orig_handle = handle,
};
try analyser.iterateSymbolsGlobal(handle, pos_index, declToCompletion, context);
try populateSnippedCompletions(arena, &completions, &snipped_data.generic, server.config);
try populateSnippedCompletions(server, arena, &completions, &snipped_data.generic);
try formatCompletionDetails(server, arena, completions.items);

return completions.toOwnedSlice(arena);
Expand Down Expand Up @@ -932,7 +933,7 @@ pub fn completionAtIndex(server: *Server, analyser: *Analyser, arena: std.mem.Al
const at_line_start = offsets.lineSliceUntilIndex(source, source_index).len < 2;
if (at_line_start) {
var completions = std.ArrayListUnmanaged(types.CompletionItem){};
try populateSnippedCompletions(arena, &completions, &snipped_data.top_level_decl_data, server.config);
try populateSnippedCompletions(server, arena, &completions, &snipped_data.top_level_decl_data);

return .{ .isIncomplete = false, .items = completions.items };
}
Expand Down

0 comments on commit a781897

Please sign in to comment.