Copy scope nodes when cloning an analysis context
This commit is contained in:
parent
7d5d217e2f
commit
a330932b7c
@ -327,6 +327,7 @@ fn refreshDocument(self: *DocumentStore, handle: *Handle, zig_lib_path: ?[]const
|
|||||||
var import_strs = std.ArrayList([]const u8).init(&arena.allocator);
|
var import_strs = std.ArrayList([]const u8).init(&arena.allocator);
|
||||||
try analysis.collectImports(&import_strs, handle.tree);
|
try analysis.collectImports(&import_strs, handle.tree);
|
||||||
|
|
||||||
|
// @TODO: Check final resolved import path and not just import string
|
||||||
const still_exist = try arena.allocator.alloc(bool, handle.import_uris.items.len);
|
const still_exist = try arena.allocator.alloc(bool, handle.import_uris.items.len);
|
||||||
for (still_exist) |*ex| {
|
for (still_exist) |*ex| {
|
||||||
ex.* = false;
|
ex.* = false;
|
||||||
@ -576,12 +577,14 @@ pub const AnalysisContext = struct {
|
|||||||
return &self.tree().root_node.base;
|
return &self.tree().root_node.base;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clone(self: *AnalysisContext) AnalysisContext {
|
pub fn clone(self: *AnalysisContext) !AnalysisContext {
|
||||||
|
// Copy the cope nodes, the rest are references
|
||||||
|
// that are not owned by the context.
|
||||||
return AnalysisContext{
|
return AnalysisContext{
|
||||||
.store = self.store,
|
.store = self.store,
|
||||||
.handle = self.handle,
|
.handle = self.handle,
|
||||||
.arena = self.arena,
|
.arena = self.arena,
|
||||||
.scope_nodes = self.scope_nodes,
|
.scope_nodes = try std.mem.dupe(&self.arena.allocator, *std.zig.ast.Node, self.scope_nodes),
|
||||||
.in_container = self.in_container,
|
.in_container = self.in_container,
|
||||||
.std_uri = self.std_uri,
|
.std_uri = self.std_uri,
|
||||||
};
|
};
|
||||||
|
20
src/main.zig
20
src/main.zig
@ -189,8 +189,8 @@ const ResolveVarDeclFnAliasRewsult = struct {
|
|||||||
analysis_ctx: DocumentStore.AnalysisContext,
|
analysis_ctx: DocumentStore.AnalysisContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn resolveVarDeclFnAlias(analysis_ctx: *DocumentStore.AnalysisContext, decl: *std.zig.ast.Node) ResolveVarDeclFnAliasRewsult {
|
fn resolveVarDeclFnAlias(analysis_ctx: *DocumentStore.AnalysisContext, decl: *std.zig.ast.Node) !ResolveVarDeclFnAliasRewsult {
|
||||||
var child_analysis_context = analysis_ctx.clone();
|
var child_analysis_context = try analysis_ctx.clone();
|
||||||
if (decl.cast(std.zig.ast.Node.VarDecl)) |var_decl| {
|
if (decl.cast(std.zig.ast.Node.VarDecl)) |var_decl| {
|
||||||
const child_node = block: {
|
const child_node = block: {
|
||||||
if (var_decl.type_node) |type_node| {
|
if (var_decl.type_node) |type_node| {
|
||||||
@ -204,11 +204,17 @@ fn resolveVarDeclFnAlias(analysis_ctx: *DocumentStore.AnalysisContext, decl: *st
|
|||||||
|
|
||||||
if (analysis.resolveTypeOfNode(&child_analysis_context, child_node)) |resolved_node| {
|
if (analysis.resolveTypeOfNode(&child_analysis_context, child_node)) |resolved_node| {
|
||||||
if (resolved_node.id == .FnProto) {
|
if (resolved_node.id == .FnProto) {
|
||||||
return .{ .decl = resolved_node, .analysis_ctx = child_analysis_context };
|
return ResolveVarDeclFnAliasRewsult{
|
||||||
|
.decl = resolved_node,
|
||||||
|
.analysis_ctx = child_analysis_context,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return .{ .decl = decl, .analysis_ctx = analysis_ctx.* };
|
return ResolveVarDeclFnAliasRewsult{
|
||||||
|
.decl = decl,
|
||||||
|
.analysis_ctx = analysis_ctx.*,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nodeToCompletion(
|
fn nodeToCompletion(
|
||||||
@ -254,7 +260,7 @@ fn nodeToCompletion(
|
|||||||
const var_decl = node.cast(std.zig.ast.Node.VarDecl).?;
|
const var_decl = node.cast(std.zig.ast.Node.VarDecl).?;
|
||||||
const is_const = analysis_ctx.tree().token_ids[var_decl.mut_token] == .Keyword_const;
|
const is_const = analysis_ctx.tree().token_ids[var_decl.mut_token] == .Keyword_const;
|
||||||
|
|
||||||
var result = resolveVarDeclFnAlias(analysis_ctx, node);
|
var result = try resolveVarDeclFnAlias(analysis_ctx, node);
|
||||||
if (result.decl != node) {
|
if (result.decl != node) {
|
||||||
return try nodeToCompletion(list, &result.analysis_ctx, orig_handle, result.decl, config);
|
return try nodeToCompletion(list, &result.analysis_ctx, orig_handle, result.decl, config);
|
||||||
}
|
}
|
||||||
@ -312,7 +318,7 @@ fn identifierFromPosition(pos_index: usize, handle: DocumentStore.Handle) []cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn gotoDefinitionSymbol(id: i64, analysis_ctx: *DocumentStore.AnalysisContext, decl: *std.zig.ast.Node) !void {
|
fn gotoDefinitionSymbol(id: i64, analysis_ctx: *DocumentStore.AnalysisContext, decl: *std.zig.ast.Node) !void {
|
||||||
const result = resolveVarDeclFnAlias(analysis_ctx, decl);
|
const result = try resolveVarDeclFnAlias(analysis_ctx, decl);
|
||||||
|
|
||||||
const name_token = analysis.getDeclNameToken(result.analysis_ctx.tree(), result.decl) orelse unreachable;
|
const name_token = analysis.getDeclNameToken(result.analysis_ctx.tree(), result.decl) orelse unreachable;
|
||||||
|
|
||||||
@ -328,7 +334,7 @@ fn gotoDefinitionSymbol(id: i64, analysis_ctx: *DocumentStore.AnalysisContext, d
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn hoverSymbol(id: i64, analysis_ctx: *DocumentStore.AnalysisContext, decl: *std.zig.ast.Node) !void {
|
fn hoverSymbol(id: i64, analysis_ctx: *DocumentStore.AnalysisContext, decl: *std.zig.ast.Node) !void {
|
||||||
const result = resolveVarDeclFnAlias(analysis_ctx, decl);
|
const result = try resolveVarDeclFnAlias(analysis_ctx, decl);
|
||||||
|
|
||||||
const str_value = switch (result.decl.id) {
|
const str_value = switch (result.decl.id) {
|
||||||
.VarDecl => blk: {
|
.VarDecl => blk: {
|
||||||
|
Loading…
Reference in New Issue
Block a user