Fixed field completions with partial identifiers after the period

This commit is contained in:
Alexandros Naskos 2020-05-18 16:21:16 +03:00
parent a6a4afd4fd
commit bbe2800139
2 changed files with 9 additions and 2 deletions

View File

@ -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,8 @@ pub fn getFieldAccessTypeNode(analysis_ctx: *AnalysisContext, tokenizer: *std.zi
if (after_period.id == .Eof) {
return current_node;
} else if (after_period.id == .Identifier) {
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;

View File

@ -309,8 +309,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);
}