fix comment in references.zig, format

This commit is contained in:
SuperAuguste 2020-07-16 15:19:08 -04:00
parent 5302cfbdbc
commit 489378b939
2 changed files with 96 additions and 165 deletions

View File

@ -687,77 +687,65 @@ pub fn resolveTypeOfNodeInternal(
else => null, else => null,
}; };
}, },
// .InfixOp => { .Period => {
// const infix_op = node.castTag(.InfixOp).?; const infix_op = node.cast(ast.Node.SimpleInfixOp).?;
// switch (infix_op.op) { const rhs_str = nodeToString(handle.tree, infix_op.rhs) orelse return null;
.Period => { // If we are accessing a pointer type, remove one pointerness level :)
const infix_op = node.cast(ast.Node.SimpleInfixOp).?; const left_type = try resolveFieldAccessLhsType(
const rhs_str = nodeToString(handle.tree, infix_op.rhs) orelse return null; store,
// If we are accessing a pointer type, remove one pointerness level :) arena,
const left_type = try resolveFieldAccessLhsType( (try resolveTypeOfNodeInternal(store, arena, .{
store, .node = infix_op.lhs,
arena, .handle = handle,
(try resolveTypeOfNodeInternal(store, arena, .{ }, bound_type_params)) orelse return null,
.node = infix_op.lhs, bound_type_params,
.handle = handle, );
}, bound_type_params)) orelse return null,
bound_type_params,
);
const left_type_node = switch (left_type.type.data) { const left_type_node = switch (left_type.type.data) {
.other => |n| n, .other => |n| n,
else => return null, else => return null,
}; };
if (try lookupSymbolContainer( if (try lookupSymbolContainer(
store, store,
arena, arena,
.{ .node = left_type_node, .handle = left_type.handle }, .{ .node = left_type_node, .handle = left_type.handle },
rhs_str, rhs_str,
!left_type.type.is_type_val, !left_type.type.is_type_val,
)) |child| { )) |child| {
return try child.resolveType(store, arena, bound_type_params); return try child.resolveType(store, arena, bound_type_params);
} else return null; } else return null;
}, },
.UnwrapOptional => { .UnwrapOptional => {
const infix_op = node.cast(ast.Node.SimpleInfixOp).?; const infix_op = node.cast(ast.Node.SimpleInfixOp).?;
const left_type = (try resolveTypeOfNodeInternal(store, arena, .{ const left_type = (try resolveTypeOfNodeInternal(store, arena, .{
.node = infix_op.lhs, .node = infix_op.lhs,
.handle = handle, .handle = handle,
}, bound_type_params)) orelse return null; }, bound_type_params)) orelse return null;
return try resolveUnwrapOptionalType(store, arena, left_type, bound_type_params); return try resolveUnwrapOptionalType(store, arena, left_type, bound_type_params);
}, },
.Catch => { .Catch => {
const infix_op = node.cast(ast.Node.SimpleInfixOp).?; const infix_op = node.cast(ast.Node.SimpleInfixOp).?;
const left_type = (try resolveTypeOfNodeInternal(store, arena, .{ const left_type = (try resolveTypeOfNodeInternal(store, arena, .{
.node = infix_op.lhs, .node = infix_op.lhs,
.handle = handle, .handle = handle,
}, bound_type_params)) orelse return null; }, bound_type_params)) orelse return null;
return try resolveUnwrapErrorType(store, arena, left_type, bound_type_params); return try resolveUnwrapErrorType(store, arena, left_type, bound_type_params);
}, },
.ErrorUnion => return TypeWithHandle.typeVal(node_handle), .ErrorUnion => return TypeWithHandle.typeVal(node_handle),
// else => return null, .SliceType,
// } .ArrayType,
// }, .OptionalType,
// .PrefixOp => { .PtrType,
// const prefix_op = node.castTag(.PrefixOp).?; => return TypeWithHandle.typeVal(node_handle),
// switch (prefix_op.op) { .Try => {
.SliceType, const prefix_op = node.cast(ast.Node.SimplePrefixOp).?;
.ArrayType, const rhs_type = (try resolveTypeOfNodeInternal(store, arena, .{
.OptionalType, .node = prefix_op.rhs,
.PtrType, .handle = handle,
=> return TypeWithHandle.typeVal(node_handle), }, bound_type_params)) orelse return null;
.Try => { return try resolveUnwrapErrorType(store, arena, rhs_type, bound_type_params);
const prefix_op = node.cast(ast.Node.SimplePrefixOp).?; },
const rhs_type = (try resolveTypeOfNodeInternal(store, arena, .{
.node = prefix_op.rhs,
.handle = handle,
}, bound_type_params)) orelse return null;
return try resolveUnwrapErrorType(store, arena, rhs_type, bound_type_params);
},
// else => {},
// }
// },
.BuiltinCall => { .BuiltinCall => {
const builtin_call = node.castTag(.BuiltinCall).?; const builtin_call = node.castTag(.BuiltinCall).?;
const call_name = handle.tree.tokenSlice(builtin_call.builtin_token); const call_name = handle.tree.tokenSlice(builtin_call.builtin_token);
@ -1349,61 +1337,7 @@ pub fn documentPositionContext(arena: *std.heap.ArenaAllocator, document: types.
fn addOutlineNodes(allocator: *std.mem.Allocator, tree: *ast.Tree, child: *ast.Node, context: *GetDocumentSymbolsContext) anyerror!void { fn addOutlineNodes(allocator: *std.mem.Allocator, tree: *ast.Tree, child: *ast.Node, context: *GetDocumentSymbolsContext) anyerror!void {
switch (child.tag) { switch (child.tag) {
.StringLiteral, .IntegerLiteral, .BuiltinCall, .Call, .Identifier, .Add, .StringLiteral, .IntegerLiteral, .BuiltinCall, .Call, .Identifier, .Add, .AddWrap, .ArrayCat, .ArrayMult, .Assign, .AssignBitAnd, .AssignBitOr, .AssignBitShiftLeft, .AssignBitShiftRight, .AssignBitXor, .AssignDiv, .AssignSub, .AssignSubWrap, .AssignMod, .AssignAdd, .AssignAddWrap, .AssignMul, .AssignMulWrap, .BangEqual, .BitAnd, .BitOr, .BitShiftLeft, .BitShiftRight, .BitXor, .BoolAnd, .BoolOr, .Div, .EqualEqual, .ErrorUnion, .GreaterOrEqual, .GreaterThan, .LessOrEqual, .LessThan, .MergeErrorSets, .Mod, .Mul, .MulWrap, .Period, .Range, .Sub, .SubWrap, .UnwrapOptional, .AddressOf, .Await, .BitNot, .BoolNot, .OptionalType, .Negation, .NegationWrap, .Resume, .Try, .ArrayType, .ArrayTypeSentinel, .PtrType, .SliceType, .SuffixOp, .ControlFlowExpression, .ArrayInitializerDot, .SwitchElse, .SwitchCase, .For, .EnumLiteral, .PointerIndexPayload, .StructInitializerDot, .PointerPayload, .While, .Switch, .Else, .BoolLiteral, .NullLiteral, .Defer, .StructInitializer, .FieldInitializer, .If, .MultilineStringLiteral, .UndefinedLiteral, .AnyType, .Block, .ErrorSetDecl => return,
.AddWrap,
.ArrayCat,
.ArrayMult,
.Assign,
.AssignBitAnd,
.AssignBitOr,
.AssignBitShiftLeft,
.AssignBitShiftRight,
.AssignBitXor,
.AssignDiv,
.AssignSub,
.AssignSubWrap,
.AssignMod,
.AssignAdd,
.AssignAddWrap,
.AssignMul,
.AssignMulWrap,
.BangEqual,
.BitAnd,
.BitOr,
.BitShiftLeft,
.BitShiftRight,
.BitXor,
.BoolAnd,
.BoolOr,
.Div,
.EqualEqual,
.ErrorUnion,
.GreaterOrEqual,
.GreaterThan,
.LessOrEqual,
.LessThan,
.MergeErrorSets,
.Mod,
.Mul,
.MulWrap,
.Period,
.Range,
.Sub,
.SubWrap,
.UnwrapOptional,
.AddressOf,
.Await,
.BitNot,
.BoolNot,
.OptionalType,
.Negation,
.NegationWrap,
.Resume,
.Try,
.ArrayType,
.ArrayTypeSentinel,
.PtrType,
.SliceType, .SuffixOp, .ControlFlowExpression, .ArrayInitializerDot, .SwitchElse, .SwitchCase, .For, .EnumLiteral, .PointerIndexPayload, .StructInitializerDot, .PointerPayload, .While, .Switch, .Else, .BoolLiteral, .NullLiteral, .Defer, .StructInitializer, .FieldInitializer, .If, .MultilineStringLiteral, .UndefinedLiteral, .AnyType, .Block, .ErrorSetDecl => return,
.ContainerDecl => { .ContainerDecl => {
const decl = child.castTag(.ContainerDecl).?; const decl = child.castTag(.ContainerDecl).?;

View File

@ -214,7 +214,7 @@ fn symbolReferencesInternal(
const info = switch (node.tag) { const info = switch (node.tag) {
.PtrType => node.castTag(.PtrType).?.ptr_info, .PtrType => node.castTag(.PtrType).?.ptr_info,
.SliceType => node.castTag(.SliceType).?.ptr_info, .SliceType => node.castTag(.SliceType).?.ptr_info,
else => return else => return,
}; };
const prefix_op = node.cast(ast.Node.SimplePrefixOp).?; const prefix_op = node.cast(ast.Node.SimplePrefixOp).?;
@ -317,50 +317,47 @@ fn symbolReferencesInternal(
const test_decl = node.cast(ast.Node.TestDecl).?; const test_decl = node.cast(ast.Node.TestDecl).?;
try symbolReferencesInternal(arena, store, .{ .node = test_decl.body_node, .handle = handle }, decl, encoding, context, handler); try symbolReferencesInternal(arena, store, .{ .node = test_decl.body_node, .handle = handle }, decl, encoding, context, handler);
}, },
else => { .Period => {
// switch (ast.Node.Tag.Type(node.tag)) { const infix_op = node.cast(ast.Node.SimpleInfixOp).?;
// SimpleInfixOp => {
// switch (node.tag) {
// .Period => {
// try symbolReferencesInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, encoding, context, handler);
// const rhs_str = analysis.nodeToString(handle.tree, infix_op.rhs) orelse return; try symbolReferencesInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, encoding, context, handler);
// var bound_type_params = analysis.BoundTypeParams.init(&arena.allocator);
// const left_type = try analysis.resolveFieldAccessLhsType(
// store,
// arena,
// (try analysis.resolveTypeOfNodeInternal(store, arena, .{
// .node = infix_op.lhs,
// .handle = handle,
// }, &bound_type_params)) orelse return,
// &bound_type_params,
// );
// const left_type_node = switch (left_type.type.data) { const rhs_str = analysis.nodeToString(handle.tree, infix_op.rhs) orelse return;
// .other => |n| n, var bound_type_params = analysis.BoundTypeParams.init(&arena.allocator);
// else => return, const left_type = try analysis.resolveFieldAccessLhsType(
// }; store,
arena,
(try analysis.resolveTypeOfNodeInternal(store, arena, .{
.node = infix_op.lhs,
.handle = handle,
}, &bound_type_params)) orelse return,
&bound_type_params,
);
// if (try analysis.lookupSymbolContainer( const left_type_node = switch (left_type.type.data) {
// store, .other => |n| n,
// arena, else => return,
// .{ .node = left_type_node, .handle = left_type.handle }, };
// rhs_str,
// !left_type.type.is_type_val, if (try analysis.lookupSymbolContainer(
// )) |child| { store,
// if (std.meta.eql(child, decl)) { arena,
// try tokenReference(handle, infix_op.rhs.firstToken(), encoding, context, handler); .{ .node = left_type_node, .handle = left_type.handle },
// } rhs_str,
// } !left_type.type.is_type_val,
// }, )) |child| {
// else => { if (std.meta.eql(child, decl)) {
// try symbolReferencesInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, encoding, context, handler); try tokenReference(handle, infix_op.rhs.firstToken(), encoding, context, handler);
// try symbolReferencesInternal(arena, store, .{ .node = infix_op.rhs, .handle = handle }, decl, encoding, context, handler); }
// }, }
// }
// }
// }
}, },
.Add, .AddWrap, .ArrayCat, .ArrayMult, .Assign, .AssignBitAnd, .AssignBitOr, .AssignBitShiftLeft, .AssignBitShiftRight, .AssignBitXor, .AssignDiv, .AssignSub, .AssignSubWrap, .AssignMod, .AssignAdd, .AssignAddWrap, .AssignMul, .AssignMulWrap, .BangEqual, .BitAnd, .BitOr, .BitShiftLeft, .BitShiftRight, .BitXor, .BoolOr, .Div, .EqualEqual, .ErrorUnion, .GreaterOrEqual, .GreaterThan, .LessOrEqual, .LessThan, .MergeErrorSets, .Mod, .Mul, .MulWrap, .Range, .Sub, .SubWrap, .UnwrapOptional => {
const infix_op = node.cast(ast.Node.SimpleInfixOp).?;
try symbolReferencesInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, encoding, context, handler);
try symbolReferencesInternal(arena, store, .{ .node = infix_op.rhs, .handle = handle }, decl, encoding, context, handler);
},
else => {},
} }
} }