use single line method signatures
This commit is contained in:
parent
f482950f5f
commit
ad8d75b613
197
src/analysis.zig
197
src/analysis.zig
@ -19,12 +19,7 @@ pub fn deinit() void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a declaration's doc comments. Caller owns returned memory.
|
/// Gets a declaration's doc comments. Caller owns returned memory.
|
||||||
pub fn getDocComments(
|
pub fn getDocComments(allocator: *std.mem.Allocator, tree: Analysis.Tree, node: ast.Node.Index, format: types.MarkupContent.Kind) !?[]const u8 {
|
||||||
allocator: *std.mem.Allocator,
|
|
||||||
tree: Analysis.Tree,
|
|
||||||
node: ast.Node.Index,
|
|
||||||
format: types.MarkupContent.Kind,
|
|
||||||
) !?[]const u8 {
|
|
||||||
const base = tree.nodes.items(.main_token)[node];
|
const base = tree.nodes.items(.main_token)[node];
|
||||||
const base_kind = tree.nodes.items(.tag)[node];
|
const base_kind = tree.nodes.items(.tag)[node];
|
||||||
const tokens = tree.tokens.items(.tag);
|
const tokens = tree.tokens.items(.tag);
|
||||||
@ -72,13 +67,7 @@ pub fn getDocCommentTokenIndex(tokens: []std.zig.Token.Tag, base_token: ast.Toke
|
|||||||
} else idx + 1;
|
} else idx + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collectDocComments(
|
pub fn collectDocComments(allocator: *std.mem.Allocator, tree: Analysis.Tree, doc_comments: ast.TokenIndex, format: types.MarkupContent.Kind, container_doc: bool) ![]const u8 {
|
||||||
allocator: *std.mem.Allocator,
|
|
||||||
tree: Analysis.Tree,
|
|
||||||
doc_comments: ast.TokenIndex,
|
|
||||||
format: types.MarkupContent.Kind,
|
|
||||||
container_doc: bool,
|
|
||||||
) ![]const u8 {
|
|
||||||
var lines = std.ArrayList([]const u8).init(allocator);
|
var lines = std.ArrayList([]const u8).init(allocator);
|
||||||
defer lines.deinit();
|
defer lines.deinit();
|
||||||
const tokens = tree.tokens.items(.tag);
|
const tokens = tree.tokens.items(.tag);
|
||||||
@ -106,12 +95,7 @@ pub fn getFunctionSignature(tree: Analysis.Tree, func: ast.full.FnProto) []const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates snippet insert text for a function. Caller owns returned memory.
|
/// Creates snippet insert text for a function. Caller owns returned memory.
|
||||||
pub fn getFunctionSnippet(
|
pub fn getFunctionSnippet(allocator: *std.mem.Allocator, tree: Analysis.Tree, func: ast.full.FnProto, skip_self_param: bool) ![]const u8 {
|
||||||
allocator: *std.mem.Allocator,
|
|
||||||
tree: Analysis.Tree,
|
|
||||||
func: ast.full.FnProto,
|
|
||||||
skip_self_param: bool,
|
|
||||||
) ![]const u8 {
|
|
||||||
const name_index = func.name_token.?;
|
const name_index = func.name_token.?;
|
||||||
|
|
||||||
var buffer = std.ArrayList(u8).init(allocator);
|
var buffer = std.ArrayList(u8).init(allocator);
|
||||||
@ -172,12 +156,7 @@ pub fn getFunctionSnippet(
|
|||||||
return buffer.toOwnedSlice();
|
return buffer.toOwnedSlice();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hasSelfParam(
|
pub fn hasSelfParam(arena: *std.heap.ArenaAllocator, document_store: *DocumentStore, handle: *DocumentStore.Handle, func: ast.full.FnProto) !bool {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
document_store: *DocumentStore,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
func: ast.full.FnProto,
|
|
||||||
) !bool {
|
|
||||||
// Non-decl prototypes cannot have a self parameter.
|
// Non-decl prototypes cannot have a self parameter.
|
||||||
if (func.name_token == null) return false;
|
if (func.name_token == null) return false;
|
||||||
if (func.ast.params.len == 0) return false;
|
if (func.ast.params.len == 0) return false;
|
||||||
@ -314,12 +293,7 @@ fn isContainerDecl(decl_handle: DeclWithHandle) bool {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolveVarDeclAliasInternal(
|
fn resolveVarDeclAliasInternal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle, root: bool) error{OutOfMemory}!?DeclWithHandle {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
node_handle: NodeWithHandle,
|
|
||||||
root: bool,
|
|
||||||
) error{OutOfMemory}!?DeclWithHandle {
|
|
||||||
_ = root;
|
_ = root;
|
||||||
const handle = node_handle.handle;
|
const handle = node_handle.handle;
|
||||||
const tree = handle.tree;
|
const tree = handle.tree;
|
||||||
@ -406,12 +380,7 @@ fn isBlock(tree: Analysis.Tree, node: ast.Node.Index) bool {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn findReturnStatementInternal(
|
fn findReturnStatementInternal(tree: Analysis.Tree, fn_decl: ast.full.FnProto, body: ast.Node.Index, already_found: *bool) ?ast.Node.Index {
|
||||||
tree: Analysis.Tree,
|
|
||||||
fn_decl: ast.full.FnProto,
|
|
||||||
body: ast.Node.Index,
|
|
||||||
already_found: *bool,
|
|
||||||
) ?ast.Node.Index {
|
|
||||||
var result: ?ast.Node.Index = null;
|
var result: ?ast.Node.Index = null;
|
||||||
|
|
||||||
const node_tags = tree.nodes.items(.tag);
|
const node_tags = tree.nodes.items(.tag);
|
||||||
@ -465,14 +434,7 @@ fn findReturnStatement(tree: Analysis.Tree, fn_decl: ast.full.FnProto, body: ast
|
|||||||
return findReturnStatementInternal(tree, fn_decl, body, &already_found);
|
return findReturnStatementInternal(tree, fn_decl, body, &already_found);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolveReturnType(
|
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 {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
fn_decl: ast.full.FnProto,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
bound_type_params: *BoundTypeParams,
|
|
||||||
fn_body: ?ast.Node.Index,
|
|
||||||
) !?TypeWithHandle {
|
|
||||||
const tree = handle.tree;
|
const tree = handle.tree;
|
||||||
if (isTypeFunction(tree, fn_decl) and fn_body != null) {
|
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
|
// If this is a type function and it only contains a single return statement that returns
|
||||||
@ -509,12 +471,7 @@ pub fn resolveReturnType(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Resolves the child type of an optional type
|
/// Resolves the child type of an optional type
|
||||||
fn resolveUnwrapOptionalType(
|
fn resolveUnwrapOptionalType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, opt: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
opt: TypeWithHandle,
|
|
||||||
bound_type_params: *BoundTypeParams,
|
|
||||||
) !?TypeWithHandle {
|
|
||||||
const opt_node = switch (opt.type.data) {
|
const opt_node = switch (opt.type.data) {
|
||||||
.other => |n| n,
|
.other => |n| n,
|
||||||
else => return null,
|
else => return null,
|
||||||
@ -530,12 +487,7 @@ fn resolveUnwrapOptionalType(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolveUnwrapErrorType(
|
fn resolveUnwrapErrorType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, rhs: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
rhs: TypeWithHandle,
|
|
||||||
bound_type_params: *BoundTypeParams,
|
|
||||||
) !?TypeWithHandle {
|
|
||||||
const rhs_node = switch (rhs.type.data) {
|
const rhs_node = switch (rhs.type.data) {
|
||||||
.other => |n| n,
|
.other => |n| n,
|
||||||
.error_union => |n| return TypeWithHandle{
|
.error_union => |n| return TypeWithHandle{
|
||||||
@ -567,12 +519,7 @@ pub fn isPtrType(tree: Analysis.Tree, node: ast.Node.Index) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Resolves the child type of a deref type
|
/// Resolves the child type of a deref type
|
||||||
fn resolveDerefType(
|
fn resolveDerefType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, deref: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
deref: TypeWithHandle,
|
|
||||||
bound_type_params: *BoundTypeParams,
|
|
||||||
) !?TypeWithHandle {
|
|
||||||
const deref_node = switch (deref.type.data) {
|
const deref_node = switch (deref.type.data) {
|
||||||
.other => |n| n,
|
.other => |n| n,
|
||||||
.pointer => |n| return TypeWithHandle{
|
.pointer => |n| return TypeWithHandle{
|
||||||
@ -605,13 +552,7 @@ fn resolveDerefType(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Resolves slicing and array access
|
/// Resolves slicing and array access
|
||||||
fn resolveBracketAccessType(
|
fn resolveBracketAccessType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, lhs: TypeWithHandle, rhs: enum { Single, Range }, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
lhs: TypeWithHandle,
|
|
||||||
rhs: enum { Single, Range },
|
|
||||||
bound_type_params: *BoundTypeParams,
|
|
||||||
) !?TypeWithHandle {
|
|
||||||
const lhs_node = switch (lhs.type.data) {
|
const lhs_node = switch (lhs.type.data) {
|
||||||
.other => |n| n,
|
.other => |n| n,
|
||||||
else => return null,
|
else => return null,
|
||||||
@ -648,12 +589,7 @@ fn resolveBracketAccessType(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Called to remove one level of pointerness before a field access
|
/// Called to remove one level of pointerness before a field access
|
||||||
pub fn resolveFieldAccessLhsType(
|
pub fn resolveFieldAccessLhsType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, lhs: TypeWithHandle, bound_type_params: *BoundTypeParams) !TypeWithHandle {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
lhs: TypeWithHandle,
|
|
||||||
bound_type_params: *BoundTypeParams,
|
|
||||||
) !TypeWithHandle {
|
|
||||||
return (try resolveDerefType(store, arena, lhs, bound_type_params)) orelse lhs;
|
return (try resolveDerefType(store, arena, lhs, bound_type_params)) orelse lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,12 +627,7 @@ pub fn isTypeIdent(tree: Analysis.Tree, token_idx: ast.TokenIndex) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Resolves the type of a node
|
/// Resolves the type of a node
|
||||||
pub fn resolveTypeOfNodeInternal(
|
pub fn resolveTypeOfNodeInternal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle, bound_type_params: *BoundTypeParams) error{OutOfMemory}!?TypeWithHandle {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
node_handle: NodeWithHandle,
|
|
||||||
bound_type_params: *BoundTypeParams,
|
|
||||||
) error{OutOfMemory}!?TypeWithHandle {
|
|
||||||
// If we were asked to resolve this node before,
|
// If we were asked to resolve this node before,
|
||||||
// it is self-referential and we cannot resolve it.
|
// it is self-referential and we cannot resolve it.
|
||||||
for (resolve_trail.items) |i| {
|
for (resolve_trail.items) |i| {
|
||||||
@ -1201,13 +1132,7 @@ pub const FieldAccessReturn = struct {
|
|||||||
unwrapped: ?TypeWithHandle = null,
|
unwrapped: ?TypeWithHandle = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn getFieldAccessType(
|
pub fn getFieldAccessType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *DocumentStore.Handle, source_index: usize, tokenizer: *std.zig.Tokenizer) !?FieldAccessReturn {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
source_index: usize,
|
|
||||||
tokenizer: *std.zig.Tokenizer,
|
|
||||||
) !?FieldAccessReturn {
|
|
||||||
var current_type = TypeWithHandle.typeVal(.{
|
var current_type = TypeWithHandle.typeVal(.{
|
||||||
.node = undefined,
|
.node = undefined,
|
||||||
.handle = handle,
|
.handle = handle,
|
||||||
@ -1518,11 +1443,7 @@ fn tokenRangeAppend(prev: SourceRange, token: std.zig.Token) SourceRange {
|
|||||||
|
|
||||||
const DocumentPosition = offsets.DocumentPosition;
|
const DocumentPosition = offsets.DocumentPosition;
|
||||||
|
|
||||||
pub fn documentPositionContext(
|
pub fn documentPositionContext(arena: *std.heap.ArenaAllocator, document: types.TextDocument, doc_position: DocumentPosition) !PositionContext {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
document: types.TextDocument,
|
|
||||||
doc_position: DocumentPosition,
|
|
||||||
) !PositionContext {
|
|
||||||
_ = document;
|
_ = document;
|
||||||
|
|
||||||
const line = doc_position.line;
|
const line = doc_position.line;
|
||||||
@ -1808,12 +1729,7 @@ const GetDocumentSymbolsContext = struct {
|
|||||||
encoding: offsets.Encoding,
|
encoding: offsets.Encoding,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn getDocumentSymbolsInternal(
|
fn getDocumentSymbolsInternal(allocator: *std.mem.Allocator, tree: Analysis.Tree, node: ast.Node.Index, context: *GetDocumentSymbolsContext) anyerror!void {
|
||||||
allocator: *std.mem.Allocator,
|
|
||||||
tree: Analysis.Tree,
|
|
||||||
node: ast.Node.Index,
|
|
||||||
context: *GetDocumentSymbolsContext,
|
|
||||||
) anyerror!void {
|
|
||||||
const name = getDeclName(tree, node) orelse return;
|
const name = getDeclName(tree, node) orelse return;
|
||||||
if (name.len == 0)
|
if (name.len == 0)
|
||||||
return;
|
return;
|
||||||
@ -2072,16 +1988,7 @@ fn findContainerScope(container_handle: NodeWithHandle) ?*Scope {
|
|||||||
} else null;
|
} else null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iterateSymbolsContainerInternal(
|
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(*const ast.Node.Index)) error{OutOfMemory}!void {
|
||||||
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(*const ast.Node.Index),
|
|
||||||
) error{OutOfMemory}!void {
|
|
||||||
const container = container_handle.node;
|
const container = container_handle.node;
|
||||||
const handle = container_handle.handle;
|
const handle = container_handle.handle;
|
||||||
|
|
||||||
@ -2148,25 +2055,12 @@ fn iterateSymbolsContainerInternal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iterateSymbolsContainer(
|
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 {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
container_handle: NodeWithHandle,
|
|
||||||
orig_handle: *DocumentStore.Handle,
|
|
||||||
comptime callback: anytype,
|
|
||||||
context: anytype,
|
|
||||||
instance_access: bool,
|
|
||||||
) error{OutOfMemory}!void {
|
|
||||||
var use_trail = std.ArrayList(*const ast.Node.Index).init(&arena.allocator);
|
var use_trail = std.ArrayList(*const ast.Node.Index).init(&arena.allocator);
|
||||||
return try iterateSymbolsContainerInternal(store, arena, container_handle, orig_handle, callback, context, instance_access, &use_trail);
|
return try iterateSymbolsContainerInternal(store, arena, container_handle, orig_handle, callback, context, instance_access, &use_trail);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iterateLabels(
|
pub fn iterateLabels(handle: *DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype) error{OutOfMemory}!void {
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
source_index: usize,
|
|
||||||
comptime callback: anytype,
|
|
||||||
context: anytype,
|
|
||||||
) error{OutOfMemory}!void {
|
|
||||||
for (handle.document_scope.scopes) |scope| {
|
for (handle.document_scope.scopes) |scope| {
|
||||||
if (source_index >= scope.range.start and source_index < scope.range.end) {
|
if (source_index >= scope.range.start and source_index < scope.range.end) {
|
||||||
var decl_it = scope.decls.iterator();
|
var decl_it = scope.decls.iterator();
|
||||||
@ -2182,15 +2076,7 @@ pub fn iterateLabels(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iterateSymbolsGlobalInternal(
|
fn iterateSymbolsGlobalInternal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype, use_trail: *std.ArrayList(*const ast.Node.Index)) error{OutOfMemory}!void {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
source_index: usize,
|
|
||||||
comptime callback: anytype,
|
|
||||||
context: anytype,
|
|
||||||
use_trail: *std.ArrayList(*const ast.Node.Index),
|
|
||||||
) error{OutOfMemory}!void {
|
|
||||||
for (handle.document_scope.scopes) |scope| {
|
for (handle.document_scope.scopes) |scope| {
|
||||||
if (source_index >= scope.range.start and source_index <= scope.range.end) {
|
if (source_index >= scope.range.start and source_index <= scope.range.end) {
|
||||||
var decl_it = scope.decls.iterator();
|
var decl_it = scope.decls.iterator();
|
||||||
@ -2231,14 +2117,7 @@ fn iterateSymbolsGlobalInternal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iterateSymbolsGlobal(
|
pub fn iterateSymbolsGlobal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype) error{OutOfMemory}!void {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
source_index: usize,
|
|
||||||
comptime callback: anytype,
|
|
||||||
context: anytype,
|
|
||||||
) error{OutOfMemory}!void {
|
|
||||||
var use_trail = std.ArrayList(*const ast.Node.Index).init(&arena.allocator);
|
var use_trail = std.ArrayList(*const ast.Node.Index).init(&arena.allocator);
|
||||||
return try iterateSymbolsGlobalInternal(store, arena, handle, source_index, callback, context, &use_trail);
|
return try iterateSymbolsGlobalInternal(store, arena, handle, source_index, callback, context, &use_trail);
|
||||||
}
|
}
|
||||||
@ -2279,13 +2158,7 @@ pub fn innermostContainer(handle: *DocumentStore.Handle, source_index: usize) Ty
|
|||||||
return TypeWithHandle.typeVal(.{ .node = current, .handle = handle });
|
return TypeWithHandle.typeVal(.{ .node = current, .handle = handle });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolveUse(
|
fn resolveUse(store: *DocumentStore, arena: *std.heap.ArenaAllocator, uses: []const *const ast.Node.Index, symbol: []const u8, handle: *DocumentStore.Handle) error{OutOfMemory}!?DeclWithHandle {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
uses: []const *const ast.Node.Index,
|
|
||||||
symbol: []const u8,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
) error{OutOfMemory}!?DeclWithHandle {
|
|
||||||
// If we were asked to resolve this symbol before,
|
// If we were asked to resolve this symbol before,
|
||||||
// it is self-referential and we cannot resolve it.
|
// it is self-referential and we cannot resolve it.
|
||||||
if (std.mem.indexOfScalar([*]const u8, using_trail.items, symbol.ptr) != null)
|
if (std.mem.indexOfScalar([*]const u8, using_trail.items, symbol.ptr) != null)
|
||||||
@ -2319,11 +2192,7 @@ fn resolveUse(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lookupLabel(
|
pub fn lookupLabel(handle: *DocumentStore.Handle, symbol: []const u8, source_index: usize) error{OutOfMemory}!?DeclWithHandle {
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
symbol: []const u8,
|
|
||||||
source_index: usize,
|
|
||||||
) error{OutOfMemory}!?DeclWithHandle {
|
|
||||||
for (handle.document_scope.scopes) |scope| {
|
for (handle.document_scope.scopes) |scope| {
|
||||||
if (source_index >= scope.range.start and source_index < scope.range.end) {
|
if (source_index >= scope.range.start and source_index < scope.range.end) {
|
||||||
if (scope.decls.getEntry(symbol)) |candidate| {
|
if (scope.decls.getEntry(symbol)) |candidate| {
|
||||||
@ -2342,13 +2211,7 @@ pub fn lookupLabel(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lookupSymbolGlobal(
|
pub fn lookupSymbolGlobal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *DocumentStore.Handle, symbol: []const u8, source_index: usize) error{OutOfMemory}!?DeclWithHandle {
|
||||||
store: *DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
symbol: []const u8,
|
|
||||||
source_index: usize,
|
|
||||||
) error{OutOfMemory}!?DeclWithHandle {
|
|
||||||
const innermost_scope_idx = innermostBlockScopeIndex(handle.*, source_index);
|
const innermost_scope_idx = innermostBlockScopeIndex(handle.*, source_index);
|
||||||
|
|
||||||
var curr = innermost_scope_idx;
|
var curr = innermost_scope_idx;
|
||||||
@ -2555,11 +2418,7 @@ const ScopeContext = struct {
|
|||||||
tree: Analysis.Tree,
|
tree: Analysis.Tree,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn makeInnerScope(
|
fn makeInnerScope(allocator: *std.mem.Allocator, context: ScopeContext, node_idx: ast.Node.Index) error{OutOfMemory}!void {
|
||||||
allocator: *std.mem.Allocator,
|
|
||||||
context: ScopeContext,
|
|
||||||
node_idx: ast.Node.Index,
|
|
||||||
) error{OutOfMemory}!void {
|
|
||||||
const scopes = context.scopes;
|
const scopes = context.scopes;
|
||||||
const tree = context.tree;
|
const tree = context.tree;
|
||||||
const tags = tree.nodes.items(.tag);
|
const tags = tree.nodes.items(.tag);
|
||||||
@ -2675,11 +2534,7 @@ fn makeInnerScope(
|
|||||||
|
|
||||||
// Whether we have already visited the root node.
|
// Whether we have already visited the root node.
|
||||||
var had_root = true;
|
var had_root = true;
|
||||||
fn makeScopeInternal(
|
fn makeScopeInternal(allocator: *std.mem.Allocator, context: ScopeContext, node_idx: ast.Node.Index) error{OutOfMemory}!void {
|
||||||
allocator: *std.mem.Allocator,
|
|
||||||
context: ScopeContext,
|
|
||||||
node_idx: ast.Node.Index,
|
|
||||||
) error{OutOfMemory}!void {
|
|
||||||
const scopes = context.scopes;
|
const scopes = context.scopes;
|
||||||
const tree = context.tree;
|
const tree = context.tree;
|
||||||
const tags = tree.nodes.items(.tag);
|
const tags = tree.nodes.items(.tag);
|
||||||
|
@ -53,14 +53,7 @@ build_runner_path: []const u8,
|
|||||||
build_runner_cache_path: []const u8,
|
build_runner_cache_path: []const u8,
|
||||||
std_uri: ?[]const u8,
|
std_uri: ?[]const u8,
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(self: *DocumentStore, allocator: *std.mem.Allocator, zig_exe_path: ?[]const u8, build_runner_path: []const u8, build_runner_cache_path: []const u8, zig_lib_path: ?[]const u8) !void {
|
||||||
self: *DocumentStore,
|
|
||||||
allocator: *std.mem.Allocator,
|
|
||||||
zig_exe_path: ?[]const u8,
|
|
||||||
build_runner_path: []const u8,
|
|
||||||
build_runner_cache_path: []const u8,
|
|
||||||
zig_lib_path: ?[]const u8,
|
|
||||||
) !void {
|
|
||||||
self.allocator = allocator;
|
self.allocator = allocator;
|
||||||
self.handles = std.StringHashMap(*Handle).init(allocator);
|
self.handles = std.StringHashMap(*Handle).init(allocator);
|
||||||
self.zig_exe_path = zig_exe_path;
|
self.zig_exe_path = zig_exe_path;
|
||||||
@ -502,12 +495,7 @@ pub fn applySave(self: *DocumentStore, handle: *Handle) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn applyChanges(
|
pub fn applyChanges(self: *DocumentStore, handle: *Handle, content_changes: std.json.Array, offset_encoding: offsets.Encoding) !void {
|
||||||
self: *DocumentStore,
|
|
||||||
handle: *Handle,
|
|
||||||
content_changes: std.json.Array,
|
|
||||||
offset_encoding: offsets.Encoding,
|
|
||||||
) !void {
|
|
||||||
const document = &handle.document;
|
const document = &handle.document;
|
||||||
|
|
||||||
for (content_changes.items) |change| {
|
for (content_changes.items) |change| {
|
||||||
@ -574,12 +562,7 @@ pub fn applyChanges(
|
|||||||
try self.refreshDocument(handle);
|
try self.refreshDocument(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uriFromImportStr(
|
pub fn uriFromImportStr(self: *DocumentStore, allocator: *std.mem.Allocator, handle: Handle, import_str: []const u8) !?[]const u8 {
|
||||||
self: *DocumentStore,
|
|
||||||
allocator: *std.mem.Allocator,
|
|
||||||
handle: Handle,
|
|
||||||
import_str: []const u8,
|
|
||||||
) !?[]const u8 {
|
|
||||||
if (std.mem.eql(u8, import_str, "std")) {
|
if (std.mem.eql(u8, import_str, "std")) {
|
||||||
if (self.std_uri) |uri| return try std.mem.dupe(allocator, u8, uri) else {
|
if (self.std_uri) |uri| return try std.mem.dupe(allocator, u8, uri) else {
|
||||||
log.debug("Cannot resolve std library import, path is null.", .{});
|
log.debug("Cannot resolve std library import, path is null.", .{});
|
||||||
@ -742,12 +725,7 @@ pub fn deinit(self: *DocumentStore) void {
|
|||||||
self.build_files.deinit(self.allocator);
|
self.build_files.deinit(self.allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tagStoreCompletionItems(
|
fn tagStoreCompletionItems(self: DocumentStore, arena: *std.heap.ArenaAllocator, base: *DocumentStore.Handle, comptime name: []const u8) ![]types.CompletionItem {
|
||||||
self: DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
base: *DocumentStore.Handle,
|
|
||||||
comptime name: []const u8,
|
|
||||||
) ![]types.CompletionItem {
|
|
||||||
// TODO Better solution for deciding what tags to include
|
// TODO Better solution for deciding what tags to include
|
||||||
var max_len: usize = @field(base.document_scope, name).count();
|
var max_len: usize = @field(base.document_scope, name).count();
|
||||||
for (base.imports_used.items) |uri| {
|
for (base.imports_used.items) |uri| {
|
||||||
@ -769,18 +747,10 @@ fn tagStoreCompletionItems(
|
|||||||
return result_set.entries.items(.key);
|
return result_set.entries.items(.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn errorCompletionItems(
|
pub fn errorCompletionItems(self: DocumentStore, arena: *std.heap.ArenaAllocator, base: *DocumentStore.Handle) ![]types.CompletionItem {
|
||||||
self: DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
base: *DocumentStore.Handle,
|
|
||||||
) ![]types.CompletionItem {
|
|
||||||
return try self.tagStoreCompletionItems(arena, base, "error_completions");
|
return try self.tagStoreCompletionItems(arena, base, "error_completions");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enumCompletionItems(
|
pub fn enumCompletionItems(self: DocumentStore, arena: *std.heap.ArenaAllocator, base: *DocumentStore.Handle) ![]types.CompletionItem {
|
||||||
self: DocumentStore,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
base: *DocumentStore.Handle,
|
|
||||||
) ![]types.CompletionItem {
|
|
||||||
return try self.tagStoreCompletionItems(arena, base, "enum_completions");
|
return try self.tagStoreCompletionItems(arena, base, "enum_completions");
|
||||||
}
|
}
|
||||||
|
126
src/main.zig
126
src/main.zig
@ -348,16 +348,7 @@ fn typeToCompletion(arena: *std.heap.ArenaAllocator, list: *std.ArrayList(types.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nodeToCompletion(
|
fn nodeToCompletion(arena: *std.heap.ArenaAllocator, list: *std.ArrayList(types.CompletionItem), node_handle: analysis.NodeWithHandle, unwrapped: ?analysis.TypeWithHandle, orig_handle: *DocumentStore.Handle, is_type_val: bool, parent_is_type_val: ?bool, config: Config) error{OutOfMemory}!void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
list: *std.ArrayList(types.CompletionItem),
|
|
||||||
node_handle: analysis.NodeWithHandle,
|
|
||||||
unwrapped: ?analysis.TypeWithHandle,
|
|
||||||
orig_handle: *DocumentStore.Handle,
|
|
||||||
is_type_val: bool,
|
|
||||||
parent_is_type_val: ?bool,
|
|
||||||
config: Config,
|
|
||||||
) error{OutOfMemory}!void {
|
|
||||||
const node = node_handle.node;
|
const node = node_handle.node;
|
||||||
const handle = node_handle.handle;
|
const handle = node_handle.handle;
|
||||||
const tree = handle.tree;
|
const tree = handle.tree;
|
||||||
@ -614,11 +605,7 @@ fn gotoDefinitionSymbol(id: types.RequestId, arena: *std.heap.ArenaAllocator, de
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hoverSymbol(
|
fn hoverSymbol(id: types.RequestId, arena: *std.heap.ArenaAllocator, decl_handle: analysis.DeclWithHandle) (std.os.WriteError || error{OutOfMemory})!void {
|
||||||
id: types.RequestId,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
decl_handle: analysis.DeclWithHandle,
|
|
||||||
) (std.os.WriteError || error{OutOfMemory})!void {
|
|
||||||
const handle = decl_handle.handle;
|
const handle = decl_handle.handle;
|
||||||
const tree = handle.tree;
|
const tree = handle.tree;
|
||||||
|
|
||||||
@ -758,13 +745,7 @@ fn hoverDefinitionGlobal(arena: *std.heap.ArenaAllocator, id: types.RequestId, p
|
|||||||
return try hoverSymbol(id, arena, decl);
|
return try hoverSymbol(id, arena, decl);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getSymbolFieldAccess(
|
fn getSymbolFieldAccess(handle: *DocumentStore.Handle, arena: *std.heap.ArenaAllocator, position: offsets.DocumentPosition, range: analysis.SourceRange, config: Config) !?analysis.DeclWithHandle {
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
position: offsets.DocumentPosition,
|
|
||||||
range: analysis.SourceRange,
|
|
||||||
config: Config,
|
|
||||||
) !?analysis.DeclWithHandle {
|
|
||||||
_ = config;
|
_ = config;
|
||||||
|
|
||||||
const name = identifierFromPosition(position.absolute_index, handle.*);
|
const name = identifierFromPosition(position.absolute_index, handle.*);
|
||||||
@ -793,27 +774,12 @@ fn getSymbolFieldAccess(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gotoDefinitionFieldAccess(
|
fn gotoDefinitionFieldAccess(arena: *std.heap.ArenaAllocator, id: types.RequestId, handle: *DocumentStore.Handle, position: offsets.DocumentPosition, range: analysis.SourceRange, config: Config, resolve_alias: bool) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
id: types.RequestId,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
position: offsets.DocumentPosition,
|
|
||||||
range: analysis.SourceRange,
|
|
||||||
config: Config,
|
|
||||||
resolve_alias: bool,
|
|
||||||
) !void {
|
|
||||||
const decl = (try getSymbolFieldAccess(handle, arena, position, range, config)) orelse return try respondGeneric(id, null_result_response);
|
const decl = (try getSymbolFieldAccess(handle, arena, position, range, config)) orelse return try respondGeneric(id, null_result_response);
|
||||||
return try gotoDefinitionSymbol(id, arena, decl, resolve_alias);
|
return try gotoDefinitionSymbol(id, arena, decl, resolve_alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hoverDefinitionFieldAccess(
|
fn hoverDefinitionFieldAccess(arena: *std.heap.ArenaAllocator, id: types.RequestId, handle: *DocumentStore.Handle, position: offsets.DocumentPosition, range: analysis.SourceRange, config: Config) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
id: types.RequestId,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
position: offsets.DocumentPosition,
|
|
||||||
range: analysis.SourceRange,
|
|
||||||
config: Config,
|
|
||||||
) !void {
|
|
||||||
const decl = (try getSymbolFieldAccess(handle, arena, position, range, config)) orelse return try respondGeneric(id, null_result_response);
|
const decl = (try getSymbolFieldAccess(handle, arena, position, range, config)) orelse return try respondGeneric(id, null_result_response);
|
||||||
return try hoverSymbol(id, arena, decl);
|
return try hoverSymbol(id, arena, decl);
|
||||||
}
|
}
|
||||||
@ -857,15 +823,7 @@ fn renameDefinitionGlobal(arena: *std.heap.ArenaAllocator, id: types.RequestId,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn renameDefinitionFieldAccess(
|
fn renameDefinitionFieldAccess(arena: *std.heap.ArenaAllocator, id: types.RequestId, handle: *DocumentStore.Handle, position: offsets.DocumentPosition, range: analysis.SourceRange, new_name: []const u8, config: Config) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
id: types.RequestId,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
position: offsets.DocumentPosition,
|
|
||||||
range: analysis.SourceRange,
|
|
||||||
new_name: []const u8,
|
|
||||||
config: Config,
|
|
||||||
) !void {
|
|
||||||
const decl = (try getSymbolFieldAccess(handle, arena, position, range, config)) orelse return try respondGeneric(id, null_result_response);
|
const decl = (try getSymbolFieldAccess(handle, arena, position, range, config)) orelse return try respondGeneric(id, null_result_response);
|
||||||
|
|
||||||
var workspace_edit = types.WorkspaceEdit{
|
var workspace_edit = types.WorkspaceEdit{
|
||||||
@ -891,14 +849,7 @@ fn renameDefinitionLabel(arena: *std.heap.ArenaAllocator, id: types.RequestId, h
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn referencesDefinitionGlobal(
|
fn referencesDefinitionGlobal(arena: *std.heap.ArenaAllocator, id: types.RequestId, handle: *DocumentStore.Handle, pos_index: usize, include_decl: bool, skip_std_references: bool) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
id: types.RequestId,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
pos_index: usize,
|
|
||||||
include_decl: bool,
|
|
||||||
skip_std_references: bool,
|
|
||||||
) !void {
|
|
||||||
const decl = (try getSymbolGlobal(arena, pos_index, handle)) orelse return try respondGeneric(id, null_result_response);
|
const decl = (try getSymbolGlobal(arena, pos_index, handle)) orelse return try respondGeneric(id, null_result_response);
|
||||||
var locs = std.ArrayList(types.Location).init(&arena.allocator);
|
var locs = std.ArrayList(types.Location).init(&arena.allocator);
|
||||||
try references.symbolReferences(
|
try references.symbolReferences(
|
||||||
@ -917,15 +868,7 @@ fn referencesDefinitionGlobal(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn referencesDefinitionFieldAccess(
|
fn referencesDefinitionFieldAccess(arena: *std.heap.ArenaAllocator, id: types.RequestId, handle: *DocumentStore.Handle, position: offsets.DocumentPosition, range: analysis.SourceRange, include_decl: bool, config: Config) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
id: types.RequestId,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
position: offsets.DocumentPosition,
|
|
||||||
range: analysis.SourceRange,
|
|
||||||
include_decl: bool,
|
|
||||||
config: Config,
|
|
||||||
) !void {
|
|
||||||
const decl = (try getSymbolFieldAccess(handle, arena, position, range, config)) orelse return try respondGeneric(id, null_result_response);
|
const decl = (try getSymbolFieldAccess(handle, arena, position, range, config)) orelse return try respondGeneric(id, null_result_response);
|
||||||
var locs = std.ArrayList(types.Location).init(&arena.allocator);
|
var locs = std.ArrayList(types.Location).init(&arena.allocator);
|
||||||
try references.symbolReferences(arena, &document_store, decl, offset_encoding, include_decl, &locs, std.ArrayList(types.Location).append, config.skip_std_references);
|
try references.symbolReferences(arena, &document_store, decl, offset_encoding, include_decl, &locs, std.ArrayList(types.Location).append, config.skip_std_references);
|
||||||
@ -1109,13 +1052,7 @@ fn completeBuiltin(arena: *std.heap.ArenaAllocator, id: types.RequestId, config:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn completeGlobal(
|
fn completeGlobal(arena: *std.heap.ArenaAllocator, id: types.RequestId, pos_index: usize, handle: *DocumentStore.Handle, config: Config) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
id: types.RequestId,
|
|
||||||
pos_index: usize,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
config: Config,
|
|
||||||
) !void {
|
|
||||||
var completions = std.ArrayList(types.CompletionItem).init(&arena.allocator);
|
var completions = std.ArrayList(types.CompletionItem).init(&arena.allocator);
|
||||||
|
|
||||||
const context = DeclToCompletionContext{
|
const context = DeclToCompletionContext{
|
||||||
@ -1138,14 +1075,7 @@ fn completeGlobal(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn completeFieldAccess(
|
fn completeFieldAccess(arena: *std.heap.ArenaAllocator, id: types.RequestId, handle: *DocumentStore.Handle, position: offsets.DocumentPosition, range: analysis.SourceRange, config: Config) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
id: types.RequestId,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
position: offsets.DocumentPosition,
|
|
||||||
range: analysis.SourceRange,
|
|
||||||
config: Config,
|
|
||||||
) !void {
|
|
||||||
var completions = std.ArrayList(types.CompletionItem).init(&arena.allocator);
|
var completions = std.ArrayList(types.CompletionItem).init(&arena.allocator);
|
||||||
|
|
||||||
const line_mem_start = @ptrToInt(position.line.ptr) - @ptrToInt(handle.document.mem.ptr);
|
const line_mem_start = @ptrToInt(position.line.ptr) - @ptrToInt(handle.document.mem.ptr);
|
||||||
@ -1170,12 +1100,7 @@ fn completeFieldAccess(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn completeError(
|
fn completeError(arena: *std.heap.ArenaAllocator, id: types.RequestId, handle: *DocumentStore.Handle, config: Config) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
id: types.RequestId,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
config: Config,
|
|
||||||
) !void {
|
|
||||||
const completions = try document_store.errorCompletionItems(arena, handle);
|
const completions = try document_store.errorCompletionItems(arena, handle);
|
||||||
truncateCompletions(completions, config.max_detail_length);
|
truncateCompletions(completions, config.max_detail_length);
|
||||||
logger.debug("Completing error:", .{});
|
logger.debug("Completing error:", .{});
|
||||||
@ -1191,12 +1116,7 @@ fn completeError(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn completeDot(
|
fn completeDot(arena: *std.heap.ArenaAllocator, id: types.RequestId, handle: *DocumentStore.Handle, config: Config) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
id: types.RequestId,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
config: Config,
|
|
||||||
) !void {
|
|
||||||
var completions = try document_store.enumCompletionItems(arena, handle);
|
var completions = try document_store.enumCompletionItems(arena, handle);
|
||||||
truncateCompletions(completions, config.max_detail_length);
|
truncateCompletions(completions, config.max_detail_length);
|
||||||
|
|
||||||
@ -1432,12 +1352,7 @@ fn semanticTokensFullHandler(arena: *std.heap.ArenaAllocator, id: types.RequestI
|
|||||||
return try respondGeneric(id, no_semantic_tokens_response);
|
return try respondGeneric(id, no_semantic_tokens_response);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn completionHandler(
|
fn completionHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.Completion, config: Config) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
id: types.RequestId,
|
|
||||||
req: requests.Completion,
|
|
||||||
config: Config,
|
|
||||||
) !void {
|
|
||||||
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
|
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
|
||||||
logger.warn("Trying to complete in non existent document {s}", .{req.params.textDocument.uri});
|
logger.warn("Trying to complete in non existent document {s}", .{req.params.textDocument.uri});
|
||||||
return try respondGeneric(id, no_completions_response);
|
return try respondGeneric(id, no_completions_response);
|
||||||
@ -1460,12 +1375,7 @@ fn completionHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signatureHelpHandler(
|
fn signatureHelpHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.SignatureHelp, config: Config) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
id: types.RequestId,
|
|
||||||
req: requests.SignatureHelp,
|
|
||||||
config: Config,
|
|
||||||
) !void {
|
|
||||||
_ = config;
|
_ = config;
|
||||||
|
|
||||||
const getSignatureInfo = @import("signature_help.zig").getSignatureInfo;
|
const getSignatureInfo = @import("signature_help.zig").getSignatureInfo;
|
||||||
@ -1499,13 +1409,7 @@ fn signatureHelpHandler(
|
|||||||
return try respondGeneric(id, no_signatures_response);
|
return try respondGeneric(id, no_signatures_response);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gotoHandler(
|
fn gotoHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: requests.GotoDefinition, config: Config, resolve_alias: bool) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
id: types.RequestId,
|
|
||||||
req: requests.GotoDefinition,
|
|
||||||
config: Config,
|
|
||||||
resolve_alias: bool,
|
|
||||||
) !void {
|
|
||||||
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
|
const handle = document_store.getHandle(req.params.textDocument.uri) orelse {
|
||||||
logger.warn("Trying to go to definition in non existent document {s}", .{req.params.textDocument.uri});
|
logger.warn("Trying to go to definition in non existent document {s}", .{req.params.textDocument.uri});
|
||||||
return try respondGeneric(id, null_result_response);
|
return try respondGeneric(id, null_result_response);
|
||||||
|
@ -9,13 +9,7 @@ usingnamespace @import("./ast.zig");
|
|||||||
|
|
||||||
const ast = std.zig.Ast;
|
const ast = std.zig.Ast;
|
||||||
|
|
||||||
fn tokenReference(
|
fn tokenReference(handle: *DocumentStore.Handle, tok: ast.TokenIndex, encoding: offsets.Encoding, context: anytype, comptime handler: anytype) !void {
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
tok: ast.TokenIndex,
|
|
||||||
encoding: offsets.Encoding,
|
|
||||||
context: anytype,
|
|
||||||
comptime handler: anytype,
|
|
||||||
) !void {
|
|
||||||
const loc = offsets.tokenRelativeLocation(handle.tree, 0, handle.tree.tokens.items(.start)[tok], encoding) catch return;
|
const loc = offsets.tokenRelativeLocation(handle.tree, 0, handle.tree.tokens.items(.start)[tok], encoding) catch return;
|
||||||
try handler(context, types.Location{
|
try handler(context, types.Location{
|
||||||
.uri = handle.uri(),
|
.uri = handle.uri(),
|
||||||
@ -32,14 +26,7 @@ fn tokenReference(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn labelReferences(
|
pub fn labelReferences(arena: *std.heap.ArenaAllocator, decl: analysis.DeclWithHandle, encoding: offsets.Encoding, include_decl: bool, context: anytype, comptime handler: anytype) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
decl: analysis.DeclWithHandle,
|
|
||||||
encoding: offsets.Encoding,
|
|
||||||
include_decl: bool,
|
|
||||||
context: anytype,
|
|
||||||
comptime handler: anytype,
|
|
||||||
) !void {
|
|
||||||
_ = arena;
|
_ = arena;
|
||||||
|
|
||||||
std.debug.assert(decl.decl.* == .label_decl);
|
std.debug.assert(decl.decl.* == .label_decl);
|
||||||
@ -70,15 +57,7 @@ pub fn labelReferences(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn symbolReferencesInternal(
|
fn symbolReferencesInternal(arena: *std.heap.ArenaAllocator, store: *DocumentStore, node_handle: analysis.NodeWithHandle, decl: analysis.DeclWithHandle, encoding: offsets.Encoding, context: anytype, comptime handler: anytype) error{OutOfMemory}!void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
store: *DocumentStore,
|
|
||||||
node_handle: analysis.NodeWithHandle,
|
|
||||||
decl: analysis.DeclWithHandle,
|
|
||||||
encoding: offsets.Encoding,
|
|
||||||
context: anytype,
|
|
||||||
comptime handler: anytype,
|
|
||||||
) error{OutOfMemory}!void {
|
|
||||||
const node = node_handle.node;
|
const node = node_handle.node;
|
||||||
const handle = node_handle.handle;
|
const handle = node_handle.handle;
|
||||||
const tree = handle.tree;
|
const tree = handle.tree;
|
||||||
@ -515,16 +494,7 @@ fn symbolReferencesInternal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn symbolReferences(
|
pub fn symbolReferences(arena: *std.heap.ArenaAllocator, store: *DocumentStore, decl_handle: analysis.DeclWithHandle, encoding: offsets.Encoding, include_decl: bool, context: anytype, comptime handler: anytype, skip_std_references: bool) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
store: *DocumentStore,
|
|
||||||
decl_handle: analysis.DeclWithHandle,
|
|
||||||
encoding: offsets.Encoding,
|
|
||||||
include_decl: bool,
|
|
||||||
context: anytype,
|
|
||||||
comptime handler: anytype,
|
|
||||||
skip_std_references: bool,
|
|
||||||
) !void {
|
|
||||||
std.debug.assert(decl_handle.decl.* != .label_decl);
|
std.debug.assert(decl_handle.decl.* != .label_decl);
|
||||||
const curr_handle = decl_handle.handle;
|
const curr_handle = decl_handle.handle;
|
||||||
if (include_decl) {
|
if (include_decl) {
|
||||||
|
@ -25,14 +25,7 @@ fn refHandler(context: RefHandlerContext, loc: types.Location) !void {
|
|||||||
try context.edits.put(loc.uri, text_edits.toOwnedSlice());
|
try context.edits.put(loc.uri, text_edits.toOwnedSlice());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn renameSymbol(
|
pub fn renameSymbol(arena: *std.heap.ArenaAllocator, store: *DocumentStore, decl_handle: analysis.DeclWithHandle, new_name: []const u8, edits: *std.StringHashMap([]types.TextEdit), encoding: offsets.Encoding) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
store: *DocumentStore,
|
|
||||||
decl_handle: analysis.DeclWithHandle,
|
|
||||||
new_name: []const u8,
|
|
||||||
edits: *std.StringHashMap([]types.TextEdit),
|
|
||||||
encoding: offsets.Encoding,
|
|
||||||
) !void {
|
|
||||||
std.debug.assert(decl_handle.decl.* != .label_decl);
|
std.debug.assert(decl_handle.decl.* != .label_decl);
|
||||||
try references.symbolReferences(arena, store, decl_handle, encoding, true, RefHandlerContext{
|
try references.symbolReferences(arena, store, decl_handle, encoding, true, RefHandlerContext{
|
||||||
.edits = edits,
|
.edits = edits,
|
||||||
@ -41,13 +34,7 @@ pub fn renameSymbol(
|
|||||||
}, refHandler, true);
|
}, refHandler, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn renameLabel(
|
pub fn renameLabel(arena: *std.heap.ArenaAllocator, decl_handle: analysis.DeclWithHandle, new_name: []const u8, edits: *std.StringHashMap([]types.TextEdit), encoding: offsets.Encoding) !void {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
decl_handle: analysis.DeclWithHandle,
|
|
||||||
new_name: []const u8,
|
|
||||||
edits: *std.StringHashMap([]types.TextEdit),
|
|
||||||
encoding: offsets.Encoding,
|
|
||||||
) !void {
|
|
||||||
std.debug.assert(decl_handle.decl.* == .label_decl);
|
std.debug.assert(decl_handle.decl.* == .label_decl);
|
||||||
try references.labelReferences(arena, decl_handle, encoding, true, RefHandlerContext{
|
try references.labelReferences(arena, decl_handle, encoding, true, RefHandlerContext{
|
||||||
.edits = edits,
|
.edits = edits,
|
||||||
|
@ -177,20 +177,11 @@ const Builder = struct {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline fn writeToken(
|
inline fn writeToken(builder: *Builder, token_idx: ?ast.TokenIndex, tok_type: TokenType) !void {
|
||||||
builder: *Builder,
|
|
||||||
token_idx: ?ast.TokenIndex,
|
|
||||||
tok_type: TokenType,
|
|
||||||
) !void {
|
|
||||||
return try writeTokenMod(builder, token_idx, tok_type, .{});
|
return try writeTokenMod(builder, token_idx, tok_type, .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fn writeTokenMod(
|
inline fn writeTokenMod(builder: *Builder, token_idx: ?ast.TokenIndex, tok_type: TokenType, tok_mod: TokenModifiers) !void {
|
||||||
builder: *Builder,
|
|
||||||
token_idx: ?ast.TokenIndex,
|
|
||||||
tok_type: TokenType,
|
|
||||||
tok_mod: TokenModifiers,
|
|
||||||
) !void {
|
|
||||||
if (token_idx) |ti| {
|
if (token_idx) |ti| {
|
||||||
try builder.add(ti, tok_type, tok_mod);
|
try builder.add(ti, tok_type, tok_mod);
|
||||||
}
|
}
|
||||||
@ -258,12 +249,7 @@ const WriteTokensError = error{
|
|||||||
MovedBackwards,
|
MovedBackwards,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn writeNodeTokens(
|
fn writeNodeTokens(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *DocumentStore, maybe_node: ?ast.Node.Index) WriteTokensError!void {
|
||||||
builder: *Builder,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
store: *DocumentStore,
|
|
||||||
maybe_node: ?ast.Node.Index,
|
|
||||||
) WriteTokensError!void {
|
|
||||||
const node = maybe_node orelse return;
|
const node = maybe_node orelse return;
|
||||||
|
|
||||||
const handle = builder.handle;
|
const handle = builder.handle;
|
||||||
@ -995,14 +981,7 @@ fn writeNodeTokens(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn writeContainerField(
|
fn writeContainerField(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *DocumentStore, node: ast.Node.Index, field_token_type: ?TokenType, child_frame: anytype) !void {
|
||||||
builder: *Builder,
|
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
store: *DocumentStore,
|
|
||||||
node: ast.Node.Index,
|
|
||||||
field_token_type: ?TokenType,
|
|
||||||
child_frame: anytype,
|
|
||||||
) !void {
|
|
||||||
const tree = builder.handle.tree;
|
const tree = builder.handle.tree;
|
||||||
const container_field = SemanticToken.containerField(tree, node).?;
|
const container_field = SemanticToken.containerField(tree, node).?;
|
||||||
const base = tree.nodes.items(.main_token)[node];
|
const base = tree.nodes.items(.main_token)[node];
|
||||||
@ -1036,12 +1015,7 @@ fn writeContainerField(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO Range version, edit version.
|
// TODO Range version, edit version.
|
||||||
pub fn writeAllSemanticTokens(
|
pub fn writeAllSemanticTokens(arena: *std.heap.ArenaAllocator, store: *DocumentStore, handle: *DocumentStore.Handle, encoding: offsets.Encoding) ![]u32 {
|
||||||
arena: *std.heap.ArenaAllocator,
|
|
||||||
store: *DocumentStore,
|
|
||||||
handle: *DocumentStore.Handle,
|
|
||||||
encoding: offsets.Encoding,
|
|
||||||
) ![]u32 {
|
|
||||||
var builder = Builder.init(arena.child_allocator, handle, encoding);
|
var builder = Builder.init(arena.child_allocator, handle, encoding);
|
||||||
errdefer builder.arr.deinit();
|
errdefer builder.arr.deinit();
|
||||||
|
|
||||||
|
@ -94,11 +94,7 @@ pub const DiagnosticSeverity = enum(i64) {
|
|||||||
Information = 3,
|
Information = 3,
|
||||||
Hint = 4,
|
Hint = 4,
|
||||||
|
|
||||||
pub fn jsonStringify(
|
pub fn jsonStringify(value: DiagnosticSeverity, options: json.StringifyOptions, out_stream: anytype) !void {
|
||||||
value: DiagnosticSeverity,
|
|
||||||
options: json.StringifyOptions,
|
|
||||||
out_stream: anytype,
|
|
||||||
) !void {
|
|
||||||
try json.stringify(@enumToInt(value), options, out_stream);
|
try json.stringify(@enumToInt(value), options, out_stream);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -149,11 +145,7 @@ pub const TextDocument = struct {
|
|||||||
pub const WorkspaceEdit = struct {
|
pub const WorkspaceEdit = struct {
|
||||||
changes: ?std.StringHashMap([]TextEdit),
|
changes: ?std.StringHashMap([]TextEdit),
|
||||||
|
|
||||||
pub fn jsonStringify(
|
pub fn jsonStringify(self: WorkspaceEdit, options: std.json.StringifyOptions, writer: anytype) @TypeOf(writer).Error!void {
|
||||||
self: WorkspaceEdit,
|
|
||||||
options: std.json.StringifyOptions,
|
|
||||||
writer: anytype,
|
|
||||||
) @TypeOf(writer).Error!void {
|
|
||||||
try writer.writeByte('{');
|
try writer.writeByte('{');
|
||||||
if (self.changes) |changes| {
|
if (self.changes) |changes| {
|
||||||
try writer.writeAll("\"changes\": {");
|
try writer.writeAll("\"changes\": {");
|
||||||
@ -209,11 +201,7 @@ pub const InsertTextFormat = enum(i64) {
|
|||||||
PlainText = 1,
|
PlainText = 1,
|
||||||
Snippet = 2,
|
Snippet = 2,
|
||||||
|
|
||||||
pub fn jsonStringify(
|
pub fn jsonStringify(value: InsertTextFormat, options: json.StringifyOptions, out_stream: anytype) !void {
|
||||||
value: InsertTextFormat,
|
|
||||||
options: json.StringifyOptions,
|
|
||||||
out_stream: anytype,
|
|
||||||
) !void {
|
|
||||||
try json.stringify(@enumToInt(value), options, out_stream);
|
try json.stringify(@enumToInt(value), options, out_stream);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -246,11 +234,7 @@ pub const CompletionItem = struct {
|
|||||||
Operator = 24,
|
Operator = 24,
|
||||||
TypeParameter = 25,
|
TypeParameter = 25,
|
||||||
|
|
||||||
pub fn jsonStringify(
|
pub fn jsonStringify(value: Kind, options: json.StringifyOptions, out_stream: anytype) !void {
|
||||||
value: Kind,
|
|
||||||
options: json.StringifyOptions,
|
|
||||||
out_stream: anytype,
|
|
||||||
) !void {
|
|
||||||
try json.stringify(@enumToInt(value), options, out_stream);
|
try json.stringify(@enumToInt(value), options, out_stream);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -294,11 +278,7 @@ pub const DocumentSymbol = struct {
|
|||||||
Operator = 25,
|
Operator = 25,
|
||||||
TypeParameter = 26,
|
TypeParameter = 26,
|
||||||
|
|
||||||
pub fn jsonStringify(
|
pub fn jsonStringify(value: Kind, options: json.StringifyOptions, out_stream: anytype) !void {
|
||||||
value: Kind,
|
|
||||||
options: json.StringifyOptions,
|
|
||||||
out_stream: anytype,
|
|
||||||
) !void {
|
|
||||||
try json.stringify(@enumToInt(value), options, out_stream);
|
try json.stringify(@enumToInt(value), options, out_stream);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user