From 8d34232c7ad57e81f91038aacf5fe547c7bbfbe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20H=C3=A4hne?= Date: Wed, 24 Mar 2021 22:40:15 +0100 Subject: [PATCH] Fix completion of builtins and a piece of slightly overcomplicated logic --- src/document_store.zig | 24 ++++++++++++------------ src/main.zig | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/document_store.zig b/src/document_store.zig index de817d6..4ad5f47 100644 --- a/src/document_store.zig +++ b/src/document_store.zig @@ -381,27 +381,27 @@ fn refreshDocument(self: *DocumentStore, handle: *Handle, zig_lib_path: ?[]const const std_uri = try stdUriFromLibPath(&arena.allocator, zig_lib_path); for (import_strs.items) |str| { const uri = (try self.uriFromImportStr(&arena.allocator, handle.*, str)) orelse continue; + + exists_loop: for (still_exist) |*does_still_exist, i| { + if (does_still_exist.*) continue; - var idx: usize = 0; - exists_loop: while (idx < still_exist.len) : (idx += 1) { - if (still_exist[idx]) continue; - - if (std.mem.eql(u8, handle.import_uris.items[idx], uri)) { - still_exist[idx] = true; + if (std.mem.eql(u8, handle.import_uris.items[i], uri)) { + does_still_exist.* = true; break :exists_loop; } } } // Go through still_exist, remove the items that are false and decrement their handle counts. - var offset: usize = 0; var idx: usize = 0; - while (idx < still_exist.len) : (idx += 1) { - if (still_exist[idx]) continue; + for (still_exist) |does_still_exist| { + if (does_still_exist) { + idx += 1; + continue; + } - log.debug("Import removed: {s}", .{handle.import_uris.items[idx - offset]}); - const uri = handle.import_uris.orderedRemove(idx - offset); - offset += 1; + log.debug("Import removed: {s}", .{handle.import_uris.items[idx]}); + const uri = handle.import_uris.orderedRemove(idx); self.decrementCount(uri); self.allocator.free(uri); diff --git a/src/main.zig b/src/main.zig index a9c60bb..97878fb 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1027,10 +1027,10 @@ fn completeBuiltin(arena: *std.heap.ArenaAllocator, id: types.RequestId, config: }; if (config.enable_snippets) { - builtin_completions.?[idx].insertText = builtin.snippet[1..]; + builtin_completions.?[idx].insertText = builtin.snippet; builtin_completions.?[idx].insertTextFormat = .Snippet; } else { - builtin_completions.?[idx].insertText = builtin.name[1..]; + builtin_completions.?[idx].insertText = builtin.name; } } }