Merge pull request #54 from alexnask/goto_definition

Fixed field completions with partial identifiers after the period
This commit is contained in:
Auguste Rame 2020-05-18 09:25:00 -04:00 committed by GitHub
commit 847414d9ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 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; var current_node = &analysis_ctx.tree.root_node.base;
while (true) { while (true) {
@ -381,6 +385,9 @@ pub fn getFieldAccessTypeNode(analysis_ctx: *AnalysisContext, tokenizer: *std.zi
if (after_period.id == .Eof) { if (after_period.id == .Eof) {
return current_node; return current_node;
} else if (after_period.id == .Identifier) { } 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 (getChild(analysis_ctx.tree, current_node, tokenizer.buffer[after_period.start..after_period.end])) |child| {
if (resolveTypeOfNode(analysis_ctx, child)) |child_type| { if (resolveTypeOfNode(analysis_ctx, child)) |child_type| {
current_node = child_type; current_node = child_type;

View File

@ -315,8 +315,9 @@ fn completeFieldAccess(id: i64, handle: *DocumentStore.Handle, position: types.P
const line = try handle.document.getLine(@intCast(usize, position.line)); const line = try handle.document.getLine(@intCast(usize, position.line));
var tokenizer = std.zig.Tokenizer.init(line[line_start_idx..]); 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); try nodeToCompletion(&completions, analysis_ctx.tree, node, config);
} }