diff --git a/src/DocumentStore.zig b/src/DocumentStore.zig index 37f515f..7e5a309 100644 --- a/src/DocumentStore.zig +++ b/src/DocumentStore.zig @@ -107,10 +107,16 @@ pub fn deinit(self: *DocumentStore) void { /// returns a handle to the given document pub fn getHandle(self: *DocumentStore, uri: Uri) ?*const Handle { - return self.getHandleInternal(uri) catch null; + return self.handles.get(uri); } -fn getHandleInternal(self: *DocumentStore, uri: Uri) !?*const Handle { +/// returns a handle to the given document +/// will load the document from disk if it hasn't been already +pub fn getOrLoadHandle(self: *DocumentStore, uri: Uri) ?*const Handle { + return self.getOrLoadHandleInternal(uri) catch null; +} + +fn getOrLoadHandleInternal(self: *DocumentStore, uri: Uri) !?*const Handle { if (self.handles.get(uri)) |handle| return handle; var handle = try self.allocator.create(Handle); @@ -569,7 +575,7 @@ fn uriInImports( // consider it checked even if a failure happens try checked_uris.put(try self.allocator.dupe(u8, source_uri), {}); - const handle = self.getHandle(source_uri) orelse return false; + const handle = self.getOrLoadHandle(source_uri) orelse return false; for (handle.import_uris.items) |import_uri| { if (std.mem.eql(u8, uri, import_uri)) diff --git a/src/analysis.zig b/src/analysis.zig index f02e6b2..e34c1e8 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -914,14 +914,14 @@ pub fn resolveTypeOfNodeInternal(store: *DocumentStore, arena: *std.heap.ArenaAl const import_str = tree.tokenSlice(main_tokens[import_param]); const import_uri = (try store.uriFromImportStr(arena.allocator(), handle.*, import_str[1 .. import_str.len - 1])) orelse return null; - const new_handle = store.getHandle(import_uri) orelse return null; + const new_handle = store.getOrLoadHandle(import_uri) orelse return null; // reference to node '0' which is root return TypeWithHandle.typeVal(.{ .node = 0, .handle = new_handle }); } else if (std.mem.eql(u8, call_name, "@cImport")) { const cimport_uri = (try store.resolveCImport(handle.*, node)) orelse return null; - const new_handle = store.getHandle(cimport_uri) orelse return null; + const new_handle = store.getOrLoadHandle(cimport_uri) orelse return null; // reference to node '0' which is root return TypeWithHandle.typeVal(.{ .node = 0, .handle = new_handle });