References working for current file
This commit is contained in:
parent
a699dab2f7
commit
d7ccf6a3c2
@ -413,7 +413,6 @@ pub fn resolveReturnType(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fn_decl.ast.return_type == 0) return null;
|
if (fn_decl.ast.return_type == 0) return null;
|
||||||
log.debug("Ret type: '{s}'", .{tree.nodes.items(.tag)[fn_decl.ast.return_type]});
|
|
||||||
return resolveTypeOfNodeInternal(store, arena, .{
|
return resolveTypeOfNodeInternal(store, arena, .{
|
||||||
.node = fn_decl.ast.return_type,
|
.node = fn_decl.ast.return_type,
|
||||||
.handle = handle,
|
.handle = handle,
|
||||||
@ -639,12 +638,11 @@ pub fn resolveTypeOfNodeInternal(
|
|||||||
.ast_node => |n| {
|
.ast_node => |n| {
|
||||||
if (n == node) return null;
|
if (n == node) return null;
|
||||||
if (varDecl(tree, n)) |var_decl| {
|
if (varDecl(tree, n)) |var_decl| {
|
||||||
if (var_decl.ast.init_node == node) return null;
|
if (var_decl.ast.init_node != 0 and var_decl.ast.init_node == node) return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
log.debug("Resolving child: {s}", .{tree.tokenSlice(child.nameToken())});
|
|
||||||
return try child.resolveType(store, arena, bound_type_params);
|
return try child.resolveType(store, arena, bound_type_params);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -681,7 +679,6 @@ pub fn resolveTypeOfNodeInternal(
|
|||||||
else => unreachable,
|
else => unreachable,
|
||||||
};
|
};
|
||||||
|
|
||||||
log.debug("Call fn expr: {s}", .{node_tags[call.ast.fn_expr]});
|
|
||||||
const decl = (try resolveTypeOfNodeInternal(
|
const decl = (try resolveTypeOfNodeInternal(
|
||||||
store,
|
store,
|
||||||
arena,
|
arena,
|
||||||
@ -694,41 +691,37 @@ pub fn resolveTypeOfNodeInternal(
|
|||||||
.other => |n| n,
|
.other => |n| n,
|
||||||
else => return null,
|
else => return null,
|
||||||
};
|
};
|
||||||
log.debug("CALL: {d} - {d}", .{ call.ast.fn_expr, decl_node });
|
|
||||||
var buf: [1]ast.Node.Index = undefined;
|
var buf: [1]ast.Node.Index = undefined;
|
||||||
const func_maybe = fnProto(tree, decl_node, &buf);
|
const func_maybe = fnProto(decl.handle.tree, decl_node, &buf);
|
||||||
|
|
||||||
if (func_maybe) |fn_decl| {
|
if (func_maybe) |fn_decl| {
|
||||||
// check for x.y(..). if '.' is found, it means first param should be skipped
|
// check for x.y(..). if '.' is found, it means first param should be skipped
|
||||||
const has_self_param = token_tags[call.ast.lparen - 2] == .period;
|
const has_self_param = token_tags[call.ast.lparen - 2] == .period;
|
||||||
var it = fn_decl.iterate(tree);
|
var it = fn_decl.iterate(decl.handle.tree);
|
||||||
|
|
||||||
// Bind type params to the expressions passed in the calls.
|
// Bind type params to the expressions passed in the calls.
|
||||||
const param_len = std.math.min(call.ast.params.len + @boolToInt(has_self_param), fn_decl.ast.params.len);
|
const param_len = std.math.min(call.ast.params.len + @boolToInt(has_self_param), fn_decl.ast.params.len);
|
||||||
while (it.next()) |decl_param| {
|
while (it.next()) |decl_param| {
|
||||||
if (it.param_i == 0 and has_self_param) continue;
|
if (it.param_i == 0 and has_self_param) continue;
|
||||||
if (it.param_i >= param_len) break;
|
if (it.param_i >= param_len) break;
|
||||||
if (!typeIsType(tree, decl_param.type_expr)) continue;
|
if (!typeIsType(decl.handle.tree, decl_param.type_expr)) continue;
|
||||||
|
|
||||||
const call_param_type = (try resolveTypeOfNodeInternal(store, arena, .{
|
const call_param_type = (try resolveTypeOfNodeInternal(store, arena, .{
|
||||||
.node = call.ast.params[it.param_i - @boolToInt(has_self_param)],
|
.node = call.ast.params[it.param_i - @boolToInt(has_self_param)],
|
||||||
.handle = handle,
|
.handle = decl.handle,
|
||||||
}, bound_type_params)) orelse continue;
|
}, bound_type_params)) orelse continue;
|
||||||
if (!call_param_type.type.is_type_val) continue;
|
if (!call_param_type.type.is_type_val) continue;
|
||||||
|
|
||||||
_ = try bound_type_params.put(decl_param, call_param_type);
|
_ = try bound_type_params.put(decl_param, call_param_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
const has_body = node_tags[decl_node] == .fn_decl;
|
const has_body = decl.handle.tree.nodes.items(.tag)[decl_node] == .fn_decl;
|
||||||
const body = datas[decl_node].rhs;
|
const body = decl.handle.tree.nodes.items(.data)[decl_node].rhs;
|
||||||
return try resolveReturnType(store, arena, fn_decl, decl.handle, bound_type_params, if (has_body) body else null);
|
return try resolveReturnType(store, arena, fn_decl, decl.handle, bound_type_params, if (has_body) body else null);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
.@"comptime", .@"nosuspend" => {
|
.@"comptime", .@"nosuspend", .grouped_expression => {
|
||||||
return try resolveTypeOfNodeInternal(store, arena, .{ .node = datas[node].lhs, .handle = handle }, bound_type_params);
|
|
||||||
},
|
|
||||||
.grouped_expression => {
|
|
||||||
return try resolveTypeOfNodeInternal(store, arena, .{ .node = datas[node].lhs, .handle = handle }, bound_type_params);
|
return try resolveTypeOfNodeInternal(store, arena, .{ .node = datas[node].lhs, .handle = handle }, bound_type_params);
|
||||||
},
|
},
|
||||||
.struct_init, .struct_init_comma, .struct_init_one, .struct_init_one_comma => {
|
.struct_init, .struct_init_comma, .struct_init_one, .struct_init_one_comma => {
|
||||||
@ -769,8 +762,9 @@ pub fn resolveTypeOfNodeInternal(
|
|||||||
},
|
},
|
||||||
.field_access => {
|
.field_access => {
|
||||||
const field_access = datas[node];
|
const field_access = datas[node];
|
||||||
const rhs_str = nodeToString(handle.tree, node) orelse return null;
|
|
||||||
|
|
||||||
|
if (datas[node].rhs == 0) return null;
|
||||||
|
const rhs_str = tree.tokenSlice(datas[node].rhs);
|
||||||
// If we are accessing a pointer type, remove one pointerness level :)
|
// If we are accessing a pointer type, remove one pointerness level :)
|
||||||
const left_type = try resolveFieldAccessLhsType(
|
const left_type = try resolveFieldAccessLhsType(
|
||||||
store,
|
store,
|
||||||
@ -786,7 +780,6 @@ pub fn resolveTypeOfNodeInternal(
|
|||||||
.other => |n| n,
|
.other => |n| n,
|
||||||
else => return null,
|
else => return null,
|
||||||
};
|
};
|
||||||
log.debug("Left_type_node: '{s}' for rhs: '{s}'", .{ node_tags[left_type_node], rhs_str });
|
|
||||||
if (try lookupSymbolContainer(
|
if (try lookupSymbolContainer(
|
||||||
store,
|
store,
|
||||||
arena,
|
arena,
|
||||||
@ -794,7 +787,6 @@ pub fn resolveTypeOfNodeInternal(
|
|||||||
rhs_str,
|
rhs_str,
|
||||||
left_type.type.is_type_val,
|
left_type.type.is_type_val,
|
||||||
)) |child| {
|
)) |child| {
|
||||||
log.debug("Found child: '{s}'", .{tree.tokenSlice(child.nameToken())});
|
|
||||||
return try child.resolveType(store, arena, bound_type_params);
|
return try child.resolveType(store, arena, bound_type_params);
|
||||||
} else return null;
|
} else return null;
|
||||||
},
|
},
|
||||||
@ -939,8 +931,9 @@ pub fn resolveTypeOfNodeInternal(
|
|||||||
.type = .{ .data = .{ .other = node }, .is_type_val = false },
|
.type = .{ .data = .{ .other = node }, .is_type_val = false },
|
||||||
.handle = handle,
|
.handle = handle,
|
||||||
},
|
},
|
||||||
|
.root => return TypeWithHandle.typeVal(node_handle),
|
||||||
else => {
|
else => {
|
||||||
log.debug("TODO: implement type resolving for ast tag: {s}", .{node_tags[node]});
|
// log.debug("TODO: implement type resolving for ast tag: {s}", .{node_tags[node]});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -1309,6 +1302,16 @@ pub fn nodeToString(tree: ast.Tree, node: ast.Node.Index) ?[]const u8 {
|
|||||||
=> if (fnProto(tree, node, &buf).?.name_token) |name|
|
=> if (fnProto(tree, node, &buf).?.name_token) |name|
|
||||||
return tree.tokenSlice(name),
|
return tree.tokenSlice(name),
|
||||||
.field_access => return tree.tokenSlice(data[node].rhs),
|
.field_access => return tree.tokenSlice(data[node].rhs),
|
||||||
|
.call,
|
||||||
|
.call_comma,
|
||||||
|
.async_call,
|
||||||
|
.async_call_comma,
|
||||||
|
=> return tree.tokenSlice(tree.callFull(node).ast.lparen - 1),
|
||||||
|
.call_one,
|
||||||
|
.call_one_comma,
|
||||||
|
.async_call_one,
|
||||||
|
.async_call_one_comma,
|
||||||
|
=> return tree.tokenSlice(tree.callOne(&buf, node).ast.lparen - 1),
|
||||||
else => |tag| log.debug("INVALID: {}", .{tag}),
|
else => |tag| log.debug("INVALID: {}", .{tag}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ fn symbolReferencesInternal(
|
|||||||
const node = node_handle.node;
|
const node = node_handle.node;
|
||||||
const handle = node_handle.handle;
|
const handle = node_handle.handle;
|
||||||
const tree = handle.tree;
|
const tree = handle.tree;
|
||||||
|
if (node > tree.nodes.len) return;
|
||||||
const node_tags = tree.nodes.items(.tag);
|
const node_tags = tree.nodes.items(.tag);
|
||||||
const datas = tree.nodes.items(.data);
|
const datas = tree.nodes.items(.data);
|
||||||
const main_tokens = tree.nodes.items(.main_token);
|
const main_tokens = tree.nodes.items(.main_token);
|
||||||
@ -405,7 +406,7 @@ fn symbolReferencesInternal(
|
|||||||
.field_access => {
|
.field_access => {
|
||||||
try symbolReferencesInternal(arena, store, .{ .node = datas[node].lhs, .handle = handle }, decl, encoding, context, handler);
|
try symbolReferencesInternal(arena, store, .{ .node = datas[node].lhs, .handle = handle }, decl, encoding, context, handler);
|
||||||
|
|
||||||
const rhs_str = analysis.nodeToString(handle.tree, node) orelse return;
|
const rhs_str = tree.tokenSlice(datas[node].rhs);
|
||||||
var bound_type_params = analysis.BoundTypeParams.init(&arena.allocator);
|
var bound_type_params = analysis.BoundTypeParams.init(&arena.allocator);
|
||||||
const left_type = try analysis.resolveFieldAccessLhsType(
|
const left_type = try analysis.resolveFieldAccessLhsType(
|
||||||
store,
|
store,
|
||||||
@ -504,9 +505,11 @@ pub fn symbolReferences(
|
|||||||
for (handles.items) |handle| {
|
for (handles.items) |handle| {
|
||||||
if (include_decl and handle == curr_handle) {
|
if (include_decl and handle == curr_handle) {
|
||||||
try tokenReference(curr_handle, decl_handle.nameToken(), encoding, context, handler);
|
try tokenReference(curr_handle, decl_handle.nameToken(), encoding, context, handler);
|
||||||
|
try symbolReferencesInternal(arena, store, .{ .node = 0, .handle = handle }, decl_handle, encoding, context, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
try symbolReferencesInternal(arena, store, .{ .node = 0, .handle = handle }, decl_handle, encoding, context, handler);
|
// @TODO: make references across files working
|
||||||
|
// try symbolReferencesInternal(arena, store, .{ .node = 0, .handle = handle }, decl_handle, encoding, context, handler);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.param_decl => |param| {
|
.param_decl => |param| {
|
||||||
|
Loading…
Reference in New Issue
Block a user