Small fixes and code cleanup
This commit is contained in:
parent
9bf0842697
commit
6f23d8a053
@ -245,30 +245,24 @@ pub fn openDocument(self: *DocumentStore, uri: []const u8, text: []const u8) !*H
|
|||||||
return try self.newDocument(duped_uri, duped_text);
|
return try self.newDocument(duped_uri, duped_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decrementBuildFileRefs(self: *DocumentStore, build_file_ptr: *?*BuildFile) void {
|
fn decrementBuildFileRefs(self: *DocumentStore, build_file: *BuildFile) void {
|
||||||
const build_file = build_file_ptr.*.?;
|
|
||||||
|
|
||||||
build_file.refs -= 1;
|
build_file.refs -= 1;
|
||||||
if (build_file.refs == 0) {
|
if (build_file.refs == 0) {
|
||||||
std.debug.warn("Freeing build file {}\n", .{build_file.uri});
|
std.debug.warn("Freeing build file {}\n", .{build_file.uri});
|
||||||
// Free the build file, set the pointer to null.
|
|
||||||
for (build_file.packages.items) |pkg| {
|
for (build_file.packages.items) |pkg| {
|
||||||
self.allocator.free(pkg.name);
|
self.allocator.free(pkg.name);
|
||||||
self.allocator.free(pkg.uri);
|
self.allocator.free(pkg.uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
build_file.packages.deinit(self.allocator);
|
build_file.packages.deinit(self.allocator);
|
||||||
|
|
||||||
// Decrement count of the document since one count comes
|
// Decrement count of the document since one count comes
|
||||||
// from the build file existing.
|
// from the build file existing.
|
||||||
self.decrementCount(build_file.uri);
|
self.decrementCount(build_file.uri);
|
||||||
self.allocator.free(build_file.uri);
|
self.allocator.free(build_file.uri);
|
||||||
|
|
||||||
// Remove the build file from the array list
|
// Remove the build file from the array list
|
||||||
_ = self.build_files.swapRemove(std.mem.indexOfScalar(*BuildFile, self.build_files.items, build_file).?);
|
_ = self.build_files.swapRemove(std.mem.indexOfScalar(*BuildFile, self.build_files.items, build_file).?);
|
||||||
|
|
||||||
self.allocator.destroy(build_file);
|
self.allocator.destroy(build_file);
|
||||||
build_file_ptr.* = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,8 +270,8 @@ fn decrementCount(self: *DocumentStore, uri: []const u8) void {
|
|||||||
if (self.handles.get(uri)) |entry| {
|
if (self.handles.get(uri)) |entry| {
|
||||||
entry.value.count -= 1;
|
entry.value.count -= 1;
|
||||||
|
|
||||||
if (entry.value.associated_build_file != null) {
|
if (entry.value.associated_build_file) |build_file| {
|
||||||
self.decrementBuildFileRefs(&entry.value.associated_build_file);
|
self.decrementBuildFileRefs(build_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.value.count > 0)
|
if (entry.value.count > 0)
|
||||||
@ -535,7 +529,11 @@ pub const AnalysisContext = struct {
|
|||||||
// New import.
|
// New import.
|
||||||
// Check if the import is already opened by others.
|
// Check if the import is already opened by others.
|
||||||
if (self.store.getHandle(final_uri)) |new_handle| {
|
if (self.store.getHandle(final_uri)) |new_handle| {
|
||||||
// If it is, increment the count, set our new handle and return the parsed tree root node.
|
// If it is, append it to our imports, increment the count, set our new handle
|
||||||
|
// and return the parsed tree root node.
|
||||||
|
try self.handle.import_uris.append(final_uri);
|
||||||
|
consumed_final_uri = true;
|
||||||
|
|
||||||
new_handle.count += 1;
|
new_handle.count += 1;
|
||||||
self.handle = new_handle;
|
self.handle = new_handle;
|
||||||
try self.refreshScopeNodes();
|
try self.refreshScopeNodes();
|
||||||
|
Loading…
Reference in New Issue
Block a user