Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
.hash = "diffz-0.0.1-G2tlIQrOAQCfH15jdyaLyrMgV8eGPouFhkCeYFTmJaLk",
},
.lsp_kit = .{
.url = "https://github.com/zigtools/lsp-kit/archive/39820a04f098d03424ced689fa016c2130fd876c.tar.gz",
.hash = "lsp_kit-0.1.0-bi_PL500CgBbZ3Pbh6TG-Voqb9MRJO8_aLDgBU9Yy7DN",
.url = "https://github.com/zigtools/lsp-kit/archive/eb2b440e5a309ab8c4b4c67e97d77791db21e308.tar.gz",
.hash = "lsp_kit-0.1.0-bi_PL7s0CgBO95W_AKmQPouVfLO2KgublMZjxra3k6uY",
},
.tracy = .{
.url = "https://github.com/wolfpld/tracy/archive/refs/tags/v0.11.1.tar.gz",
Expand Down
6 changes: 3 additions & 3 deletions deps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ linkFarm "zig-packages" [
};
}
{
name = "lsp_kit-0.1.0-bi_PL500CgBbZ3Pbh6TG-Voqb9MRJO8_aLDgBU9Yy7DN";
name = "lsp_kit-0.1.0-bi_PL7s0CgBO95W_AKmQPouVfLO2KgublMZjxra3k6uY";
path = fetchzip {
url = "https://github.com/zigtools/lsp-kit/archive/39820a04f098d03424ced689fa016c2130fd876c.tar.gz";
hash = "sha256-GHR1uIXO5ydb7xFV7SxVFuIyLl/Vy3sEl1EQZBK9hwY=";
url = "https://github.com/zigtools/lsp-kit/archive/eb2b440e5a309ab8c4b4c67e97d77791db21e308.tar.gz";
hash = "sha256-clfJjizR8caDYOxDfTQdqCzuLU3DkygG1X4I6xSN5XM=";
};
}
]
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/DocumentScope.zig
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ fn walkNode(
.container_field,
.@"asm",
.asm_simple,
.asm_legacy,

.grouped_expression,
.field_access,
Expand Down
4 changes: 3 additions & 1 deletion src/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const ClientCapabilities = struct {

pub const Error = error{
OutOfMemory,
WriteFailed,
ParseError,
InvalidRequest,
MethodNotFound,
Expand Down Expand Up @@ -1857,7 +1858,7 @@ fn formattingHandler(server: *Server, arena: std.mem.Allocator, request: types.D

if (handle.tree.errors.len != 0) return null;

const formatted = try handle.tree.render(arena);
const formatted = try handle.tree.renderAlloc(arena);

if (std.mem.eql(u8, handle.tree.source, formatted)) return null;

Expand Down Expand Up @@ -2283,6 +2284,7 @@ fn processMessageReportError(server: *Server, message: Message) ?[]const u8 {
.request => |request| return server.sendToClientResponseError(request.id, .{
.code = @enumFromInt(switch (err) {
error.OutOfMemory => @intFromEnum(types.ErrorCodes.InternalError),
error.WriteFailed => @intFromEnum(types.ErrorCodes.InternalError),
error.ParseError => @intFromEnum(types.ErrorCodes.ParseError),
error.InvalidRequest => @intFromEnum(types.ErrorCodes.InvalidRequest),
error.MethodNotFound => @intFromEnum(types.ErrorCodes.MethodNotFound),
Expand Down
64 changes: 33 additions & 31 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ pub fn isInstanceCall(
call_handle: *DocumentStore.Handle,
call: Ast.full.Call,
func_ty: Type,
) error{OutOfMemory}!bool {
) error{ OutOfMemory, WriteFailed }!bool {
std.debug.assert(!func_ty.is_type_val);
if (call_handle.tree.nodeTag(call.ast.fn_expr) != .field_access) return false;

Expand Down Expand Up @@ -712,7 +712,7 @@ test identifierLocFromIndex {
/// const decl = @import("decl-file.zig").decl;
/// const other = decl.middle.other;
///```
pub fn resolveVarDeclAlias(analyser: *Analyser, options: ResolveOptions) error{OutOfMemory}!?DeclWithHandle {
pub fn resolveVarDeclAlias(analyser: *Analyser, options: ResolveOptions) error{ OutOfMemory, WriteFailed }!?DeclWithHandle {
const tracy_zone = tracy.trace(@src());
defer tracy_zone.end();

Expand All @@ -721,7 +721,7 @@ pub fn resolveVarDeclAlias(analyser: *Analyser, options: ResolveOptions) error{O
return try analyser.resolveVarDeclAliasInternal(options, &node_trail);
}

fn resolveVarDeclAliasInternal(analyser: *Analyser, options: ResolveOptions, node_trail: *NodeSet) error{OutOfMemory}!?DeclWithHandle {
fn resolveVarDeclAliasInternal(analyser: *Analyser, options: ResolveOptions, node_trail: *NodeSet) error{ OutOfMemory, WriteFailed }!?DeclWithHandle {
const node_handle = options.node_handle;
const node_with_uri: NodeWithUri = .{
.node = node_handle.node,
Expand Down Expand Up @@ -891,7 +891,7 @@ fn resolveReturnValueOfFuncNode(
analyser: *Analyser,
handle: *DocumentStore.Handle,
func_node: Ast.Node.Index,
) error{OutOfMemory}!?Type {
) error{ OutOfMemory, WriteFailed }!?Type {
const tree = handle.tree;

var buf: [1]Ast.Node.Index = undefined;
Expand Down Expand Up @@ -981,7 +981,7 @@ pub fn resolveUnwrapErrorUnionType(analyser: *Analyser, ty: Type, side: ErrorUni
};
}

fn resolveUnionTag(analyser: *Analyser, ty: Type) error{OutOfMemory}!?Type {
fn resolveUnionTag(analyser: *Analyser, ty: Type) error{ OutOfMemory, WriteFailed }!?Type {
if (!ty.is_type_val)
return null;

Expand Down Expand Up @@ -1010,7 +1010,7 @@ fn resolveUnionTag(analyser: *Analyser, ty: Type) error{OutOfMemory}!?Type {
return null;
}

fn resolveUnionTagAccess(analyser: *Analyser, ty: Type, symbol: []const u8) error{OutOfMemory}!?Type {
fn resolveUnionTagAccess(analyser: *Analyser, ty: Type, symbol: []const u8) error{ OutOfMemory, WriteFailed }!?Type {
if (!ty.is_type_val)
return null;

Expand Down Expand Up @@ -1085,7 +1085,7 @@ pub const BracketAccess = union(enum) {
analyser: *Analyser,
handle: *DocumentStore.Handle,
slice: Ast.full.Slice,
) error{OutOfMemory}!BracketAccess {
) error{ OutOfMemory, WriteFailed }!BracketAccess {
const start_node = slice.ast.start;
const end_node = slice.ast.end.unwrap() orelse
return .{
Expand Down Expand Up @@ -1360,12 +1360,12 @@ fn resolveOptionalIPValue(
analyser: *Analyser,
optional_node: Ast.Node.OptionalIndex,
handle: *DocumentStore.Handle,
) error{OutOfMemory}!?InternPool.Index {
) error{ OutOfMemory, WriteFailed }!?InternPool.Index {
const node = optional_node.unwrap() orelse return null;
return try analyser.resolveInternPoolValue(.of(node, handle));
}

fn resolveInternPoolValue(analyser: *Analyser, options: ResolveOptions) error{OutOfMemory}!?InternPool.Index {
fn resolveInternPoolValue(analyser: *Analyser, options: ResolveOptions) error{ OutOfMemory, WriteFailed }!?InternPool.Index {
const old_resolve_number_literal_values = analyser.resolve_number_literal_values;
analyser.resolve_number_literal_values = true;
defer analyser.resolve_number_literal_values = old_resolve_number_literal_values;
Expand All @@ -1377,7 +1377,7 @@ fn resolveInternPoolValue(analyser: *Analyser, options: ResolveOptions) error{Ou
}
}

fn resolveIntegerLiteral(analyser: *Analyser, comptime T: type, options: ResolveOptions) error{OutOfMemory}!?T {
fn resolveIntegerLiteral(analyser: *Analyser, comptime T: type, options: ResolveOptions) error{ OutOfMemory, WriteFailed }!?T {
const ip_index = try analyser.resolveInternPoolValue(options) orelse return null;
return analyser.ip.toInt(ip_index, T);
}
Expand Down Expand Up @@ -1494,7 +1494,7 @@ fn resolveStringLiteral(analyser: *Analyser, options: ResolveOptions) !?[]const
return field_name[1 .. field_name.len - 1];
}

fn resolveErrorSetIPIndex(analyser: *Analyser, options: ResolveOptions) error{OutOfMemory}!?InternPool.Index {
fn resolveErrorSetIPIndex(analyser: *Analyser, options: ResolveOptions) error{ OutOfMemory, WriteFailed }!?InternPool.Index {
const ty = try analyser.resolveTypeOfNodeInternal(options) orelse return null;
if (!ty.is_type_val) return null;
const ip_index = switch (ty.data) {
Expand Down Expand Up @@ -1842,24 +1842,24 @@ const FindBreaks = struct {

/// Resolves the type of an Ast Node.
/// Returns `null` if the type could not be resolved.
pub fn resolveTypeOfNode(analyser: *Analyser, options: ResolveOptions) error{OutOfMemory}!?Type {
pub fn resolveTypeOfNode(analyser: *Analyser, options: ResolveOptions) error{ OutOfMemory, WriteFailed }!?Type {
const binding = try analyser.resolveBindingOfNode(options) orelse return null;
return binding.type;
}

fn resolveTypeOfNodeInternal(analyser: *Analyser, options: ResolveOptions) error{OutOfMemory}!?Type {
fn resolveTypeOfNodeInternal(analyser: *Analyser, options: ResolveOptions) error{ OutOfMemory, WriteFailed }!?Type {
const binding = try analyser.resolveBindingOfNodeInternal(options) orelse return null;
return binding.type;
}

pub fn resolveBindingOfNode(analyser: *Analyser, options: ResolveOptions) error{OutOfMemory}!?Binding {
pub fn resolveBindingOfNode(analyser: *Analyser, options: ResolveOptions) error{ OutOfMemory, WriteFailed }!?Binding {
const tracy_zone = tracy.trace(@src());
defer tracy_zone.end();

return analyser.resolveBindingOfNodeInternal(options);
}

fn resolveBindingOfNodeInternal(analyser: *Analyser, options: ResolveOptions) error{OutOfMemory}!?Binding {
fn resolveBindingOfNodeInternal(analyser: *Analyser, options: ResolveOptions) error{ OutOfMemory, WriteFailed }!?Binding {
const node_handle = options.node_handle;
const node_with_uri: NodeWithUri = .{
.node = node_handle.node,
Expand All @@ -1879,7 +1879,7 @@ fn resolveBindingOfNodeInternal(analyser: *Analyser, options: ResolveOptions) er
return binding;
}

fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) error{OutOfMemory}!?Type {
fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) error{ OutOfMemory, WriteFailed }!?Type {
const node_handle = options.node_handle;
const node = node_handle.node;
const handle = node_handle.handle;
Expand Down Expand Up @@ -2672,7 +2672,8 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) error
const token_bytes = tree.tokenSlice(tree.nodeMainToken(node));

var counting_writer = std.io.countingWriter(std.io.null_writer);
const result = try std.zig.string_literal.parseWrite(counting_writer.writer(), token_bytes);
var w = counting_writer.writer().adaptToNewApi();
const result = try std.zig.string_literal.parseWrite(&w.new_interface, token_bytes);
switch (result) {
.success => {},
.failure => return null,
Expand Down Expand Up @@ -2917,6 +2918,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) error

.asm_simple,
.@"asm",
.asm_legacy,
.asm_output,
.asm_input,
=> {},
Expand All @@ -2937,7 +2939,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) error
return null;
}

fn resolveBindingOfNodeUncached(analyser: *Analyser, options: ResolveOptions) error{OutOfMemory}!?Binding {
fn resolveBindingOfNodeUncached(analyser: *Analyser, options: ResolveOptions) error{ OutOfMemory, WriteFailed }!?Binding {
const node_handle = options.node_handle;
const node = node_handle.node;
const handle = node_handle.handle;
Expand Down Expand Up @@ -4105,7 +4107,7 @@ pub const Type = struct {
self: Type,
analyser: *Analyser,
symbol: []const u8,
) error{OutOfMemory}!?DeclWithHandle {
) error{ OutOfMemory, WriteFailed }!?DeclWithHandle {
switch (self.data) {
.either => |entries| {
// TODO: Return all options instead of first valid one
Expand Down Expand Up @@ -4416,7 +4418,7 @@ pub const ScopeWithHandle = struct {

/// Look up `type_name` in 'zig_lib_dir/std/builtin.zig' and return it as an instance
/// Useful for functionality related to builtin fns
pub fn instanceStdBuiltinType(analyser: *Analyser, type_name: []const u8) error{OutOfMemory}!?Type {
pub fn instanceStdBuiltinType(analyser: *Analyser, type_name: []const u8) error{ OutOfMemory, WriteFailed }!?Type {
const zig_lib_dir = analyser.store.config.zig_lib_dir orelse return null;
const builtin_path = try zig_lib_dir.join(analyser.arena, &.{ "std", "builtin.zig" });
const builtin_uri = try URI.fromPath(analyser.arena, builtin_path);
Expand Down Expand Up @@ -4524,7 +4526,7 @@ pub fn getFieldAccessType(
handle: *DocumentStore.Handle,
source_index: usize,
loc: offsets.Loc,
) error{OutOfMemory}!?Type {
) error{ OutOfMemory, WriteFailed }!?Type {
const held_range = try analyser.arena.dupeZ(u8, offsets.locToSlice(handle.tree.source, loc));
var tokenizer: std.zig.Tokenizer = .init(held_range);
var current_type: ?Type = null;
Expand Down Expand Up @@ -5146,7 +5148,7 @@ pub const DeclWithHandle = struct {
return self.decl.nameToken(self.handle.tree);
}

pub fn definitionToken(self: DeclWithHandle, analyser: *Analyser, resolve_alias: bool) error{OutOfMemory}!TokenWithHandle {
pub fn definitionToken(self: DeclWithHandle, analyser: *Analyser, resolve_alias: bool) error{ OutOfMemory, WriteFailed }!TokenWithHandle {
if (resolve_alias) {
switch (self.decl) {
.ast_node => |node| {
Expand Down Expand Up @@ -5361,7 +5363,7 @@ pub const DeclWithHandle = struct {
};
}

pub fn resolveType(self: DeclWithHandle, analyser: *Analyser) error{OutOfMemory}!?Type {
pub fn resolveType(self: DeclWithHandle, analyser: *Analyser) error{ OutOfMemory, WriteFailed }!?Type {
const tracy_zone = tracy.trace(@src());
defer tracy_zone.end();

Expand Down Expand Up @@ -5518,7 +5520,7 @@ pub fn collectDeclarationsOfContainer(
instance_access: bool,
/// allocated with `analyser.arena`
decl_collection: *std.ArrayListUnmanaged(DeclWithHandle),
) error{OutOfMemory}!void {
) error{ OutOfMemory, WriteFailed }!void {
const info = switch (container_type.data) {
.container => |info| info,
.either => |entries| {
Expand Down Expand Up @@ -5836,7 +5838,7 @@ pub fn lookupSymbolFieldInit(
field_name: []const u8,
node: Ast.Node.Index,
ancestors: []const Ast.Node.Index,
) error{OutOfMemory}!?DeclWithHandle {
) error{ OutOfMemory, WriteFailed }!?DeclWithHandle {
var container_type = (try analyser.resolveExpressionType(
handle,
node,
Expand Down Expand Up @@ -5891,7 +5893,7 @@ pub fn resolveExpressionType(
handle: *DocumentStore.Handle,
node: Ast.Node.Index,
ancestors: []const Ast.Node.Index,
) error{OutOfMemory}!?Type {
) error{ OutOfMemory, WriteFailed }!?Type {
return (try analyser.resolveExpressionTypeFromAncestors(
handle,
node,
Expand All @@ -5904,7 +5906,7 @@ pub fn resolveExpressionTypeFromAncestors(
handle: *DocumentStore.Handle,
node: Ast.Node.Index,
ancestors: []const Ast.Node.Index,
) error{OutOfMemory}!?Type {
) error{ OutOfMemory, WriteFailed }!?Type {
if (ancestors.len == 0) return null;

const tree = handle.tree;
Expand Down Expand Up @@ -6240,7 +6242,7 @@ pub fn getSymbolEnumLiteral(
handle: *DocumentStore.Handle,
source_index: usize,
name: []const u8,
) error{OutOfMemory}!?DeclWithHandle {
) error{ OutOfMemory, WriteFailed }!?DeclWithHandle {
const tracy_zone = tracy.trace(@src());
defer tracy_zone.end();

Expand All @@ -6254,7 +6256,7 @@ pub fn resolveStructInitType(
analyser: *Analyser,
handle: *DocumentStore.Handle,
source_index: usize,
) error{OutOfMemory}!?Type {
) error{ OutOfMemory, WriteFailed }!?Type {
const tracy_zone = tracy.trace(@src());
defer tracy_zone.end();

Expand All @@ -6280,7 +6282,7 @@ pub fn getSymbolFieldAccesses(
source_index: usize,
held_loc: offsets.Loc,
name: []const u8,
) error{OutOfMemory}!?[]const DeclWithHandle {
) error{ OutOfMemory, WriteFailed }!?[]const DeclWithHandle {
var decls_with_handles: std.ArrayListUnmanaged(DeclWithHandle) = .empty;
var property_types: std.ArrayListUnmanaged(Type) = .empty;
try analyser.getSymbolFieldAccessesArrayList(arena, handle, source_index, held_loc, name, &decls_with_handles, &property_types);
Expand All @@ -6296,7 +6298,7 @@ pub fn getSymbolFieldAccessesArrayList(
name: []const u8,
decls_with_handles: *std.ArrayListUnmanaged(DeclWithHandle),
property_types: *std.ArrayListUnmanaged(Type),
) error{OutOfMemory}!void {
) error{ OutOfMemory, WriteFailed }!void {
const tracy_zone = tracy.trace(@src());
defer tracy_zone.end();

Expand Down
Loading
Loading