so... jai :D

This commit is contained in:
agra
2026-02-04 01:34:30 +02:00
commit 55fc5790e4
60 changed files with 15876 additions and 0 deletions

48
src/lsp/document.zig Normal file
View File

@@ -0,0 +1,48 @@
const std = @import("std");
pub const DocumentStore = struct {
documents: std.StringHashMap(Document),
allocator: std.mem.Allocator,
pub const Document = struct {
uri: []const u8,
text: []const u8,
version: i64,
};
pub fn init(allocator: std.mem.Allocator) DocumentStore {
return .{
.documents = std.StringHashMap(Document).init(allocator),
.allocator = allocator,
};
}
pub fn open(self: *DocumentStore, uri: []const u8, text: []const u8, version: i64) !void {
const uri_copy = try self.allocator.dupe(u8, uri);
const text_copy = try self.allocator.dupe(u8, text);
try self.documents.put(uri_copy, .{
.uri = uri_copy,
.text = text_copy,
.version = version,
});
}
pub fn update(self: *DocumentStore, uri: []const u8, text: []const u8, version: i64) !void {
if (self.documents.getPtr(uri)) |doc| {
self.allocator.free(doc.text);
doc.text = try self.allocator.dupe(u8, text);
doc.version = version;
}
}
pub fn close(self: *DocumentStore, uri: []const u8) void {
if (self.documents.fetchRemove(uri)) |kv| {
self.allocator.free(kv.value.text);
self.allocator.free(kv.key);
}
}
pub fn get(self: *const DocumentStore, uri: []const u8) ?*const Document {
return self.documents.getPtr(uri);
}
};