Fixed errors after upstream merge

This commit is contained in:
Sergeeeek 2020-05-18 11:37:15 +03:00
parent 2c5cc2b48f
commit 07a44bc0ed
3 changed files with 41 additions and 41 deletions

View File

@ -52,7 +52,10 @@ pub fn init(self: *DocumentStore, allocator: *std.mem.Allocator, zig_lib_path: ?
fn newDocument(self: *DocumentStore, uri: []const u8, text: []u8) !*Handle { fn newDocument(self: *DocumentStore, uri: []const u8, text: []u8) !*Handle {
std.debug.warn("Opened document: {}\n", .{uri}); std.debug.warn("Opened document: {}\n", .{uri});
var handle = Handle{ var handle = try self.allocator.create(Handle);
errdefer self.allocator.destroy(handle);
handle.* = Handle{
.count = 1, .count = 1,
.import_uris = std.ArrayList([]const u8).init(self.allocator), .import_uris = std.ArrayList([]const u8).init(self.allocator),
.document = .{ .document = .{
@ -61,9 +64,9 @@ fn newDocument(self: *DocumentStore, uri: []const u8, text: []u8) !*Handle {
.mem = text, .mem = text,
}, },
}; };
try self.checkSanity(&handle); try self.checkSanity(handle);
const kv = try self.handles.getOrPutValue(uri, handle); const kv = try self.handles.getOrPutValue(uri, handle);
return &kv.value; return kv.value;
} }
pub fn openDocument(self: *DocumentStore, uri: []const u8, text: []const u8) !*Handle { pub fn openDocument(self: *DocumentStore, uri: []const u8, text: []const u8) !*Handle {

View File

@ -298,6 +298,15 @@ fn completeGlobal(id: i64, pos_index: usize, handle: DocumentStore.Handle, confi
}); });
} }
fn nodePosition(tree: *std.zig.ast.Tree, node: *std.zig.ast.Node) types.Position {
const location = tree.tokenLocation(0, node.firstToken());
return types.Position{
.line = @intCast(i64, location.line),
.character = @intCast(i64, location.column),
};
}
fn completeFieldAccess(id: i64, handle: *DocumentStore.Handle, position: types.Position, line_start_idx: usize, config: Config) !void { fn completeFieldAccess(id: i64, handle: *DocumentStore.Handle, position: types.Position, line_start_idx: usize, config: Config) !void {
var arena = std.heap.ArenaAllocator.init(allocator); var arena = std.heap.ArenaAllocator.init(allocator);
defer arena.deinit(); defer arena.deinit();
@ -312,49 +321,37 @@ fn completeFieldAccess(id: i64, handle: *DocumentStore.Handle, position: types.P
// var decls = try analysis.declsFromIndex(&arena.allocator, analysis_ctx.tree, try handle.document.positionToIndex(position)); // var decls = try analysis.declsFromIndex(&arena.allocator, analysis_ctx.tree, try handle.document.positionToIndex(position));
if (analysis.getFieldAccessTypeNode(&analysis_ctx, &tokenizer)) |node| { if (analysis.getFieldAccessTypeNode(&analysis_ctx, &tokenizer)) |node| {
var index: usize = 0; try nodeToCompletion(&completions, analysis_ctx.tree, node, config);
while (node.iterate(index)) |child_node| { // var index: usize = 0;
if (analysis.isNodePublic(analysis_ctx.tree, child_node)) { // while (node.iterate(index)) |child_node| {
// TODO: Not great to allocate it again and again inside a loop // if (analysis.isNodePublic(analysis_ctx.tree, child_node)) {
// Creating a new context, so that we don't destroy the tree that is iterated above when resolving imports // // TODO: Not great to allocate it again and again inside a loop
const initial_handle = analysis_ctx.handle; // // Creating a new context, so that we don't destroy the tree that is iterated above when resolving imports
std.debug.warn("\ncompleteFieldAccess calling resolveTypeOfNode for {}\n", .{analysis_ctx.tree.getNodeSource(child_node)}); // const initial_handle = analysis_ctx.handle;
var node_analysis_ctx = (try document_store.analysisContext(initial_handle, &arena)) orelse { // std.debug.warn("\ncompleteFieldAccess calling resolveTypeOfNode for {}\n", .{analysis_ctx.tree.getNodeSource(child_node)});
return send(types.Response{ // var node_analysis_ctx = try document_store.analysisContext(initial_handle, &arena, nodePosition(analysis_ctx.tree, node));
.id = .{ .Integer = id }, // defer node_analysis_ctx.deinit();
.result = .{
.CompletionList = .{
.isIncomplete = true,
.items = completions.items,
},
},
});
};
defer node_analysis_ctx.deinit();
const resolved_node = analysis.resolveTypeOfNode(&node_analysis_ctx, child_node); // const resolved_node = analysis.resolveTypeOfNode(&node_analysis_ctx, child_node);
if (resolved_node) |n| { // if (resolved_node) |n| {
std.debug.warn("completeFieldAccess resolveTypeOfNode result = {}\n", .{resolved_node}); // std.debug.warn("completeFieldAccess resolveTypeOfNode result = {}\n", .{resolved_node});
} // }
const completion_node: struct { node: *std.zig.ast.Node, context: *DocumentStore.AnalysisContext } = blk: { // const completion_node: struct { node: *std.zig.ast.Node, context: *DocumentStore.AnalysisContext } = blk: {
if (resolved_node) |n| { // if (resolved_node) |n| {
break :blk .{ .node = n, .context = &node_analysis_ctx }; // break :blk .{ .node = n, .context = &node_analysis_ctx };
} // }
break :blk .{ .node = child_node, .context = &analysis_ctx }; // break :blk .{ .node = child_node, .context = &analysis_ctx };
}; // };
std.debug.warn("completeFieldAccess resolved_node = {}\n", .{completion_node.context.tree.getNodeSource(completion_node.node)}); // std.debug.warn("completeFieldAccess resolved_node = {}\n", .{completion_node.context.tree.getNodeSource(completion_node.node)});
if (try nodeToCompletion(&arena.allocator, completion_node.context.tree, completion_node.node, config)) |completion| { // try nodeToCompletion(&completions, completion_node.context.tree, completion_node.node, config);
try completions.append(completion); // }
// index += 1;
// }
} }
}
index += 1;
}
}
try send(types.Response{ try send(types.Response{
.id = .{ .Integer = id }, .id = .{ .Integer = id },
.result = .{ .result = .{