Skip to content
Merged
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
706 changes: 403 additions & 303 deletions src/DocumentStore.zig

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,9 @@ pub fn resolveConfiguration(server: *Server) error{ Canceled, OutOfMemory }!void
(new_zig_exe_path or new_zig_lib_path) and
server.client_capabilities.supports_publish_diagnostics)
{
for (server.document_store.handles.values()) |handle| {
if (!handle.isLspSynced()) continue;
var it: DocumentStore.HandleIterator = .{ .store = &server.document_store };
while (it.next()) |handle| {
if (!handle.lsp_synced) continue;
server.generateDiagnostics(handle);
}
}
Expand Down Expand Up @@ -1719,7 +1720,7 @@ pub fn setTransport(server: *Server, transport: *lsp.Transport) void {
server.document_store.transport = transport;
}

pub fn keepRunning(server: Server) bool {
pub fn keepRunning(server: *const Server) bool {
switch (server.status) {
.exiting_success, .exiting_failure => return false,
else => return true,
Expand Down
7 changes: 7 additions & 0 deletions src/Uri.zig
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@ test "fromPath - windows like path on posix" {
try std.testing.expectEqualStrings(reparsed_uri.raw, uri.raw);
}

pub fn isFileScheme(uri: Uri) bool {
const scheme = for (uri.raw, 0..) |byte, i| {
if (!isSchemeChar(byte)) break uri.raw[0..i];
} else unreachable; // The Uri is guranteed to be valid
return std.mem.eql(u8, scheme, "file");
}

/// Converts a Uri to a file system path.
/// Caller owns the returned memory
pub fn toFsPath(
Expand Down
16 changes: 8 additions & 8 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4515,7 +4515,7 @@ pub const ScopeWithHandle = struct {

pub fn toNode(scope_handle: ScopeWithHandle) Ast.Node.Index {
if (scope_handle.scope == Scope.Index.root) return .root;
var doc_scope = scope_handle.handle.getDocumentScopeCached();
var doc_scope = scope_handle.handle.document_scope.getCached();
return doc_scope.getScopeAstNode(scope_handle.scope).?;
}

Expand Down Expand Up @@ -5806,7 +5806,7 @@ pub fn collectAllSymbolsAtSourceIndex(
std.debug.assert(source_index <= handle.tree.source.len);

const document_scope = try handle.getDocumentScope();
var scope_iterator = iterateEnclosingScopes(&document_scope, source_index);
var scope_iterator = iterateEnclosingScopes(document_scope, source_index);
while (scope_iterator.next().unwrap()) |scope_index| {
const scope_decls = document_scope.getScopeDeclarationsConst(scope_index);
for (scope_decls) |decl_index| {
Expand Down Expand Up @@ -5862,7 +5862,7 @@ fn iterateEnclosingScopes(document_scope: *const DocumentScope, source_index: us

pub fn iterateLabels(handle: *DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype) error{OutOfMemory}!void {
const document_scope = try handle.getDocumentScope();
var scope_iterator = iterateEnclosingScopes(&document_scope, source_index);
var scope_iterator = iterateEnclosingScopes(document_scope, source_index);
while (scope_iterator.next().unwrap()) |scope_index| {
for (document_scope.getScopeDeclarationsConst(scope_index)) |decl_index| {
const decl = document_scope.declarations.get(@intFromEnum(decl_index));
Expand All @@ -5873,18 +5873,18 @@ pub fn iterateLabels(handle: *DocumentStore.Handle, source_index: usize, comptim
}

pub fn innermostScopeAtIndex(
document_scope: DocumentScope,
document_scope: *const DocumentScope,
source_index: usize,
) Scope.Index {
return innermostScopeAtIndexWithTag(document_scope, source_index, .initFull()).unwrap().?;
}

pub fn innermostScopeAtIndexWithTag(
document_scope: DocumentScope,
document_scope: *const DocumentScope,
source_index: usize,
tag_filter: std.EnumSet(Scope.Tag),
) Scope.OptionalIndex {
var scope_iterator = iterateEnclosingScopes(&document_scope, source_index);
var scope_iterator = iterateEnclosingScopes(document_scope, source_index);
var scope_index: Scope.OptionalIndex = .none;
while (scope_iterator.next().unwrap()) |inner_scope| {
const scope_tag = document_scope.getScopeTag(inner_scope);
Expand All @@ -5907,7 +5907,7 @@ pub fn innermostContainer(analyser: *Analyser, handle: *DocumentStore.Handle, so

var current: DocumentScope.Scope.Index = .root;
var meta_params: TokenToTypeMap = .empty;
var scope_iterator = iterateEnclosingScopes(&document_scope, source_index);
var scope_iterator = iterateEnclosingScopes(document_scope, source_index);
while (scope_iterator.next().unwrap()) |scope_index| {
switch (document_scope.getScopeTag(scope_index)) {
.container => {
Expand Down Expand Up @@ -5954,7 +5954,7 @@ pub fn lookupLabel(
source_index: usize,
) error{OutOfMemory}!?DeclWithHandle {
const document_scope = try handle.getDocumentScope();
var scope_iterator = iterateEnclosingScopes(&document_scope, source_index);
var scope_iterator = iterateEnclosingScopes(document_scope, source_index);
while (scope_iterator.next().unwrap()) |scope_index| {
const decl_index = document_scope.getScopeDeclaration(.{
.scope = scope_index,
Expand Down
2 changes: 1 addition & 1 deletion src/features/completions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ fn globalSetCompletions(builder: *Builder, kind: enum { error_set, enum_set }) A
for (dependencies.items) |uri| {
// not every dependency is loaded which results in incomplete completion
const dependency_handle = store.getHandle(uri) orelse continue;
const document_scope: DocumentScope = try dependency_handle.getDocumentScope();
const document_scope = try dependency_handle.getDocumentScope();
const curr_set: DocumentScope.IdentifierSet = switch (kind) {
.error_set => @field(document_scope, "global_error_set"),
.enum_set => @field(document_scope, "global_enum_set"),
Expand Down
3 changes: 2 additions & 1 deletion src/features/references.zig
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ fn gatherReferences(
dependencies.deinit(allocator);
}

for (analyser.store.handles.values()) |handle| {
var it: DocumentStore.HandleIterator = .{ .store = analyser.store };
while (it.next()) |handle| {
if (skip_std_references and DocumentStore.isInStd(handle.uri)) {
if (!include_decl or !handle.uri.eql(curr_handle.uri))
continue;
Expand Down
1 change: 1 addition & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
pub fn main(init: std.process.Init.Minimal) !u8 {
const base_allocator, const is_debug = gpa: {
if (exe_options.debug_gpa) break :gpa .{ debug_allocator.allocator(), true };
if (zig_builtin.link_libc) break :gpa .{ std.heap.c_allocator, false };
if (zig_builtin.target.os.tag == .wasi) break :gpa .{ std.heap.wasm_allocator, false };
break :gpa switch (zig_builtin.mode) {
.Debug => .{ debug_allocator.allocator(), true },
Expand Down
2 changes: 1 addition & 1 deletion tests/analysis_check.zig
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub fn main(init: std.process.Init) Error!void {

const handle_uri: zls.Uri = try .fromPath(arena, file_path);
try document_store.openLspSyncedDocument(handle_uri, source);
const handle: *zls.DocumentStore.Handle = document_store.handles.get(handle_uri).?;
const handle: *zls.DocumentStore.Handle = document_store.getHandle(handle_uri).?;

var error_builder: ErrorBuilder = .init(gpa);
defer error_builder.deinit();
Expand Down