add initial intern pool implementation

This commit is contained in:
Techatrix 2022-12-02 00:08:45 +01:00
parent 40167a5b52
commit 4f180712bb
4 changed files with 2329 additions and 515 deletions

File diff suppressed because it is too large Load Diff

View File

@ -943,6 +943,7 @@ pub fn ensureInterpreterExists(self: *DocumentStore, uri: Uri) !void {
var int = try self.allocator.create(ComptimeInterpreter); var int = try self.allocator.create(ComptimeInterpreter);
int.* = ComptimeInterpreter{ int.* = ComptimeInterpreter{
.allocator = self.allocator, .allocator = self.allocator,
.arena = std.heap.ArenaAllocator.init(self.allocator),
.document_store = self, .document_store = self,
.uri = uri, .uri = uri,
}; };

2110
src/InternPool.zig Normal file

File diff suppressed because it is too large Load Diff

View File

@ -504,11 +504,12 @@ fn typeToCompletion(
), ),
.primitive, .array_index => {}, .primitive, .array_index => {},
.@"comptime" => |co| { .@"comptime" => |co| {
const ti = co.type.getTypeInfo(); const key = co.interpreter.ip.indexToKey(co.type.ty);
switch (ti) {
.@"struct" => |st| { switch (key) {
var fit = st.fields.iterator(); .struct_type => |struct_info| {
while (fit.next()) |entry| { var field_it = struct_info.fields.iterator();
while (field_it.next()) |entry| {
try list.append(allocator, .{ try list.append(allocator, .{
.label = entry.key_ptr.*, .label = entry.key_ptr.*,
.kind = .Field, .kind = .Field,
@ -516,16 +517,8 @@ fn typeToCompletion(
.insertTextFormat = .PlainText, .insertTextFormat = .PlainText,
}); });
} }
var it = st.scope.declarations.iterator(); // TODO declaration completion
while (it.next()) |entry| {
try list.append(allocator, .{
.label = entry.key_ptr.*,
.kind = if (entry.value_ptr.isConstant()) .Constant else .Variable,
.insertText = entry.key_ptr.*,
.insertTextFormat = .PlainText,
});
}
}, },
else => {}, else => {},
} }
@ -846,10 +839,10 @@ fn hoverSymbol(server: *Server, decl_handle: analysis.DeclWithHandle) error{OutO
var bound_type_params = analysis.BoundTypeParams{}; var bound_type_params = analysis.BoundTypeParams{};
const resolved_type = try decl_handle.resolveType(&server.document_store, &server.arena, &bound_type_params); const resolved_type = try decl_handle.resolveType(&server.document_store, &server.arena, &bound_type_params);
const resolved_type_str = if (resolved_type) |rt| const resolved_type_str = if (resolved_type) |rt|
if (rt.type.is_type_val) switch (rt.type.data) { if (rt.type.is_type_val) switch (rt.type.data) {
.@"comptime" => |*co| try std.fmt.allocPrint(server.arena.allocator(), "{ }", .{co.interpreter.formatTypeInfo(co.type.getTypeInfo())}), .@"comptime" => |*co| try std.fmt.allocPrint(server.arena.allocator(), "{}", .{co.type.ty.fmtType(&co.interpreter.ip)}),
else => "type", else => "type",
} else switch (rt.type.data) { // TODO: Investigate random weird numbers like 897 that cause index of bounds } else switch (rt.type.data) { // TODO: Investigate random weird numbers like 897 that cause index of bounds
.pointer, .pointer,