Skip to content

Commit

Permalink
cache the result of prepareFunctionCompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Dec 26, 2024
1 parent c4456e7 commit bd4b226
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/features/completions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Builder = struct {
orig_handle: *DocumentStore.Handle,
source_index: usize,
completions: std.ArrayListUnmanaged(types.CompletionItem),
cached_prepare_function_completion_result: ?PrepareFunctionCompletionResult = null,
};

fn typeToCompletion(builder: *Builder, ty: Analyser.Type) error{OutOfMemory}!void {
Expand Down Expand Up @@ -469,8 +470,11 @@ fn populateSnippedCompletions(builder: *Builder, snippets: []const snipped_data.
}

const FunctionCompletionFormat = enum { snippet, only_name };
const PrepareFunctionCompletionResult = struct { types.Range, types.Range, FunctionCompletionFormat };

fn prepareFunctionCompletion(builder: *Builder) PrepareFunctionCompletionResult {
if (builder.cached_prepare_function_completion_result) |result| return result;

fn prepareFunctionCompletion(builder: *Builder) struct { types.Range, types.Range, FunctionCompletionFormat } {
const use_snippets = builder.server.config.enable_snippets and builder.server.client_capabilities.supports_snippets;
const source = builder.orig_handle.tree.source;

Expand Down Expand Up @@ -505,7 +509,8 @@ fn prepareFunctionCompletion(builder: *Builder) struct { types.Range, types.Rang
const insert_range = offsets.locToRange(source, insert_loc, builder.server.offset_encoding);
const replace_range = offsets.locToRange(source, replace_loc, builder.server.offset_encoding);

return .{ insert_range, replace_range, format };
builder.cached_prepare_function_completion_result = .{ insert_range, replace_range, format };
return builder.cached_prepare_function_completion_result.?;
}

fn completeBuiltin(builder: *Builder) error{OutOfMemory}!void {
Expand Down

0 comments on commit bd4b226

Please sign in to comment.