usingnamespace semantics update
+ Ast changes adjustments
This commit is contained in:
171
src/analysis.zig
171
src/analysis.zig
@@ -1,9 +1,10 @@
|
||||
const std = @import("std");
|
||||
const DocumentStore = @import("document_store.zig");
|
||||
const ast = std.zig.ast;
|
||||
const ast = std.zig.Ast;
|
||||
const types = @import("types.zig");
|
||||
const offsets = @import("offsets.zig");
|
||||
const log = std.log.scoped(.analysis);
|
||||
const Analysis = @This();
|
||||
usingnamespace @import("ast.zig");
|
||||
|
||||
var using_trail: std.ArrayList([*]const u8) = undefined;
|
||||
@@ -20,7 +21,7 @@ pub fn deinit() void {
|
||||
/// Gets a declaration's doc comments. Caller owns returned memory.
|
||||
pub fn getDocComments(
|
||||
allocator: *std.mem.Allocator,
|
||||
tree: ast.Tree,
|
||||
tree: Analysis.Tree,
|
||||
node: ast.Node.Index,
|
||||
format: types.MarkupContent.Kind,
|
||||
) !?[]const u8 {
|
||||
@@ -73,7 +74,7 @@ pub fn getDocCommentTokenIndex(tokens: []std.zig.Token.Tag, base_token: ast.Toke
|
||||
|
||||
pub fn collectDocComments(
|
||||
allocator: *std.mem.Allocator,
|
||||
tree: ast.Tree,
|
||||
tree: Analysis.Tree,
|
||||
doc_comments: ast.TokenIndex,
|
||||
format: types.MarkupContent.Kind,
|
||||
container_doc: bool,
|
||||
@@ -94,11 +95,11 @@ pub fn collectDocComments(
|
||||
}
|
||||
|
||||
/// Gets a function's keyword, name, arguments and return value.
|
||||
pub fn getFunctionSignature(tree: ast.Tree, func: ast.full.FnProto) []const u8 {
|
||||
pub fn getFunctionSignature(tree: Analysis.Tree, func: ast.full.FnProto) []const u8 {
|
||||
const start = offsets.tokenLocation(tree, func.ast.fn_token);
|
||||
|
||||
const end = if (func.ast.return_type != 0)
|
||||
offsets.tokenLocation(tree, lastToken(tree, func.ast.return_type))
|
||||
offsets.tokenLocation(tree, Analysis.lastToken(tree, func.ast.return_type))
|
||||
else
|
||||
start;
|
||||
return tree.source[start.start..end.end];
|
||||
@@ -107,7 +108,7 @@ pub fn getFunctionSignature(tree: ast.Tree, func: ast.full.FnProto) []const u8 {
|
||||
/// Creates snippet insert text for a function. Caller owns returned memory.
|
||||
pub fn getFunctionSnippet(
|
||||
allocator: *std.mem.Allocator,
|
||||
tree: ast.Tree,
|
||||
tree: Analysis.Tree,
|
||||
func: ast.full.FnProto,
|
||||
skip_self_param: bool,
|
||||
) ![]const u8 {
|
||||
@@ -153,7 +154,7 @@ pub fn getFunctionSnippet(
|
||||
try buffer.appendSlice("...");
|
||||
} else if (param.type_expr != 0) {
|
||||
var curr_token = tree.firstToken(param.type_expr);
|
||||
var end_token = lastToken(tree, param.type_expr);
|
||||
var end_token = Analysis.lastToken(tree, param.type_expr);
|
||||
while (curr_token <= end_token) : (curr_token += 1) {
|
||||
const tag = token_tags[curr_token];
|
||||
const is_comma = tag == .comma;
|
||||
@@ -210,32 +211,32 @@ pub fn hasSelfParam(
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn getVariableSignature(tree: ast.Tree, var_decl: ast.full.VarDecl) []const u8 {
|
||||
pub fn getVariableSignature(tree: Analysis.Tree, var_decl: ast.full.VarDecl) []const u8 {
|
||||
const start = offsets.tokenLocation(tree, var_decl.ast.mut_token).start;
|
||||
const end = offsets.tokenLocation(tree, lastToken(tree, var_decl.ast.init_node)).end;
|
||||
const end = offsets.tokenLocation(tree, Analysis.lastToken(tree, var_decl.ast.init_node)).end;
|
||||
return tree.source[start..end];
|
||||
}
|
||||
|
||||
pub fn getContainerFieldSignature(tree: ast.Tree, field: ast.full.ContainerField) []const u8 {
|
||||
pub fn getContainerFieldSignature(tree: Analysis.Tree, field: ast.full.ContainerField) []const u8 {
|
||||
const start = offsets.tokenLocation(tree, field.ast.name_token).start;
|
||||
const end_node = if (field.ast.value_expr != 0) field.ast.value_expr else field.ast.type_expr;
|
||||
const end = offsets.tokenLocation(tree, lastToken(tree, end_node)).end;
|
||||
const end = offsets.tokenLocation(tree, Analysis.lastToken(tree, end_node)).end;
|
||||
return tree.source[start..end];
|
||||
}
|
||||
|
||||
/// The node is the meta-type `type`
|
||||
fn isMetaType(tree: ast.Tree, node: ast.Node.Index) bool {
|
||||
fn isMetaType(tree: Analysis.Tree, node: ast.Node.Index) bool {
|
||||
if (tree.nodes.items(.tag)[node] == .identifier) {
|
||||
return std.mem.eql(u8, tree.tokenSlice(tree.nodes.items(.main_token)[node]), "type");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn isTypeFunction(tree: ast.Tree, func: ast.full.FnProto) bool {
|
||||
pub fn isTypeFunction(tree: Analysis.Tree, func: ast.full.FnProto) bool {
|
||||
return isMetaType(tree, func.ast.return_type);
|
||||
}
|
||||
|
||||
pub fn isGenericFunction(tree: ast.Tree, func: ast.full.FnProto) bool {
|
||||
pub fn isGenericFunction(tree: Analysis.Tree, func: ast.full.FnProto) bool {
|
||||
var it = func.iterate(tree);
|
||||
while (it.next()) |param| {
|
||||
if (param.anytype_ellipsis3 != null or param.comptime_noalias != null) {
|
||||
@@ -261,7 +262,7 @@ pub fn isSnakeCase(name: []const u8) bool {
|
||||
|
||||
// ANALYSIS ENGINE
|
||||
|
||||
pub fn getDeclNameToken(tree: ast.Tree, node: ast.Node.Index) ?ast.TokenIndex {
|
||||
pub fn getDeclNameToken(tree: Analysis.Tree, node: ast.Node.Index) ?ast.TokenIndex {
|
||||
const tags = tree.nodes.items(.tag);
|
||||
const main_token = tree.nodes.items(.main_token)[node];
|
||||
return switch (tags[node]) {
|
||||
@@ -278,7 +279,7 @@ pub fn getDeclNameToken(tree: ast.Tree, node: ast.Node.Index) ?ast.TokenIndex {
|
||||
.fn_decl,
|
||||
=> blk: {
|
||||
var params: [1]ast.Node.Index = undefined;
|
||||
break :blk fnProto(tree, node, ¶ms).?.name_token;
|
||||
break :blk Analysis.fnProto(tree, node, ¶ms).?.name_token;
|
||||
},
|
||||
|
||||
// containers
|
||||
@@ -298,7 +299,7 @@ pub fn getDeclNameToken(tree: ast.Tree, node: ast.Node.Index) ?ast.TokenIndex {
|
||||
};
|
||||
}
|
||||
|
||||
fn getDeclName(tree: ast.Tree, node: ast.Node.Index) ?[]const u8 {
|
||||
fn getDeclName(tree: Analysis.Tree, node: ast.Node.Index) ?[]const u8 {
|
||||
const name = tree.tokenSlice(getDeclNameToken(tree, node) orelse return null);
|
||||
return switch (tree.nodes.items(.tag)[node]) {
|
||||
.test_decl => name[1 .. name.len - 1],
|
||||
@@ -308,7 +309,7 @@ fn getDeclName(tree: ast.Tree, node: ast.Node.Index) ?[]const u8 {
|
||||
|
||||
fn isContainerDecl(decl_handle: DeclWithHandle) bool {
|
||||
return switch (decl_handle.decl.*) {
|
||||
.ast_node => |inner_node| isContainer(decl_handle.handle.tree.nodes.items(.tag)[inner_node]),
|
||||
.ast_node => |inner_node| Analysis.isContainer(decl_handle.handle.tree.nodes.items(.tag)[inner_node]),
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
@@ -340,7 +341,7 @@ fn resolveVarDeclAliasInternal(
|
||||
if (node_tags[node_handle.node] == .field_access) {
|
||||
const lhs = datas[node_handle.node].lhs;
|
||||
|
||||
const container_node = if (isBuiltinCall(tree, lhs)) block: {
|
||||
const container_node = if (Analysis.isBuiltinCall(tree, lhs)) block: {
|
||||
if (!std.mem.eql(u8, tree.tokenSlice(main_tokens[lhs]), "@import"))
|
||||
return null;
|
||||
|
||||
@@ -355,7 +356,7 @@ fn resolveVarDeclAliasInternal(
|
||||
.other => |n| n,
|
||||
else => return null,
|
||||
};
|
||||
if (!isContainer(resolved.handle.tree, resolved_node)) return null;
|
||||
if (!Analysis.isContainer(resolved.handle.tree, resolved_node)) return null;
|
||||
break :block NodeWithHandle{ .node = resolved_node, .handle = resolved.handle };
|
||||
} else return null;
|
||||
|
||||
@@ -377,7 +378,7 @@ pub fn resolveVarDeclAlias(store: *DocumentStore, arena: *std.heap.ArenaAllocato
|
||||
const token_tags = tree.tokens.items(.tag);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
|
||||
if (varDecl(handle.tree, decl)) |var_decl| {
|
||||
if (Analysis.varDecl(handle.tree, decl)) |var_decl| {
|
||||
if (var_decl.ast.init_node == 0) return null;
|
||||
const base_exp = var_decl.ast.init_node;
|
||||
if (token_tags[var_decl.ast.mut_token] != .keyword_const) return null;
|
||||
@@ -394,7 +395,7 @@ pub fn resolveVarDeclAlias(store: *DocumentStore, arena: *std.heap.ArenaAllocato
|
||||
return null;
|
||||
}
|
||||
|
||||
fn isBlock(tree: ast.Tree, node: ast.Node.Index) bool {
|
||||
fn isBlock(tree: Analysis.Tree, node: ast.Node.Index) bool {
|
||||
return switch (tree.nodes.items(.tag)[node]) {
|
||||
.block,
|
||||
.block_semicolon,
|
||||
@@ -406,7 +407,7 @@ fn isBlock(tree: ast.Tree, node: ast.Node.Index) bool {
|
||||
}
|
||||
|
||||
fn findReturnStatementInternal(
|
||||
tree: ast.Tree,
|
||||
tree: Analysis.Tree,
|
||||
fn_decl: ast.full.FnProto,
|
||||
body: ast.Node.Index,
|
||||
already_found: *bool,
|
||||
@@ -437,7 +438,7 @@ fn findReturnStatementInternal(
|
||||
if (node_tags[child_idx] == .@"return") {
|
||||
if (datas[child_idx].lhs != 0) {
|
||||
const lhs = datas[child_idx].lhs;
|
||||
if (isCall(tree, lhs)) {
|
||||
if (Analysis.isCall(tree, lhs)) {
|
||||
const call_name = getDeclName(tree, datas[lhs].lhs);
|
||||
if (call_name) |name| {
|
||||
if (std.mem.eql(u8, name, tree.tokenSlice(fn_decl.name_token.?))) {
|
||||
@@ -459,7 +460,7 @@ fn findReturnStatementInternal(
|
||||
return result;
|
||||
}
|
||||
|
||||
fn findReturnStatement(tree: ast.Tree, fn_decl: ast.full.FnProto, body: ast.Node.Index) ?ast.Node.Index {
|
||||
fn findReturnStatement(tree: Analysis.Tree, fn_decl: ast.full.FnProto, body: ast.Node.Index) ?ast.Node.Index {
|
||||
var already_found = false;
|
||||
return findReturnStatementInternal(tree, fn_decl, body, &already_found);
|
||||
}
|
||||
@@ -554,7 +555,7 @@ fn resolveUnwrapErrorType(
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn isPtrType(tree: ast.Tree, node: ast.Node.Index) bool {
|
||||
pub fn isPtrType(tree: Analysis.Tree, node: ast.Node.Index) bool {
|
||||
return switch (tree.nodes.items(.tag)[node]) {
|
||||
.ptr_type,
|
||||
.ptr_type_aligned,
|
||||
@@ -588,7 +589,7 @@ fn resolveDerefType(
|
||||
const token_tag = tree.tokens.items(.tag)[main_token];
|
||||
|
||||
if (isPtrType(tree, deref_node)) {
|
||||
const ptr_type = ptrType(tree, deref_node).?;
|
||||
const ptr_type = Analysis.ptrType(tree, deref_node).?;
|
||||
switch (token_tag) {
|
||||
.asterisk => {
|
||||
return ((try resolveTypeOfNodeInternal(store, arena, .{
|
||||
@@ -631,7 +632,7 @@ fn resolveBracketAccessType(
|
||||
.type = .{ .data = .{ .slice = data.rhs }, .is_type_val = false },
|
||||
.handle = lhs.handle,
|
||||
};
|
||||
} else if (ptrType(tree, lhs_node)) |ptr_type| {
|
||||
} else if (Analysis.ptrType(tree, lhs_node)) |ptr_type| {
|
||||
if (ptr_type.size == .Slice) {
|
||||
if (rhs == .Single) {
|
||||
return ((try resolveTypeOfNodeInternal(store, arena, .{
|
||||
@@ -665,7 +666,7 @@ fn allDigits(str: []const u8) bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn isTypeIdent(tree: ast.Tree, token_idx: ast.TokenIndex) bool {
|
||||
pub fn isTypeIdent(tree: Analysis.Tree, token_idx: ast.TokenIndex) bool {
|
||||
const PrimitiveTypes = std.ComptimeStringMap(void, .{
|
||||
.{"isize"}, .{"usize"},
|
||||
.{"c_short"}, .{"c_ushort"},
|
||||
@@ -721,7 +722,7 @@ pub fn resolveTypeOfNodeInternal(
|
||||
.simple_var_decl,
|
||||
.aligned_var_decl,
|
||||
=> {
|
||||
const var_decl = varDecl(tree, node).?;
|
||||
const var_decl = Analysis.varDecl(tree, node).?;
|
||||
if (var_decl.ast.type_node != 0) {
|
||||
const decl_type = .{ .node = var_decl.ast.type_node, .handle = handle };
|
||||
if (try resolveTypeOfNodeInternal(store, arena, decl_type, bound_type_params)) |typ|
|
||||
@@ -751,7 +752,7 @@ pub fn resolveTypeOfNodeInternal(
|
||||
switch (child.decl.*) {
|
||||
.ast_node => |n| {
|
||||
if (n == node) return null;
|
||||
if (varDecl(child.handle.tree, n)) |var_decl| {
|
||||
if (Analysis.varDecl(child.handle.tree, n)) |var_decl| {
|
||||
if (var_decl.ast.init_node == node)
|
||||
return null;
|
||||
}
|
||||
@@ -772,7 +773,7 @@ pub fn resolveTypeOfNodeInternal(
|
||||
.async_call_one_comma,
|
||||
=> {
|
||||
var params: [1]ast.Node.Index = undefined;
|
||||
const call = callFull(tree, node, ¶ms) orelse unreachable;
|
||||
const call = Analysis.callFull(tree, node, ¶ms) orelse unreachable;
|
||||
|
||||
const callee = .{ .node = call.ast.fn_expr, .handle = handle };
|
||||
const decl = (try resolveTypeOfNodeInternal(store, arena, callee, bound_type_params)) orelse
|
||||
@@ -784,7 +785,7 @@ pub fn resolveTypeOfNodeInternal(
|
||||
else => return null,
|
||||
};
|
||||
var buf: [1]ast.Node.Index = undefined;
|
||||
const func_maybe = fnProto(decl.handle.tree, decl_node, &buf);
|
||||
const func_maybe = Analysis.fnProto(decl.handle.tree, decl_node, &buf);
|
||||
|
||||
if (func_maybe) |fn_decl| {
|
||||
var expected_params = fn_decl.ast.params.len;
|
||||
@@ -1015,7 +1016,7 @@ pub fn resolveTypeOfNodeInternal(
|
||||
=> {
|
||||
var buf: [1]ast.Node.Index = undefined;
|
||||
// This is a function type
|
||||
if (fnProto(tree, node, &buf).?.name_token == null) {
|
||||
if (Analysis.fnProto(tree, node, &buf).?.name_token == null) {
|
||||
return TypeWithHandle.typeVal(node_handle);
|
||||
}
|
||||
|
||||
@@ -1098,9 +1099,9 @@ pub const TypeWithHandle = struct {
|
||||
const tree = self.handle.tree;
|
||||
const node = self.type.data.other;
|
||||
const tags = tree.nodes.items(.tag);
|
||||
if (isContainer(tree, node)) {
|
||||
if (Analysis.isContainer(tree, node)) {
|
||||
var buf: [2]ast.Node.Index = undefined;
|
||||
for (declMembers(tree, node, &buf)) |child| {
|
||||
for (Analysis.declMembers(tree, node, &buf)) |child| {
|
||||
if (tags[child].isContainerField()) return false;
|
||||
}
|
||||
}
|
||||
@@ -1123,7 +1124,7 @@ pub const TypeWithHandle = struct {
|
||||
var buf: [1]ast.Node.Index = undefined;
|
||||
const tree = self.handle.tree;
|
||||
return switch (self.type.data) {
|
||||
.other => |n| if (fnProto(tree, n, &buf)) |fn_proto| blk: {
|
||||
.other => |n| if (Analysis.fnProto(tree, n, &buf)) |fn_proto| blk: {
|
||||
break :blk isTypeFunction(tree, fn_proto);
|
||||
} else false,
|
||||
else => false,
|
||||
@@ -1134,7 +1135,7 @@ pub const TypeWithHandle = struct {
|
||||
var buf: [1]ast.Node.Index = undefined;
|
||||
const tree = self.handle.tree;
|
||||
return switch (self.type.data) {
|
||||
.other => |n| if (fnProto(tree, n, &buf)) |fn_proto| blk: {
|
||||
.other => |n| if (Analysis.fnProto(tree, n, &buf)) |fn_proto| blk: {
|
||||
break :blk isGenericFunction(tree, fn_proto);
|
||||
} else false,
|
||||
else => false,
|
||||
@@ -1165,7 +1166,7 @@ pub fn resolveTypeOfNode(store: *DocumentStore, arena: *std.heap.ArenaAllocator,
|
||||
}
|
||||
|
||||
/// Collects all imports we can find into a slice of import paths (without quotes).
|
||||
pub fn collectImports(import_arr: *std.ArrayList([]const u8), tree: ast.Tree) !void {
|
||||
pub fn collectImports(import_arr: *std.ArrayList([]const u8), tree: Analysis.Tree) !void {
|
||||
const tags = tree.tokens.items(.tag);
|
||||
|
||||
var i: usize = 0;
|
||||
@@ -1303,7 +1304,7 @@ pub fn getFieldAccessType(
|
||||
if (current_type.type.is_type_val) return null;
|
||||
const cur_tree = current_type.handle.tree;
|
||||
var buf: [1]ast.Node.Index = undefined;
|
||||
if (fnProto(cur_tree, current_type_node, &buf)) |func| {
|
||||
if (Analysis.fnProto(cur_tree, current_type_node, &buf)) |func| {
|
||||
// Check if the function has a body and if so, pass it
|
||||
// so the type can be resolved if it's a generic function returning
|
||||
// an anonymous struct
|
||||
@@ -1357,25 +1358,25 @@ pub fn getFieldAccessType(
|
||||
};
|
||||
}
|
||||
|
||||
pub fn isNodePublic(tree: ast.Tree, node: ast.Node.Index) bool {
|
||||
pub fn isNodePublic(tree: Analysis.Tree, node: ast.Node.Index) bool {
|
||||
var buf: [1]ast.Node.Index = undefined;
|
||||
return switch (tree.nodes.items(.tag)[node]) {
|
||||
.global_var_decl,
|
||||
.local_var_decl,
|
||||
.simple_var_decl,
|
||||
.aligned_var_decl,
|
||||
=> varDecl(tree, node).?.visib_token != null,
|
||||
=> Analysis.varDecl(tree, node).?.visib_token != null,
|
||||
.fn_proto,
|
||||
.fn_proto_multi,
|
||||
.fn_proto_one,
|
||||
.fn_proto_simple,
|
||||
.fn_decl,
|
||||
=> fnProto(tree, node, &buf).?.visib_token != null,
|
||||
=> Analysis.fnProto(tree, node, &buf).?.visib_token != null,
|
||||
else => true,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn nodeToString(tree: ast.Tree, node: ast.Node.Index) ?[]const u8 {
|
||||
pub fn nodeToString(tree: Analysis.Tree, node: ast.Node.Index) ?[]const u8 {
|
||||
const data = tree.nodes.items(.data);
|
||||
const main_token = tree.nodes.items(.main_token)[node];
|
||||
var buf: [1]ast.Node.Index = undefined;
|
||||
@@ -1390,7 +1391,7 @@ pub fn nodeToString(tree: ast.Tree, node: ast.Node.Index) ?[]const u8 {
|
||||
.fn_proto_one,
|
||||
.fn_proto_simple,
|
||||
.fn_decl,
|
||||
=> if (fnProto(tree, node, &buf).?.name_token) |name|
|
||||
=> if (Analysis.fnProto(tree, node, &buf).?.name_token) |name|
|
||||
return tree.tokenSlice(name),
|
||||
.field_access => return tree.tokenSlice(data[node].rhs),
|
||||
.call,
|
||||
@@ -1411,24 +1412,24 @@ pub fn nodeToString(tree: ast.Tree, node: ast.Node.Index) ?[]const u8 {
|
||||
return null;
|
||||
}
|
||||
|
||||
fn nodeContainsSourceIndex(tree: ast.Tree, node: ast.Node.Index, source_index: usize) bool {
|
||||
fn nodeContainsSourceIndex(tree: Analysis.Tree, node: ast.Node.Index, source_index: usize) bool {
|
||||
const first_token = offsets.tokenLocation(tree, tree.firstToken(node)).start;
|
||||
const last_token = offsets.tokenLocation(tree, lastToken(tree, node)).end;
|
||||
const last_token = offsets.tokenLocation(tree, Analysis.lastToken(tree, node)).end;
|
||||
return source_index >= first_token and source_index <= last_token;
|
||||
}
|
||||
|
||||
pub fn getImportStr(tree: ast.Tree, node: ast.Node.Index, source_index: usize) ?[]const u8 {
|
||||
pub fn getImportStr(tree: Analysis.Tree, node: ast.Node.Index, source_index: usize) ?[]const u8 {
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
var buf: [2]ast.Node.Index = undefined;
|
||||
if (isContainer(tree, node)) {
|
||||
const decls = declMembers(tree, node, &buf);
|
||||
if (Analysis.isContainer(tree, node)) {
|
||||
const decls = Analysis.declMembers(tree, node, &buf);
|
||||
for (decls) |decl_idx| {
|
||||
if (getImportStr(tree, decl_idx, source_index)) |name| {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} else if (varDecl(tree, node)) |var_decl| {
|
||||
} else if (Analysis.varDecl(tree, node)) |var_decl| {
|
||||
return getImportStr(tree, var_decl.ast.init_node, source_index);
|
||||
} else if (node_tags[node] == .@"usingnamespace") {
|
||||
return getImportStr(tree, tree.nodes.items(.data)[node].lhs, source_index);
|
||||
@@ -1438,7 +1439,7 @@ pub fn getImportStr(tree: ast.Tree, node: ast.Node.Index, source_index: usize) ?
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isBuiltinCall(tree, node)) {
|
||||
if (Analysis.isBuiltinCall(tree, node)) {
|
||||
const builtin_token = tree.nodes.items(.main_token)[node];
|
||||
const call_name = tree.tokenSlice(builtin_token);
|
||||
|
||||
@@ -1656,7 +1657,7 @@ pub fn documentPositionContext(
|
||||
};
|
||||
}
|
||||
|
||||
fn addOutlineNodes(allocator: *std.mem.Allocator, tree: ast.Tree, child: ast.Node.Index, context: *GetDocumentSymbolsContext) anyerror!void {
|
||||
fn addOutlineNodes(allocator: *std.mem.Allocator, tree: Analysis.Tree, child: ast.Node.Index, context: *GetDocumentSymbolsContext) anyerror!void {
|
||||
switch (tree.nodes.items(.tag)[child]) {
|
||||
.string_literal,
|
||||
.integer_literal,
|
||||
@@ -1788,7 +1789,7 @@ fn addOutlineNodes(allocator: *std.mem.Allocator, tree: ast.Tree, child: ast.Nod
|
||||
.tagged_union_two_trailing,
|
||||
=> {
|
||||
var buf: [2]ast.Node.Index = undefined;
|
||||
for (declMembers(tree, child, &buf)) |member|
|
||||
for (Analysis.declMembers(tree, child, &buf)) |member|
|
||||
try addOutlineNodes(allocator, tree, member, context);
|
||||
return;
|
||||
},
|
||||
@@ -1809,7 +1810,7 @@ const GetDocumentSymbolsContext = struct {
|
||||
|
||||
fn getDocumentSymbolsInternal(
|
||||
allocator: *std.mem.Allocator,
|
||||
tree: ast.Tree,
|
||||
tree: Analysis.Tree,
|
||||
node: ast.Node.Index,
|
||||
context: *GetDocumentSymbolsContext,
|
||||
) anyerror!void {
|
||||
@@ -1827,7 +1828,7 @@ fn getDocumentSymbolsInternal(
|
||||
const end_loc = start_loc.add(try offsets.tokenRelativeLocation(
|
||||
tree,
|
||||
start_loc.offset,
|
||||
starts[lastToken(tree, node)],
|
||||
starts[Analysis.lastToken(tree, node)],
|
||||
context.encoding,
|
||||
));
|
||||
context.prev_loc = end_loc;
|
||||
@@ -1881,13 +1882,13 @@ fn getDocumentSymbolsInternal(
|
||||
.encoding = context.encoding,
|
||||
};
|
||||
|
||||
if (isContainer(tree, node)) {
|
||||
if (Analysis.isContainer(tree, node)) {
|
||||
var buf: [2]ast.Node.Index = undefined;
|
||||
for (declMembers(tree, node, &buf)) |child|
|
||||
for (Analysis.declMembers(tree, node, &buf)) |child|
|
||||
try addOutlineNodes(allocator, tree, child, &child_context);
|
||||
}
|
||||
|
||||
if (varDecl(tree, node)) |var_decl| {
|
||||
if (Analysis.varDecl(tree, node)) |var_decl| {
|
||||
if (var_decl.ast.init_node != 0)
|
||||
try addOutlineNodes(allocator, tree, var_decl.ast.init_node, &child_context);
|
||||
}
|
||||
@@ -1896,7 +1897,7 @@ fn getDocumentSymbolsInternal(
|
||||
};
|
||||
}
|
||||
|
||||
pub fn getDocumentSymbols(allocator: *std.mem.Allocator, tree: ast.Tree, encoding: offsets.Encoding) ![]types.DocumentSymbol {
|
||||
pub fn getDocumentSymbols(allocator: *std.mem.Allocator, tree: Analysis.Tree, encoding: offsets.Encoding) ![]types.DocumentSymbol {
|
||||
var symbols = try std.ArrayList(types.DocumentSymbol).initCapacity(allocator, tree.rootDecls().len);
|
||||
|
||||
var context = GetDocumentSymbolsContext{
|
||||
@@ -2032,7 +2033,7 @@ pub const DeclWithHandle = struct {
|
||||
if (scope.decls.getEntry(tree.tokenSlice(main_tokens[pay.items[0]]))) |candidate| {
|
||||
switch (candidate.value_ptr.*) {
|
||||
.ast_node => |node| {
|
||||
if (containerField(switch_expr_type.handle.tree, node)) |container_field| {
|
||||
if (Analysis.containerField(switch_expr_type.handle.tree, node)) |container_field| {
|
||||
if (container_field.ast.type_expr != 0) {
|
||||
return ((try resolveTypeOfNodeInternal(
|
||||
store,
|
||||
@@ -2058,7 +2059,7 @@ fn findContainerScope(container_handle: NodeWithHandle) ?*Scope {
|
||||
const container = container_handle.node;
|
||||
const handle = container_handle.handle;
|
||||
|
||||
if (!isContainer(handle.tree, container)) return null;
|
||||
if (!Analysis.isContainer(handle.tree, container)) return null;
|
||||
|
||||
// Find the container scope.
|
||||
return for (handle.document_scope.scopes) |*scope| {
|
||||
@@ -2460,7 +2461,7 @@ pub const DocumentScope = struct {
|
||||
while (decl_it.next()) |_| : (idx += 1) {
|
||||
if (idx != 0) log.debug(", ", .{});
|
||||
}
|
||||
log.debug("{s}", .{name_decl.key});
|
||||
// log.debug("{s}", .{name_decl.key});
|
||||
log.debug("\n--------------------------\n", .{});
|
||||
}
|
||||
}
|
||||
@@ -2506,7 +2507,7 @@ pub const Scope = struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub fn makeDocumentScope(allocator: *std.mem.Allocator, tree: ast.Tree) !DocumentScope {
|
||||
pub fn makeDocumentScope(allocator: *std.mem.Allocator, tree: Analysis.Tree) !DocumentScope {
|
||||
var scopes = std.ArrayListUnmanaged(Scope){};
|
||||
var error_completions = CompletionSet{};
|
||||
var enum_completions = CompletionSet{};
|
||||
@@ -2537,9 +2538,9 @@ pub fn makeDocumentScope(allocator: *std.mem.Allocator, tree: ast.Tree) !Documen
|
||||
};
|
||||
}
|
||||
|
||||
fn nodeSourceRange(tree: ast.Tree, node: ast.Node.Index) SourceRange {
|
||||
fn nodeSourceRange(tree: Analysis.Tree, node: ast.Node.Index) SourceRange {
|
||||
const loc_start = offsets.tokenLocation(tree, tree.firstToken(node));
|
||||
const loc_end = offsets.tokenLocation(tree, lastToken(tree, node));
|
||||
const loc_end = offsets.tokenLocation(tree, Analysis.lastToken(tree, node));
|
||||
|
||||
return SourceRange{
|
||||
.start = loc_start.start,
|
||||
@@ -2551,7 +2552,7 @@ const ScopeContext = struct {
|
||||
scopes: *std.ArrayListUnmanaged(Scope),
|
||||
enums: *CompletionSet,
|
||||
errors: *CompletionSet,
|
||||
tree: ast.Tree,
|
||||
tree: Analysis.Tree,
|
||||
};
|
||||
|
||||
fn makeInnerScope(
|
||||
@@ -2568,7 +2569,7 @@ fn makeInnerScope(
|
||||
const node_tag = tags[node_idx];
|
||||
|
||||
var buf: [2]ast.Node.Index = undefined;
|
||||
const ast_decls = declMembers(tree, node_idx, &buf);
|
||||
const ast_decls = Analysis.declMembers(tree, node_idx, &buf);
|
||||
|
||||
(try scopes.addOne(allocator)).* = .{
|
||||
.range = nodeSourceRange(tree, node_idx),
|
||||
@@ -2723,7 +2724,7 @@ fn makeScopeInternal(
|
||||
.fn_decl,
|
||||
=> |fn_tag| {
|
||||
var buf: [1]ast.Node.Index = undefined;
|
||||
const func = fnProto(tree, node_idx, &buf).?;
|
||||
const func = Analysis.fnProto(tree, node_idx, &buf).?;
|
||||
|
||||
(try scopes.addOne(allocator)).* = .{
|
||||
.range = nodeSourceRange(tree, node_idx),
|
||||
@@ -2770,7 +2771,7 @@ fn makeScopeInternal(
|
||||
.block_two_semicolon,
|
||||
=> {
|
||||
const first_token = tree.firstToken(node_idx);
|
||||
const last_token = lastToken(tree, node_idx);
|
||||
const last_token = Analysis.lastToken(tree, node_idx);
|
||||
|
||||
// if labeled block
|
||||
if (token_tags[first_token] == .identifier) {
|
||||
@@ -2823,7 +2824,7 @@ fn makeScopeInternal(
|
||||
}
|
||||
|
||||
try makeScopeInternal(allocator, context, idx);
|
||||
if (varDecl(tree, idx)) |var_decl| {
|
||||
if (Analysis.varDecl(tree, idx)) |var_decl| {
|
||||
const name = tree.tokenSlice(var_decl.ast.mut_token + 1);
|
||||
if (try scopes.items[scope_idx].decls.fetchPut(name, .{ .ast_node = idx })) |existing| {
|
||||
_ = existing;
|
||||
@@ -2838,14 +2839,14 @@ fn makeScopeInternal(
|
||||
.@"if",
|
||||
.if_simple,
|
||||
=> {
|
||||
const if_node = ifFull(tree, node_idx);
|
||||
const if_node = Analysis.ifFull(tree, node_idx);
|
||||
|
||||
if (if_node.payload_token) |payload| {
|
||||
var scope = try scopes.addOne(allocator);
|
||||
scope.* = .{
|
||||
.range = .{
|
||||
.start = offsets.tokenLocation(tree, payload).start,
|
||||
.end = offsets.tokenLocation(tree, lastToken(tree, if_node.ast.then_expr)).end,
|
||||
.end = offsets.tokenLocation(tree, Analysis.lastToken(tree, if_node.ast.then_expr)).end,
|
||||
},
|
||||
.decls = std.StringHashMap(Declaration).init(allocator),
|
||||
.data = .other,
|
||||
@@ -2873,7 +2874,7 @@ fn makeScopeInternal(
|
||||
scope.* = .{
|
||||
.range = .{
|
||||
.start = offsets.tokenLocation(tree, err_token).start,
|
||||
.end = offsets.tokenLocation(tree, lastToken(tree, if_node.ast.else_expr)).end,
|
||||
.end = offsets.tokenLocation(tree, Analysis.lastToken(tree, if_node.ast.else_expr)).end,
|
||||
},
|
||||
.decls = std.StringHashMap(Declaration).init(allocator),
|
||||
.data = .other,
|
||||
@@ -2896,7 +2897,7 @@ fn makeScopeInternal(
|
||||
scope.* = .{
|
||||
.range = .{
|
||||
.start = offsets.tokenLocation(tree, tree.firstToken(catch_expr)).start,
|
||||
.end = offsets.tokenLocation(tree, lastToken(tree, catch_expr)).end,
|
||||
.end = offsets.tokenLocation(tree, Analysis.lastToken(tree, catch_expr)).end,
|
||||
},
|
||||
.decls = std.StringHashMap(Declaration).init(allocator),
|
||||
.data = .other,
|
||||
@@ -2918,7 +2919,7 @@ fn makeScopeInternal(
|
||||
.@"for",
|
||||
.for_simple,
|
||||
=> {
|
||||
const while_node = whileAst(tree, node_idx).?;
|
||||
const while_node = Analysis.whileAst(tree, node_idx).?;
|
||||
const is_for = node_tag == .@"for" or node_tag == .for_simple;
|
||||
|
||||
if (while_node.label_token) |label| {
|
||||
@@ -2927,7 +2928,7 @@ fn makeScopeInternal(
|
||||
scope.* = .{
|
||||
.range = .{
|
||||
.start = offsets.tokenLocation(tree, while_node.ast.while_token).start,
|
||||
.end = offsets.tokenLocation(tree, lastToken(tree, node_idx)).end,
|
||||
.end = offsets.tokenLocation(tree, Analysis.lastToken(tree, node_idx)).end,
|
||||
},
|
||||
.decls = std.StringHashMap(Declaration).init(allocator),
|
||||
.data = .other,
|
||||
@@ -2942,7 +2943,7 @@ fn makeScopeInternal(
|
||||
scope.* = .{
|
||||
.range = .{
|
||||
.start = offsets.tokenLocation(tree, payload).start,
|
||||
.end = offsets.tokenLocation(tree, lastToken(tree, while_node.ast.then_expr)).end,
|
||||
.end = offsets.tokenLocation(tree, Analysis.lastToken(tree, while_node.ast.then_expr)).end,
|
||||
},
|
||||
.decls = std.StringHashMap(Declaration).init(allocator),
|
||||
.data = .other,
|
||||
@@ -2987,7 +2988,7 @@ fn makeScopeInternal(
|
||||
scope.* = .{
|
||||
.range = .{
|
||||
.start = offsets.tokenLocation(tree, err_token).start,
|
||||
.end = offsets.tokenLocation(tree, lastToken(tree, while_node.ast.else_expr)).end,
|
||||
.end = offsets.tokenLocation(tree, Analysis.lastToken(tree, while_node.ast.else_expr)).end,
|
||||
},
|
||||
.decls = std.StringHashMap(Declaration).init(allocator),
|
||||
.data = .other,
|
||||
@@ -3019,7 +3020,7 @@ fn makeScopeInternal(
|
||||
scope.* = .{
|
||||
.range = .{
|
||||
.start = offsets.tokenLocation(tree, payload).start,
|
||||
.end = offsets.tokenLocation(tree, lastToken(tree, switch_case.ast.target_expr)).end,
|
||||
.end = offsets.tokenLocation(tree, Analysis.lastToken(tree, switch_case.ast.target_expr)).end,
|
||||
},
|
||||
.decls = std.StringHashMap(Declaration).init(allocator),
|
||||
.data = .other,
|
||||
@@ -3053,7 +3054,7 @@ fn makeScopeInternal(
|
||||
.aligned_var_decl,
|
||||
.simple_var_decl,
|
||||
=> {
|
||||
const var_decl = varDecl(tree, node_idx).?;
|
||||
const var_decl = Analysis.varDecl(tree, node_idx).?;
|
||||
if (var_decl.ast.type_node != 0) {
|
||||
try makeScopeInternal(allocator, context, var_decl.ast.type_node);
|
||||
}
|
||||
@@ -3072,7 +3073,7 @@ fn makeScopeInternal(
|
||||
.async_call_one_comma,
|
||||
=> {
|
||||
var buf: [1]ast.Node.Index = undefined;
|
||||
const call = callFull(tree, node_idx, &buf).?;
|
||||
const call = Analysis.callFull(tree, node_idx, &buf).?;
|
||||
|
||||
try makeScopeInternal(allocator, context, call.ast.fn_expr);
|
||||
for (call.ast.params) |param|
|
||||
@@ -3131,7 +3132,7 @@ fn makeScopeInternal(
|
||||
.container_field_align,
|
||||
.container_field_init,
|
||||
=> {
|
||||
const field = containerField(tree, node_idx).?;
|
||||
const field = Analysis.containerField(tree, node_idx).?;
|
||||
|
||||
try makeScopeInternal(allocator, context, field.ast.type_expr);
|
||||
try makeScopeInternal(allocator, context, field.ast.align_expr);
|
||||
@@ -3163,7 +3164,7 @@ fn makeScopeInternal(
|
||||
.ptr_type_bit_range,
|
||||
.ptr_type_sentinel,
|
||||
=> {
|
||||
const ptr_type: ast.full.PtrType = ptrType(tree, node_idx).?;
|
||||
const ptr_type: ast.full.PtrType = Analysis.ptrType(tree, node_idx).?;
|
||||
|
||||
try makeScopeInternal(allocator, context, ptr_type.ast.sentinel);
|
||||
try makeScopeInternal(allocator, context, ptr_type.ast.align_node);
|
||||
@@ -3192,7 +3193,7 @@ fn makeScopeInternal(
|
||||
scope.* = .{
|
||||
.range = .{
|
||||
.start = offsets.tokenLocation(tree, payload_token).start,
|
||||
.end = offsets.tokenLocation(tree, lastToken(tree, expr)).end,
|
||||
.end = offsets.tokenLocation(tree, Analysis.lastToken(tree, expr)).end,
|
||||
},
|
||||
.decls = std.StringHashMap(Declaration).init(allocator),
|
||||
.data = .other,
|
||||
|
||||
Reference in New Issue
Block a user