diff --git a/src/analysis.zig b/src/analysis.zig index 04dbcd9..d818a18 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -362,7 +362,11 @@ pub fn collectImports(import_arr: *std.ArrayList([]const u8), tree: *ast.Tree) ! } } -pub fn getFieldAccessTypeNode(analysis_ctx: *AnalysisContext, tokenizer: *std.zig.Tokenizer) ?*ast.Node { +pub fn getFieldAccessTypeNode( + analysis_ctx: *AnalysisContext, + tokenizer: *std.zig.Tokenizer, + line_length: usize, +) ?*ast.Node { var current_node = &analysis_ctx.tree.root_node.base; while (true) { @@ -381,6 +385,9 @@ pub fn getFieldAccessTypeNode(analysis_ctx: *AnalysisContext, tokenizer: *std.zi if (after_period.id == .Eof) { return current_node; } else if (after_period.id == .Identifier) { + // TODO: This works for now, maybe we should filter based on the partial identifier ourselves? + if (after_period.end == line_length) return current_node; + if (getChild(analysis_ctx.tree, current_node, tokenizer.buffer[after_period.start..after_period.end])) |child| { if (resolveTypeOfNode(analysis_ctx, child)) |child_type| { current_node = child_type; diff --git a/src/main.zig b/src/main.zig index 0166787..5bd8505 100644 --- a/src/main.zig +++ b/src/main.zig @@ -315,8 +315,9 @@ fn completeFieldAccess(id: i64, handle: *DocumentStore.Handle, position: types.P const line = try handle.document.getLine(@intCast(usize, position.line)); var tokenizer = std.zig.Tokenizer.init(line[line_start_idx..]); + const line_length = line.len - line_start_idx; - if (analysis.getFieldAccessTypeNode(&analysis_ctx, &tokenizer)) |node| { + if (analysis.getFieldAccessTypeNode(&analysis_ctx, &tokenizer, line_length)) |node| { try nodeToCompletion(&completions, analysis_ctx.tree, node, config); }