diff --git a/src/DocumentStore.zig b/src/DocumentStore.zig index eafd08a..be84f81 100644 --- a/src/DocumentStore.zig +++ b/src/DocumentStore.zig @@ -100,7 +100,7 @@ pub fn deinit(self: *DocumentStore) void { } /// returns a handle to the given document -pub fn getHandle(self: *DocumentStore, uri: Uri) ?*Handle { +pub fn getHandle(self: *const DocumentStore, uri: Uri) ?*Handle { const handle = self.handles.getPtr(uri) orelse { log.warn("Trying to open non existent document {s}", .{uri}); return null; diff --git a/src/Server.zig b/src/Server.zig index a4f3a6b..95a9f9c 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -379,7 +379,7 @@ fn typeToCompletion( server: *Server, list: *std.ArrayListUnmanaged(types.CompletionItem), field_access: analysis.FieldAccessReturn, - orig_handle: *DocumentStore.Handle, + orig_handle: *const DocumentStore.Handle, ) error{OutOfMemory}!void { var allocator = server.arena.allocator(); @@ -441,7 +441,7 @@ fn nodeToCompletion( list: *std.ArrayListUnmanaged(types.CompletionItem), node_handle: analysis.NodeWithHandle, unwrapped: ?analysis.TypeWithHandle, - orig_handle: *DocumentStore.Handle, + orig_handle: *const DocumentStore.Handle, is_type_val: bool, parent_is_type_val: ?bool, ) error{OutOfMemory}!void { @@ -811,7 +811,7 @@ fn hoverSymbol(server: *Server, decl_handle: analysis.DeclWithHandle) error{OutO }; } -fn getLabelGlobal(pos_index: usize, handle: *DocumentStore.Handle) error{OutOfMemory}!?analysis.DeclWithHandle { +fn getLabelGlobal(pos_index: usize, handle: *const DocumentStore.Handle) error{OutOfMemory}!?analysis.DeclWithHandle { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -824,7 +824,7 @@ fn getLabelGlobal(pos_index: usize, handle: *DocumentStore.Handle) error{OutOfMe fn getSymbolGlobal( server: *Server, pos_index: usize, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, ) error{OutOfMemory}!?analysis.DeclWithHandle { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -838,7 +838,7 @@ fn getSymbolGlobal( fn gotoDefinitionLabel( server: *Server, pos_index: usize, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, ) error{OutOfMemory}!?types.Location { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -850,7 +850,7 @@ fn gotoDefinitionLabel( fn gotoDefinitionGlobal( server: *Server, pos_index: usize, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, resolve_alias: bool, ) error{OutOfMemory}!?types.Location { const tracy_zone = tracy.trace(@src()); @@ -860,7 +860,7 @@ fn gotoDefinitionGlobal( return try server.gotoDefinitionSymbol(decl, resolve_alias); } -fn hoverDefinitionLabel(server: *Server, pos_index: usize, handle: *DocumentStore.Handle) error{OutOfMemory}!?types.Hover { +fn hoverDefinitionLabel(server: *Server, pos_index: usize, handle: *const DocumentStore.Handle) error{OutOfMemory}!?types.Hover { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -868,7 +868,7 @@ fn hoverDefinitionLabel(server: *Server, pos_index: usize, handle: *DocumentStor return try server.hoverSymbol(decl); } -fn hoverDefinitionBuiltin(server: *Server, pos_index: usize, handle: *DocumentStore.Handle) error{OutOfMemory}!?types.Hover { +fn hoverDefinitionBuiltin(server: *Server, pos_index: usize, handle: *const DocumentStore.Handle) error{OutOfMemory}!?types.Hover { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -892,7 +892,7 @@ fn hoverDefinitionBuiltin(server: *Server, pos_index: usize, handle: *DocumentSt return null; } -fn hoverDefinitionGlobal(server: *Server, pos_index: usize, handle: *DocumentStore.Handle) error{OutOfMemory}!?types.Hover { +fn hoverDefinitionGlobal(server: *Server, pos_index: usize, handle: *const DocumentStore.Handle) error{OutOfMemory}!?types.Hover { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -902,7 +902,7 @@ fn hoverDefinitionGlobal(server: *Server, pos_index: usize, handle: *DocumentSto fn getSymbolFieldAccess( server: *Server, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, source_index: usize, loc: offsets.Loc, ) !?analysis.DeclWithHandle { @@ -934,7 +934,7 @@ fn getSymbolFieldAccess( fn gotoDefinitionFieldAccess( server: *Server, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, source_index: usize, loc: offsets.Loc, resolve_alias: bool, @@ -948,7 +948,7 @@ fn gotoDefinitionFieldAccess( fn hoverDefinitionFieldAccess( server: *Server, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, source_index: usize, loc: offsets.Loc, ) error{OutOfMemory}!?types.Hover { @@ -962,7 +962,7 @@ fn hoverDefinitionFieldAccess( fn gotoDefinitionString( server: *Server, pos_index: usize, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, ) error{OutOfMemory}!?types.Location { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -982,7 +982,7 @@ fn gotoDefinitionString( const DeclToCompletionContext = struct { server: *Server, completions: *std.ArrayListUnmanaged(types.CompletionItem), - orig_handle: *DocumentStore.Handle, + orig_handle: *const DocumentStore.Handle, parent_is_type_val: ?bool = null, }; @@ -1071,7 +1071,7 @@ fn declToCompletion(context: DeclToCompletionContext, decl_handle: analysis.Decl fn completeLabel( server: *Server, pos_index: usize, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, ) ![]types.CompletionItem { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -1112,7 +1112,7 @@ fn populateSnippedCompletions( } } -fn completeGlobal(server: *Server, pos_index: usize, handle: *DocumentStore.Handle) ![]types.CompletionItem { +fn completeGlobal(server: *Server, pos_index: usize, handle: *const DocumentStore.Handle) ![]types.CompletionItem { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -1135,7 +1135,7 @@ fn completeGlobal(server: *Server, pos_index: usize, handle: *DocumentStore.Hand return completions.toOwnedSlice(server.arena.allocator()); } -fn completeFieldAccess(server: *Server, handle: *DocumentStore.Handle, source_index: usize, loc: offsets.Loc) !?[]types.CompletionItem { +fn completeFieldAccess(server: *Server, handle: *const DocumentStore.Handle, source_index: usize, loc: offsets.Loc) !?[]types.CompletionItem { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -1322,7 +1322,7 @@ fn formatDetailledLabel(item: *types.CompletionItem, alloc: std.mem.Allocator) ! // logger.info("labelDetails: {s} :: {s}", .{item.labelDetails.?.detail, item.labelDetails.?.description}); } -fn completeError(server: *Server, handle: *DocumentStore.Handle) ![]types.CompletionItem { +fn completeError(server: *Server, handle: *const DocumentStore.Handle) ![]types.CompletionItem { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -1357,7 +1357,7 @@ fn kindToSortScore(kind: types.CompletionItem.Kind) ?[]const u8 { }; } -fn completeDot(server: *Server, handle: *DocumentStore.Handle) ![]types.CompletionItem { +fn completeDot(server: *Server, handle: *const DocumentStore.Handle) ![]types.CompletionItem { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -1366,7 +1366,7 @@ fn completeDot(server: *Server, handle: *DocumentStore.Handle) ![]types.Completi return completions; } -fn completeFileSystemStringLiteral(allocator: std.mem.Allocator, store: *const DocumentStore, handle: *DocumentStore.Handle, completing: []const u8, is_import: bool) ![]types.CompletionItem { +fn completeFileSystemStringLiteral(allocator: std.mem.Allocator, store: *const DocumentStore, handle: *const DocumentStore.Handle, completing: []const u8, is_import: bool) ![]types.CompletionItem { var subpath_present = false; var completions = std.ArrayListUnmanaged(types.CompletionItem){}; @@ -1422,7 +1422,7 @@ fn completeFileSystemStringLiteral(allocator: std.mem.Allocator, store: *const D return completions.toOwnedSlice(allocator); } -fn documentSymbol(server: *Server, writer: anytype, id: types.RequestId, handle: *DocumentStore.Handle) !void { +fn documentSymbol(server: *Server, writer: anytype, id: types.RequestId, handle: *const DocumentStore.Handle) !void { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); diff --git a/src/analysis.zig b/src/analysis.zig index b0c236a..168683d 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -47,7 +47,7 @@ pub fn getDocComments(allocator: std.mem.Allocator, tree: Ast, node: Ast.Node.In } /// Get the first doc comment of a declaration. -pub fn getDocCommentTokenIndex(tokens: []std.zig.Token.Tag, base_token: Ast.TokenIndex) ?Ast.TokenIndex { +pub fn getDocCommentTokenIndex(tokens: []const std.zig.Token.Tag, base_token: Ast.TokenIndex) ?Ast.TokenIndex { var idx = base_token; if (idx == 0) return null; idx -= 1; @@ -181,7 +181,7 @@ pub fn getFunctionSnippet(allocator: std.mem.Allocator, tree: Ast, func: Ast.ful return buffer.toOwnedSlice(allocator); } -pub fn hasSelfParam(arena: *std.heap.ArenaAllocator, document_store: *DocumentStore, handle: *DocumentStore.Handle, func: Ast.full.FnProto) !bool { +pub fn hasSelfParam(arena: *std.heap.ArenaAllocator, document_store: *const DocumentStore, handle: *const DocumentStore.Handle, func: Ast.full.FnProto) !bool { // Non-decl prototypes cannot have a self parameter. if (func.name_token == null) return false; if (func.ast.params.len == 0) return false; @@ -314,7 +314,7 @@ fn getDeclName(tree: Ast, node: Ast.Node.Index) ?[]const u8 { }; } -fn resolveVarDeclAliasInternal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle, root: bool) error{OutOfMemory}!?DeclWithHandle { +fn resolveVarDeclAliasInternal(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle, root: bool) error{OutOfMemory}!?DeclWithHandle { _ = root; const handle = node_handle.handle; const tree = handle.tree; @@ -367,7 +367,7 @@ fn resolveVarDeclAliasInternal(store: *DocumentStore, arena: *std.heap.ArenaAllo /// const decl = @import("decl-file.zig").decl; /// const other = decl.middle.other; ///``` -pub fn resolveVarDeclAlias(store: *DocumentStore, arena: *std.heap.ArenaAllocator, decl_handle: NodeWithHandle) !?DeclWithHandle { +pub fn resolveVarDeclAlias(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, decl_handle: NodeWithHandle) !?DeclWithHandle { const decl = decl_handle.node; const handle = decl_handle.handle; const tree = handle.tree; @@ -431,7 +431,7 @@ fn findReturnStatement(tree: Ast, fn_decl: Ast.full.FnProto, body: Ast.Node.Inde return findReturnStatementInternal(tree, fn_decl, body, &already_found); } -pub fn resolveReturnType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, fn_decl: Ast.full.FnProto, handle: *DocumentStore.Handle, bound_type_params: *BoundTypeParams, fn_body: ?Ast.Node.Index) !?TypeWithHandle { +pub fn resolveReturnType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, fn_decl: Ast.full.FnProto, handle: *const DocumentStore.Handle, bound_type_params: *BoundTypeParams, fn_body: ?Ast.Node.Index) !?TypeWithHandle { const tree = handle.tree; if (isTypeFunction(tree, fn_decl) and fn_body != null) { // If this is a type function and it only contains a single return statement that returns @@ -468,7 +468,7 @@ pub fn resolveReturnType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, } /// Resolves the child type of an optional type -fn resolveUnwrapOptionalType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, opt: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle { +fn resolveUnwrapOptionalType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, opt: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle { const opt_node = switch (opt.type.data) { .other => |n| n, else => return null, @@ -484,7 +484,7 @@ fn resolveUnwrapOptionalType(store: *DocumentStore, arena: *std.heap.ArenaAlloca return null; } -fn resolveUnwrapErrorType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, rhs: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle { +fn resolveUnwrapErrorType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, rhs: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle { const rhs_node = switch (rhs.type.data) { .other => |n| n, .error_union => |n| return TypeWithHandle{ @@ -505,7 +505,7 @@ fn resolveUnwrapErrorType(store: *DocumentStore, arena: *std.heap.ArenaAllocator } /// Resolves the child type of a deref type -fn resolveDerefType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, deref: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle { +fn resolveDerefType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, deref: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle { const deref_node = switch (deref.type.data) { .other => |n| n, .pointer => |n| return TypeWithHandle{ @@ -538,7 +538,7 @@ fn resolveDerefType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, dere } /// Resolves slicing and array access -fn resolveBracketAccessType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, lhs: TypeWithHandle, rhs: enum { Single, Range }, bound_type_params: *BoundTypeParams) !?TypeWithHandle { +fn resolveBracketAccessType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, lhs: TypeWithHandle, rhs: enum { Single, Range }, bound_type_params: *BoundTypeParams) !?TypeWithHandle { const lhs_node = switch (lhs.type.data) { .other => |n| n, else => return null, @@ -575,7 +575,7 @@ fn resolveBracketAccessType(store: *DocumentStore, arena: *std.heap.ArenaAllocat } /// Called to remove one level of pointerness before a field access -pub fn resolveFieldAccessLhsType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, lhs: TypeWithHandle, bound_type_params: *BoundTypeParams) !TypeWithHandle { +pub fn resolveFieldAccessLhsType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, lhs: TypeWithHandle, bound_type_params: *BoundTypeParams) !TypeWithHandle { return (try resolveDerefType(store, arena, lhs, bound_type_params)) orelse lhs; } @@ -614,7 +614,7 @@ pub fn isTypeIdent(text: []const u8) bool { } /// Resolves the type of a node -pub fn resolveTypeOfNodeInternal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle, bound_type_params: *BoundTypeParams) error{OutOfMemory}!?TypeWithHandle { +pub fn resolveTypeOfNodeInternal(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle, bound_type_params: *BoundTypeParams) error{OutOfMemory}!?TypeWithHandle { // If we were asked to resolve this node before, // it is self-referential and we cannot resolve it. for (resolve_trail.items) |i| { @@ -972,7 +972,7 @@ pub const Type = struct { pub const TypeWithHandle = struct { type: Type, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, pub fn typeVal(node_handle: NodeWithHandle) TypeWithHandle { return .{ @@ -1080,7 +1080,7 @@ pub const TypeWithHandle = struct { } }; -pub fn resolveTypeOfNode(store: *DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle) error{OutOfMemory}!?TypeWithHandle { +pub fn resolveTypeOfNode(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle) error{OutOfMemory}!?TypeWithHandle { var bound_type_params = BoundTypeParams{}; return resolveTypeOfNodeInternal(store, arena, node_handle, &bound_type_params); } @@ -1145,7 +1145,7 @@ pub fn collectCImportNodes(allocator: std.mem.Allocator, tree: Ast) error{OutOfM pub const NodeWithHandle = struct { node: Ast.Node.Index, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, }; pub const FieldAccessReturn = struct { @@ -1153,7 +1153,7 @@ pub const FieldAccessReturn = struct { unwrapped: ?TypeWithHandle = null, }; -pub fn getFieldAccessType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *DocumentStore.Handle, source_index: usize, tokenizer: *std.zig.Tokenizer) !?FieldAccessReturn { +pub fn getFieldAccessType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, source_index: usize, tokenizer: *std.zig.Tokenizer) !?FieldAccessReturn { var current_type = TypeWithHandle.typeVal(.{ .node = undefined, .handle = handle, @@ -1865,7 +1865,7 @@ pub const Declaration = union(enum) { pub const DeclWithHandle = struct { decl: *Declaration, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, pub fn nameToken(self: DeclWithHandle) Ast.TokenIndex { const tree = self.handle.tree; @@ -1887,7 +1887,7 @@ pub const DeclWithHandle = struct { }; } - pub fn resolveType(self: DeclWithHandle, store: *DocumentStore, arena: *std.heap.ArenaAllocator, bound_type_params: *BoundTypeParams) !?TypeWithHandle { + pub fn resolveType(self: DeclWithHandle, store: *const DocumentStore, arena: *std.heap.ArenaAllocator, bound_type_params: *BoundTypeParams) !?TypeWithHandle { const tree = self.handle.tree; const node_tags = tree.nodes.items(.tag); const main_tokens = tree.nodes.items(.main_token); @@ -1997,7 +1997,7 @@ fn findContainerScope(container_handle: NodeWithHandle) ?*Scope { } else null; } -fn iterateSymbolsContainerInternal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, container_handle: NodeWithHandle, orig_handle: *DocumentStore.Handle, comptime callback: anytype, context: anytype, instance_access: bool, use_trail: *std.ArrayList(Ast.Node.Index)) error{OutOfMemory}!void { +fn iterateSymbolsContainerInternal(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, container_handle: NodeWithHandle, orig_handle: *const DocumentStore.Handle, comptime callback: anytype, context: anytype, instance_access: bool, use_trail: *std.ArrayList(Ast.Node.Index)) error{OutOfMemory}!void { const container = container_handle.node; const handle = container_handle.handle; @@ -2064,12 +2064,12 @@ fn iterateSymbolsContainerInternal(store: *DocumentStore, arena: *std.heap.Arena } } -pub fn iterateSymbolsContainer(store: *DocumentStore, arena: *std.heap.ArenaAllocator, container_handle: NodeWithHandle, orig_handle: *DocumentStore.Handle, comptime callback: anytype, context: anytype, instance_access: bool) error{OutOfMemory}!void { +pub fn iterateSymbolsContainer(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, container_handle: NodeWithHandle, orig_handle: *const DocumentStore.Handle, comptime callback: anytype, context: anytype, instance_access: bool) error{OutOfMemory}!void { var use_trail = std.ArrayList(Ast.Node.Index).init(arena.allocator()); return try iterateSymbolsContainerInternal(store, arena, container_handle, orig_handle, callback, context, instance_access, &use_trail); } -pub fn iterateLabels(handle: *DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype) error{OutOfMemory}!void { +pub fn iterateLabels(handle: *const DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype) error{OutOfMemory}!void { for (handle.document_scope.scopes.items) |scope| { if (source_index >= scope.loc.start and source_index < scope.loc.end) { var decl_it = scope.decls.iterator(); @@ -2085,7 +2085,7 @@ pub fn iterateLabels(handle: *DocumentStore.Handle, source_index: usize, comptim } } -fn iterateSymbolsGlobalInternal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype, use_trail: *std.ArrayList(Ast.Node.Index)) error{OutOfMemory}!void { +fn iterateSymbolsGlobalInternal(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype, use_trail: *std.ArrayList(Ast.Node.Index)) error{OutOfMemory}!void { for (handle.document_scope.scopes.items) |scope| { if (source_index >= scope.loc.start and source_index <= scope.loc.end) { var decl_it = scope.decls.iterator(); @@ -2126,7 +2126,7 @@ fn iterateSymbolsGlobalInternal(store: *DocumentStore, arena: *std.heap.ArenaAll } } -pub fn iterateSymbolsGlobal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype) error{OutOfMemory}!void { +pub fn iterateSymbolsGlobal(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype) error{OutOfMemory}!void { var use_trail = std.ArrayList(Ast.Node.Index).init(arena.allocator()); return try iterateSymbolsGlobalInternal(store, arena, handle, source_index, callback, context, &use_trail); } @@ -2151,7 +2151,7 @@ pub fn innermostBlockScope(handle: DocumentStore.Handle, source_index: usize) As return handle.document_scope.scopes.items[innermostBlockScopeIndex(handle, source_index)].toNodeIndex().?; } -pub fn innermostContainer(handle: *DocumentStore.Handle, source_index: usize) TypeWithHandle { +pub fn innermostContainer(handle: *const DocumentStore.Handle, source_index: usize) TypeWithHandle { var current = handle.document_scope.scopes.items[0].data.container; if (handle.document_scope.scopes.items.len == 1) return TypeWithHandle.typeVal(.{ .node = current, .handle = handle }); @@ -2167,7 +2167,7 @@ pub fn innermostContainer(handle: *DocumentStore.Handle, source_index: usize) Ty return TypeWithHandle.typeVal(.{ .node = current, .handle = handle }); } -fn resolveUse(store: *DocumentStore, arena: *std.heap.ArenaAllocator, uses: []const Ast.Node.Index, symbol: []const u8, handle: *DocumentStore.Handle) error{OutOfMemory}!?DeclWithHandle { +fn resolveUse(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, uses: []const Ast.Node.Index, symbol: []const u8, handle: *const DocumentStore.Handle) error{OutOfMemory}!?DeclWithHandle { // If we were asked to resolve this symbol before, // it is self-referential and we cannot resolve it. if (std.mem.indexOfScalar([*]const u8, using_trail.items, symbol.ptr) != null) @@ -2199,7 +2199,7 @@ fn resolveUse(store: *DocumentStore, arena: *std.heap.ArenaAllocator, uses: []co return null; } -pub fn lookupLabel(handle: *DocumentStore.Handle, symbol: []const u8, source_index: usize) error{OutOfMemory}!?DeclWithHandle { +pub fn lookupLabel(handle: *const DocumentStore.Handle, symbol: []const u8, source_index: usize) error{OutOfMemory}!?DeclWithHandle { for (handle.document_scope.scopes.items) |scope| { if (source_index >= scope.loc.start and source_index < scope.loc.end) { if (scope.decls.getEntry(symbol)) |candidate| { @@ -2218,7 +2218,7 @@ pub fn lookupLabel(handle: *DocumentStore.Handle, symbol: []const u8, source_ind return null; } -pub fn lookupSymbolGlobal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *DocumentStore.Handle, symbol: []const u8, source_index: usize) error{OutOfMemory}!?DeclWithHandle { +pub fn lookupSymbolGlobal(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, symbol: []const u8, source_index: usize) error{OutOfMemory}!?DeclWithHandle { const innermost_scope_idx = innermostBlockScopeIndex(handle.*, source_index); var curr = innermost_scope_idx; @@ -2246,7 +2246,7 @@ pub fn lookupSymbolGlobal(store: *DocumentStore, arena: *std.heap.ArenaAllocator } pub fn lookupSymbolContainer( - store: *DocumentStore, + store: *const DocumentStore, arena: *std.heap.ArenaAllocator, container_handle: NodeWithHandle, symbol: []const u8, diff --git a/src/code_actions.zig b/src/code_actions.zig index b78b4b2..3161ff0 100644 --- a/src/code_actions.zig +++ b/src/code_actions.zig @@ -11,8 +11,8 @@ const offsets = @import("offsets.zig"); pub const Builder = struct { arena: *std.heap.ArenaAllocator, - document_store: *DocumentStore, - handle: *DocumentStore.Handle, + document_store: *const DocumentStore, + handle: *const DocumentStore.Handle, offset_encoding: offsets.Encoding, pub fn generateCodeAction( diff --git a/src/inlay_hints.zig b/src/inlay_hints.zig index ad95c13..2c66e69 100644 --- a/src/inlay_hints.zig +++ b/src/inlay_hints.zig @@ -34,7 +34,7 @@ fn isNodeInRange(tree: Ast, node: Ast.Node.Index, range: types.Range) bool { const Builder = struct { allocator: std.mem.Allocator, config: *const Config, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, hints: std.ArrayListUnmanaged(types.InlayHint), hover_kind: types.MarkupContent.Kind, encoding: offsets.Encoding, @@ -81,7 +81,7 @@ const Builder = struct { /// `call` is the function call /// `decl_handle` should be a function protototype /// writes parameter hints into `builder.hints` -fn writeCallHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *DocumentStore, call: Ast.full.Call, decl_handle: analysis.DeclWithHandle) !void { +fn writeCallHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *const DocumentStore, call: Ast.full.Call, decl_handle: analysis.DeclWithHandle) !void { const handle = builder.handle; const tree = handle.tree; @@ -181,7 +181,7 @@ fn writeBuiltinHint(builder: *Builder, parameters: []const Ast.Node.Index, argum } /// takes a Ast.full.Call (a function call), analysis its function expression, finds its declaration and writes parameter hints into `builder.hints` -fn writeCallNodeHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *DocumentStore, call: Ast.full.Call) !void { +fn writeCallNodeHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *const DocumentStore, call: Ast.full.Call) !void { if (call.ast.params.len == 0) return; if (builder.config.inlay_hints_exclude_single_argument and call.ast.params.len == 1) return; @@ -257,7 +257,7 @@ fn callWriteNodeInlayHint(allocator: std.mem.Allocator, args: anytype) error{Out /// iterates over the ast and writes parameter hints into `builder.hints` for every function call and builtin call /// nodes outside the given range are excluded -fn writeNodeInlayHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *DocumentStore, maybe_node: ?Ast.Node.Index, range: types.Range) error{OutOfMemory}!void { +fn writeNodeInlayHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *const DocumentStore, maybe_node: ?Ast.Node.Index, range: types.Range) error{OutOfMemory}!void { const node = maybe_node orelse return; const handle = builder.handle; @@ -688,8 +688,8 @@ fn writeNodeInlayHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store: pub fn writeRangeInlayHint( arena: *std.heap.ArenaAllocator, config: Config, - store: *DocumentStore, - handle: *DocumentStore.Handle, + store: *const DocumentStore, + handle: *const DocumentStore.Handle, range: types.Range, hover_kind: types.MarkupContent.Kind, encoding: offsets.Encoding, diff --git a/src/references.zig b/src/references.zig index 6a8923a..b155955 100644 --- a/src/references.zig +++ b/src/references.zig @@ -56,11 +56,11 @@ pub fn labelReferences( const Builder = struct { arena: *std.heap.ArenaAllocator, locations: std.ArrayListUnmanaged(types.Location), - store: *DocumentStore, + store: *const DocumentStore, decl: analysis.DeclWithHandle, encoding: offsets.Encoding, - pub fn init(arena: *std.heap.ArenaAllocator, store: *DocumentStore, decl: analysis.DeclWithHandle, encoding: offsets.Encoding) Builder { + pub fn init(arena: *std.heap.ArenaAllocator, store: *const DocumentStore, decl: analysis.DeclWithHandle, encoding: offsets.Encoding) Builder { return Builder{ .arena = arena, .locations = .{}, @@ -70,7 +70,7 @@ const Builder = struct { }; } - pub fn add(self: *Builder, handle: *DocumentStore.Handle, token_index: Ast.TokenIndex) !void { + pub fn add(self: *Builder, handle: *const DocumentStore.Handle, token_index: Ast.TokenIndex) !void { try self.locations.append(self.arena.allocator(), .{ .uri = handle.uri, .range = offsets.tokenToRange(handle.tree, token_index, self.encoding), @@ -81,7 +81,7 @@ const Builder = struct { fn symbolReferencesInternal( builder: *Builder, node: Ast.Node.Index, - handle: *DocumentStore.Handle, + handle: *const DocumentStore.Handle, ) error{OutOfMemory}!void { const tree = handle.tree; @@ -453,7 +453,7 @@ fn symbolReferencesInternal( pub fn symbolReferences( arena: *std.heap.ArenaAllocator, - store: *DocumentStore, + store: *const DocumentStore, decl_handle: analysis.DeclWithHandle, encoding: offsets.Encoding, include_decl: bool, diff --git a/src/semantic_tokens.zig b/src/semantic_tokens.zig index ab0bf10..244fd8f 100644 --- a/src/semantic_tokens.zig +++ b/src/semantic_tokens.zig @@ -52,14 +52,14 @@ pub const TokenModifiers = packed struct { const Builder = struct { arena: *std.heap.ArenaAllocator, - store: *DocumentStore, - handle: *DocumentStore.Handle, + store: *const DocumentStore, + handle: *const DocumentStore.Handle, previous_position: usize = 0, previous_token: ?Ast.TokenIndex = null, arr: std.ArrayListUnmanaged(u32), encoding: offsets.Encoding, - fn init(arena: *std.heap.ArenaAllocator, store: *DocumentStore, handle: *DocumentStore.Handle, encoding: offsets.Encoding) Builder { + fn init(arena: *std.heap.ArenaAllocator, store: *const DocumentStore, handle: *const DocumentStore.Handle, encoding: offsets.Encoding) Builder { return Builder{ .arena = arena, .store = store, @@ -223,7 +223,7 @@ fn writeDocComments(builder: *Builder, tree: Ast, doc: Ast.TokenIndex) !void { } } -fn fieldTokenType(container_decl: Ast.Node.Index, handle: *DocumentStore.Handle) ?TokenType { +fn fieldTokenType(container_decl: Ast.Node.Index, handle: *const DocumentStore.Handle) ?TokenType { const main_token = handle.tree.nodes.items(.main_token)[container_decl]; if (main_token > handle.tree.tokens.len) return null; return @as(?TokenType, switch (handle.tree.tokens.items(.tag)[main_token]) { @@ -1018,7 +1018,12 @@ fn writeContainerField(builder: *Builder, node: Ast.Node.Index, field_token_type } // TODO Range version, edit version. -pub fn writeAllSemanticTokens(arena: *std.heap.ArenaAllocator, store: *DocumentStore, handle: *DocumentStore.Handle, encoding: offsets.Encoding) ![]u32 { +pub fn writeAllSemanticTokens( + arena: *std.heap.ArenaAllocator, + store: *const DocumentStore, + handle: *const DocumentStore.Handle, + encoding: offsets.Encoding, +) ![]u32 { var builder = Builder.init(arena, store, handle, encoding); // reverse the ast from the root declarations diff --git a/src/signature_help.zig b/src/signature_help.zig index 4b16170..2313984 100644 --- a/src/signature_help.zig +++ b/src/signature_help.zig @@ -8,7 +8,7 @@ const Token = std.zig.Token; const identifierFromPosition = @import("Server.zig").identifierFromPosition; const ast = @import("ast.zig"); -fn fnProtoToSignatureInfo(document_store: *DocumentStore, arena: *std.heap.ArenaAllocator, commas: u32, skip_self_param: bool, handle: *DocumentStore.Handle, fn_node: Ast.Node.Index, proto: Ast.full.FnProto) !types.SignatureInformation { +fn fnProtoToSignatureInfo(document_store: *const DocumentStore, arena: *std.heap.ArenaAllocator, commas: u32, skip_self_param: bool, handle: *const DocumentStore.Handle, fn_node: Ast.Node.Index, proto: Ast.full.FnProto) !types.SignatureInformation { const ParameterInformation = types.SignatureInformation.ParameterInformation; const tree = handle.tree; @@ -67,7 +67,7 @@ fn fnProtoToSignatureInfo(document_store: *DocumentStore, arena: *std.heap.Arena }; } -pub fn getSignatureInfo(document_store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *DocumentStore.Handle, absolute_index: usize, comptime data: type) !?types.SignatureInformation { +pub fn getSignatureInfo(document_store: *const DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, absolute_index: usize, comptime data: type) !?types.SignatureInformation { const innermost_block = analysis.innermostBlockScope(handle.*, absolute_index); const tree = handle.tree; const token_tags = tree.tokens.items(.tag);