Change handles HashMap value type to pointers instead of values themselves
This commit is contained in:
parent
6cd98697c0
commit
d79f3bc809
@ -194,6 +194,7 @@ pub fn resolveTypeOfNode(analysis_ctx: *AnalysisContext, node: *ast.Node) ?*ast.
|
|||||||
switch (node.id) {
|
switch (node.id) {
|
||||||
.VarDecl => {
|
.VarDecl => {
|
||||||
const vari = node.cast(ast.Node.VarDecl).?;
|
const vari = node.cast(ast.Node.VarDecl).?;
|
||||||
|
|
||||||
return resolveTypeOfNode(analysis_ctx, vari.type_node orelse vari.init_node.?) orelse null;
|
return resolveTypeOfNode(analysis_ctx, vari.type_node orelse vari.init_node.?) orelse null;
|
||||||
},
|
},
|
||||||
.FnProto => {
|
.FnProto => {
|
||||||
|
@ -35,12 +35,12 @@ pub const Handle = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
allocator: *std.mem.Allocator,
|
allocator: *std.mem.Allocator,
|
||||||
handles: std.StringHashMap(Handle),
|
handles: std.StringHashMap(*Handle),
|
||||||
std_uri: ?[]const u8,
|
std_uri: ?[]const u8,
|
||||||
|
|
||||||
pub fn init(self: *DocumentStore, allocator: *std.mem.Allocator, zig_lib_path: ?[]const u8) !void {
|
pub fn init(self: *DocumentStore, allocator: *std.mem.Allocator, zig_lib_path: ?[]const u8) !void {
|
||||||
self.allocator = allocator;
|
self.allocator = allocator;
|
||||||
self.handles = std.StringHashMap(Handle).init(allocator);
|
self.handles = std.StringHashMap(*Handle).init(allocator);
|
||||||
errdefer self.handles.deinit();
|
errdefer self.handles.deinit();
|
||||||
|
|
||||||
if (zig_lib_path) |zpath| {
|
if (zig_lib_path) |zpath| {
|
||||||
@ -71,7 +71,10 @@ fn newDocument(self: *DocumentStore, uri: []const u8, text: []u8) !*Handle {
|
|||||||
self.allocator.free(text);
|
self.allocator.free(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
var handle = Handle{
|
var handle = try self.allocator.create(Handle);
|
||||||
|
errdefer self.allocator.destroy(handle);
|
||||||
|
|
||||||
|
handle.* = Handle{
|
||||||
.count = 1,
|
.count = 1,
|
||||||
.import_uris = std.ArrayList([]const u8).init(self.allocator),
|
.import_uris = std.ArrayList([]const u8).init(self.allocator),
|
||||||
.document = .{
|
.document = .{
|
||||||
@ -81,9 +84,9 @@ fn newDocument(self: *DocumentStore, uri: []const u8, text: []u8) !*Handle {
|
|||||||
.sane_text = null,
|
.sane_text = null,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
try self.checkSanity(&handle);
|
try self.checkSanity(handle);
|
||||||
try self.handles.putNoClobber(uri, handle);
|
try self.handles.putNoClobber(uri, handle);
|
||||||
return &(self.handles.get(uri) orelse unreachable).value;
|
return (self.handles.get(uri) orelse unreachable).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn openDocument(self: *DocumentStore, uri: []const u8, text: []const u8) !*Handle {
|
pub fn openDocument(self: *DocumentStore, uri: []const u8, text: []const u8) !*Handle {
|
||||||
@ -91,7 +94,7 @@ pub fn openDocument(self: *DocumentStore, uri: []const u8, text: []const u8) !*H
|
|||||||
std.debug.warn("Document already open: {}, incrementing count\n", .{uri});
|
std.debug.warn("Document already open: {}, incrementing count\n", .{uri});
|
||||||
entry.value.count += 1;
|
entry.value.count += 1;
|
||||||
std.debug.warn("New count: {}\n", .{entry.value.count});
|
std.debug.warn("New count: {}\n", .{entry.value.count});
|
||||||
return &entry.value;
|
return entry.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const duped_text = try std.mem.dupe(self.allocator, u8, text);
|
const duped_text = try std.mem.dupe(self.allocator, u8, text);
|
||||||
@ -124,6 +127,7 @@ fn decrementCount(self: *DocumentStore, uri: []const u8) void {
|
|||||||
const uri_key = entry.key;
|
const uri_key = entry.key;
|
||||||
self.handles.removeAssertDiscard(uri);
|
self.handles.removeAssertDiscard(uri);
|
||||||
self.allocator.free(uri_key);
|
self.allocator.free(uri_key);
|
||||||
|
self.allocator.destroy(entry.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +137,7 @@ pub fn closeDocument(self: *DocumentStore, uri: []const u8) void {
|
|||||||
|
|
||||||
pub fn getHandle(self: *DocumentStore, uri: []const u8) ?*Handle {
|
pub fn getHandle(self: *DocumentStore, uri: []const u8) ?*Handle {
|
||||||
if (self.handles.get(uri)) |entry| {
|
if (self.handles.get(uri)) |entry| {
|
||||||
return &entry.value;
|
return entry.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -394,6 +398,7 @@ pub fn deinit(self: *DocumentStore) void {
|
|||||||
|
|
||||||
entry.value.import_uris.deinit();
|
entry.value.import_uris.deinit();
|
||||||
self.allocator.free(entry.key);
|
self.allocator.free(entry.key);
|
||||||
|
self.allocator.destroy(entry.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.handles.deinit();
|
self.handles.deinit();
|
||||||
|
@ -287,13 +287,12 @@ fn completeFieldAccess(id: i64, handle: *DocumentStore.Handle, position: types.P
|
|||||||
var tokenizer = std.zig.Tokenizer.init(line_copy);
|
var tokenizer = std.zig.Tokenizer.init(line_copy);
|
||||||
|
|
||||||
if (analysis.getFieldAccessTypeNode(&analysis_ctx, &tokenizer)) |node| {
|
if (analysis.getFieldAccessTypeNode(&analysis_ctx, &tokenizer)) |node| {
|
||||||
const initial_document = try std.mem.dupe(&arena.allocator, u8, analysis_ctx.handle.document.uri);
|
|
||||||
var index: usize = 0;
|
var index: usize = 0;
|
||||||
while (node.iterate(index)) |child_node| {
|
while (node.iterate(index)) |child_node| {
|
||||||
if (analysis.isNodePublic(analysis_ctx.tree, child_node)) {
|
if (analysis.isNodePublic(analysis_ctx.tree, child_node)) {
|
||||||
// TODO: Not great to allocate it again and again inside a loop
|
// TODO: Not great to allocate it again and again inside a loop
|
||||||
// Creating a new context, so that we don't destroy the tree that is iterated above when resolving imports
|
// Creating a new context, so that we don't destroy the tree that is iterated above when resolving imports
|
||||||
const initial_handle = document_store.getHandle(initial_document) orelse continue;
|
const initial_handle = analysis_ctx.handle;
|
||||||
std.debug.warn("\ncompleteFieldAccess calling resolveTypeOfNode for {}\n", .{analysis_ctx.tree.getNodeSource(child_node)});
|
std.debug.warn("\ncompleteFieldAccess calling resolveTypeOfNode for {}\n", .{analysis_ctx.tree.getNodeSource(child_node)});
|
||||||
var node_analysis_ctx = (try document_store.analysisContext(initial_handle, &arena)) orelse {
|
var node_analysis_ctx = (try document_store.analysisContext(initial_handle, &arena)) orelse {
|
||||||
return send(types.Response{
|
return send(types.Response{
|
||||||
|
Loading…
Reference in New Issue
Block a user