more fixes
This commit is contained in:
parent
ce841d1dc4
commit
20f440b3a0
@ -7,9 +7,9 @@ const offsets = @import("offsets.zig");
|
|||||||
/// Get a declaration's doc comment node
|
/// Get a declaration's doc comment node
|
||||||
fn getDocCommentNode(tree: *ast.Tree, node: *ast.Node) ?*ast.Node.DocComment {
|
fn getDocCommentNode(tree: *ast.Tree, node: *ast.Node) ?*ast.Node.DocComment {
|
||||||
if (node.castTag(.FnProto)) |func| {
|
if (node.castTag(.FnProto)) |func| {
|
||||||
return func.doc_comments;
|
return func.getTrailer("doc_comments");
|
||||||
} else if (node.castTag(.VarDecl)) |var_decl| {
|
} else if (node.castTag(.VarDecl)) |var_decl| {
|
||||||
return var_decl.doc_comments;
|
return var_decl.getTrailer("doc_comments");
|
||||||
} else if (node.castTag(.ContainerField)) |field| {
|
} else if (node.castTag(.ContainerField)) |field| {
|
||||||
return field.doc_comments;
|
return field.doc_comments;
|
||||||
} else if (node.castTag(.ErrorTag)) |tag| {
|
} else if (node.castTag(.ErrorTag)) |tag| {
|
||||||
@ -182,7 +182,7 @@ pub fn getDeclNameToken(tree: *ast.Tree, node: *ast.Node) ?ast.TokenIndex {
|
|||||||
},
|
},
|
||||||
.FnProto => {
|
.FnProto => {
|
||||||
const func = node.castTag(.FnProto).?;
|
const func = node.castTag(.FnProto).?;
|
||||||
if (func.name_token == null) return null;
|
if (func.getTrailer("name_token") == null) return null;
|
||||||
return func.name_token.?;
|
return func.name_token.?;
|
||||||
},
|
},
|
||||||
.ContainerField => {
|
.ContainerField => {
|
||||||
@ -274,11 +274,10 @@ pub fn resolveVarDeclAlias(store: *DocumentStore, arena: *std.heap.ArenaAllocato
|
|||||||
const handle = decl_handle.handle;
|
const handle = decl_handle.handle;
|
||||||
|
|
||||||
if (decl.castTag(.VarDecl)) |var_decl| {
|
if (decl.castTag(.VarDecl)) |var_decl| {
|
||||||
if (var_decl.init_node == null) return null;
|
if (!var_decl.trailer_flags.has("init_node")) return null;
|
||||||
if (handle.tree.token_ids[var_decl.mut_token] != .Keyword_const) return null;
|
if (handle.tree.token_ids[var_decl.mut_token] != .Keyword_const) return null;
|
||||||
if (var_decl.init_node == null) return null;
|
|
||||||
|
|
||||||
const base_expr = var_decl.init_node.?;
|
const base_expr = var_decl.getTrailer("init_node").?;
|
||||||
if (base_expr.castTag(.InfixOp)) |infix_op| {
|
if (base_expr.castTag(.InfixOp)) |infix_op| {
|
||||||
if (infix_op.op != .Period) return null;
|
if (infix_op.op != .Period) return null;
|
||||||
const name = handle.tree.tokenSlice(infix_op.rhs.firstToken());
|
const name = handle.tree.tokenSlice(infix_op.rhs.firstToken());
|
||||||
@ -970,7 +969,7 @@ pub fn collectImports(import_arr: *std.ArrayList([]const u8), tree: *ast.Tree) !
|
|||||||
for (tree.root_node.decls()) |decl| {
|
for (tree.root_node.decls()) |decl| {
|
||||||
if (decl.tag != .VarDecl) continue;
|
if (decl.tag != .VarDecl) continue;
|
||||||
const var_decl = decl.castTag(.VarDecl).?;
|
const var_decl = decl.castTag(.VarDecl).?;
|
||||||
if (var_decl.init_node == null) continue;
|
if (!var_decl.trailer_flags.has("init_node")) continue;
|
||||||
|
|
||||||
switch (var_decl.init_node.?.tag) {
|
switch (var_decl.init_node.?.tag) {
|
||||||
.BuiltinCall => {
|
.BuiltinCall => {
|
||||||
@ -1131,11 +1130,11 @@ pub fn isNodePublic(tree: *ast.Tree, node: *ast.Node) bool {
|
|||||||
switch (node.tag) {
|
switch (node.tag) {
|
||||||
.VarDecl => {
|
.VarDecl => {
|
||||||
const var_decl = node.castTag(.VarDecl).?;
|
const var_decl = node.castTag(.VarDecl).?;
|
||||||
return var_decl.visib_token != null;
|
return var_decl.trailer_flags.has("visib_token");
|
||||||
},
|
},
|
||||||
.FnProto => {
|
.FnProto => {
|
||||||
const func = node.castTag(.FnProto).?;
|
const func = node.castTag(.FnProto).?;
|
||||||
return func.visib_token != null;
|
return func.trailer_flags.has("visib_token");
|
||||||
},
|
},
|
||||||
else => return true,
|
else => return true,
|
||||||
}
|
}
|
||||||
@ -1157,7 +1156,7 @@ pub fn nodeToString(tree: *ast.Tree, node: *ast.Node) ?[]const u8 {
|
|||||||
},
|
},
|
||||||
.FnProto => {
|
.FnProto => {
|
||||||
const func = node.castTag(.FnProto).?;
|
const func = node.castTag(.FnProto).?;
|
||||||
if (func.name_token) |name_token| {
|
if (func.getTrailer("name_token")) |name_token| {
|
||||||
return tree.tokenSlice(name_token);
|
return tree.tokenSlice(name_token);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1351,7 +1350,61 @@ 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, .InfixOp, .PrefixOp, .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,
|
.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,
|
||||||
|
|
||||||
.ContainerDecl => {
|
.ContainerDecl => {
|
||||||
const decl = child.castTag(.ContainerDecl).?;
|
const decl = child.castTag(.ContainerDecl).?;
|
||||||
|
22
src/main.zig
22
src/main.zig
@ -212,12 +212,12 @@ fn publishDiagnostics(arena: *std.heap.ArenaAllocator, handle: DocumentStore.Han
|
|||||||
switch (decl.tag) {
|
switch (decl.tag) {
|
||||||
.FnProto => blk: {
|
.FnProto => blk: {
|
||||||
const func = decl.cast(std.zig.ast.Node.FnProto).?;
|
const func = decl.cast(std.zig.ast.Node.FnProto).?;
|
||||||
const is_extern = func.extern_export_inline_token != null;
|
const is_extern = func.trailer_flags.has("extern_export_inline_token");
|
||||||
if (is_extern)
|
if (is_extern)
|
||||||
break :blk;
|
break :blk;
|
||||||
|
|
||||||
if (config.warn_style) {
|
if (config.warn_style) {
|
||||||
if (func.name_token) |name_token| {
|
if (func.getTrailer("name_token")) |name_token| {
|
||||||
const loc = tree.tokenLocation(0, name_token);
|
const loc = tree.tokenLocation(0, name_token);
|
||||||
|
|
||||||
const is_type_function = analysis.isTypeFunction(tree, func);
|
const is_type_function = analysis.isTypeFunction(tree, func);
|
||||||
@ -335,7 +335,7 @@ fn nodeToCompletion(
|
|||||||
switch (node.tag) {
|
switch (node.tag) {
|
||||||
.FnProto => {
|
.FnProto => {
|
||||||
const func = node.cast(std.zig.ast.Node.FnProto).?;
|
const func = node.cast(std.zig.ast.Node.FnProto).?;
|
||||||
if (func.name_token) |name_token| {
|
if (func.getTrailer("name_token")) |name_token| {
|
||||||
const use_snippets = config.enable_snippets and client_capabilities.supports_snippets;
|
const use_snippets = config.enable_snippets and client_capabilities.supports_snippets;
|
||||||
|
|
||||||
const insert_text = if (use_snippets) blk: {
|
const insert_text = if (use_snippets) blk: {
|
||||||
@ -418,10 +418,6 @@ fn nodeToCompletion(
|
|||||||
.detail = analysis.getContainerFieldSignature(handle.tree, field),
|
.detail = analysis.getContainerFieldSignature(handle.tree, field),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
.PrefixOp => {
|
|
||||||
const prefix_op = node.cast(std.zig.ast.Node.PrefixOp).?;
|
|
||||||
|
|
||||||
switch (prefix_op.op) {
|
|
||||||
.ArrayType, .SliceType => {},
|
.ArrayType, .SliceType => {},
|
||||||
.PtrType => {
|
.PtrType => {
|
||||||
if (config.operator_completions) {
|
if (config.operator_completions) {
|
||||||
@ -455,18 +451,6 @@ fn nodeToCompletion(
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
else => return,
|
|
||||||
}
|
|
||||||
|
|
||||||
try list.append(.{
|
|
||||||
.label = "len",
|
|
||||||
.kind = .Field,
|
|
||||||
});
|
|
||||||
try list.append(.{
|
|
||||||
.label = "ptr",
|
|
||||||
.kind = .Field,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
.StringLiteral => {
|
.StringLiteral => {
|
||||||
try list.append(.{
|
try list.append(.{
|
||||||
.label = "len",
|
.label = "len",
|
||||||
|
Loading…
Reference in New Issue
Block a user