summaryrefslogtreecommitdiff
path: root/src/lsp/Scip.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/lsp/Scip.zig')
-rw-r--r--src/lsp/Scip.zig21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/lsp/Scip.zig b/src/lsp/Scip.zig
index 3d3cc648..540ba5cd 100644
--- a/src/lsp/Scip.zig
+++ b/src/lsp/Scip.zig
@@ -16,12 +16,10 @@
const std = @import("std");
const statPath = @import("../fs.zig").statPath;
-/// One loaded index's caps, measured on a real one: rust-analyzer 1.97's
-/// index of clap_builder 4.6.7 (29 kloc) is 3.9 MB, with 55 documents,
-/// 32,795 occurrences and 6,661 symbols, and its tables take 3.1 MB; these
-/// hold eight times that. A bigger index is refused, in words.
-pub const max_bytes = 32 << 20;
-const tables_bytes = 32 << 20;
+/// Agave's workspace index is 104 MiB; leave room for it and its lookup tables.
+/// A bigger index is refused, in words.
+pub const max_bytes = 512 << 20;
+const tables_bytes = 512 << 20;
/// Indexes kept loaded at once, the one asked least recently replaced.
const kept = 2;
@@ -202,11 +200,12 @@ fn rangeOf(bytes: []const u8, typed: enum { packed_ints, single, multi }) error{
// ------------------------------------------------------------------ loading
-var regions: [kept][max_bytes + tables_bytes]u8 align(std.heap.page_size_max) = @splat(@splat(0));
+// Keep the large bounded regions out of the executable's static address range.
+var regions: [kept]?[]u8 = @splat(null);
var slots: [kept]Index = @splat(.{});
var clock: u64 = 0;
-pub const Error = error{ TooBig, Malformed, Unreadable };
+pub const Error = error{ TooBig, Malformed, Unreadable, OutOfMemory };
/// The index for a file in `dir`: the nearest `index.scip` there or up to
/// seven directories above, read again when it changed since; null with
@@ -237,7 +236,11 @@ fn use(io: std.Io, p: []const u8, st: std.Io.File.Stat) Error!*Index {
ix.* = .{ .mtime = st.mtime.nanoseconds, .size = st.size, .used = clock, .path_len = p.len };
@memcpy(ix.path_buf[0..p.len], p);
errdefer ix.* = .{};
- const region = &regions[pick];
+ const region = regions[pick] orelse blk: {
+ const memory = try std.heap.page_allocator.alloc(u8, max_bytes + tables_bytes);
+ regions[pick] = memory;
+ break :blk memory;
+ };
const file = std.Io.Dir.cwd().openFile(io, p, .{}) catch return error.Unreadable;
defer file.close(io);
const got = file.readPositionalAll(io, region[0..@intCast(st.size)], 0) catch return error.Unreadable;