Merge pull request #54 from alexnask/goto_definition
Fixed field completions with partial identifiers after the period
This commit is contained in:
commit
847414d9ca
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user