super basic completion, tons of things to iron out
This commit is contained in:
parent
a3067f88b1
commit
9ae912efdd
32
src/main.zig
32
src/main.zig
@ -298,7 +298,8 @@ fn completeGlobal(id: i64, document: *types.TextDocument, config: Config) !void
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn completeFieldAccess(id: i64, document: *types.TextDocument, index: usize, config: Config) !void {
|
fn completeFieldAccess(id: i64, document: *types.TextDocument, position: types.Position, config: Config) !void {
|
||||||
|
if (document.sane_text) |sane_text| {
|
||||||
var tree = try std.zig.parse(allocator, sane_text);
|
var tree = try std.zig.parse(allocator, sane_text);
|
||||||
defer tree.deinit();
|
defer tree.deinit();
|
||||||
|
|
||||||
@ -308,7 +309,21 @@ fn completeFieldAccess(id: i64, document: *types.TextDocument, index: usize, con
|
|||||||
// Deallocate all temporary data.
|
// Deallocate all temporary data.
|
||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
|
|
||||||
try log("{}", .{});
|
var line = try document.getLine(@intCast(usize, position.line));
|
||||||
|
try log("{}", .{line});
|
||||||
|
var tokenizer = std.zig.Tokenizer.init(line);
|
||||||
|
|
||||||
|
if (analysis.getNodeFromTokens(tree, &tree.root_node.base, &tokenizer)) |node| {
|
||||||
|
var index: usize = 0;
|
||||||
|
while (node.iterate(index)) |child_node| {
|
||||||
|
try completions.append(.{
|
||||||
|
.label = analysis.nodeToString(tree, child_node),
|
||||||
|
.kind = .Variable,
|
||||||
|
});
|
||||||
|
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try send(types.Response{
|
try send(types.Response{
|
||||||
.id = .{.Integer = id},
|
.id = .{.Integer = id},
|
||||||
@ -319,6 +334,17 @@ fn completeFieldAccess(id: i64, document: *types.TextDocument, index: usize, con
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
return try send(types.Response{
|
||||||
|
.id = .{.Integer = id},
|
||||||
|
.result = .{
|
||||||
|
.CompletionList = .{
|
||||||
|
.isIncomplete = false,
|
||||||
|
.items = &[_]types.CompletionItem{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute builtin completions at comptime.
|
// Compute builtin completions at comptime.
|
||||||
@ -588,7 +614,7 @@ fn processJsonRpc(parser: *std.json.Parser, json: []const u8, config: Config) !v
|
|||||||
} else if (pos_context == .var_access or pos_context == .empty) {
|
} else if (pos_context == .var_access or pos_context == .empty) {
|
||||||
try completeGlobal(id, document, config);
|
try completeGlobal(id, document, config);
|
||||||
} else if (pos_context == .field_access) {
|
} else if (pos_context == .field_access) {
|
||||||
try completeFieldAccess(id, document, pos_index, config);
|
try completeFieldAccess(id, document, pos, config);
|
||||||
} else {
|
} else {
|
||||||
try respondGeneric(id, no_completions_response);
|
try respondGeneric(id, no_completions_response);
|
||||||
}
|
}
|
||||||
|
@ -158,6 +158,18 @@ pub const TextDocument = struct {
|
|||||||
|
|
||||||
return @intCast(usize, index);
|
return @intCast(usize, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getLine(self: TextDocument, target_line: usize) ![]const u8 {
|
||||||
|
var split_iterator = std.mem.split(self.text, "\n");
|
||||||
|
|
||||||
|
var line: i64 = 0;
|
||||||
|
while (line < target_line) : (line += 1) {
|
||||||
|
_ = split_iterator.next() orelse return error.InvalidParams;
|
||||||
|
}
|
||||||
|
if (split_iterator.next()) |next| {
|
||||||
|
return next;
|
||||||
|
} else return error.InvalidParams;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const TextEdit = struct {
|
pub const TextEdit = struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user