diff --git a/build.zig b/build.zig index fd3fb6962c..e1fa41cd8d 100644 --- a/build.zig +++ b/build.zig @@ -13,11 +13,6 @@ pub fn build(b: *std.build.Builder) !void { } } - b.addModule(.{ - .name = "zls", - .source_file = .{ .path = "src/zls.zig" }, - }); - const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); @@ -187,4 +182,6 @@ pub fn build(b: *std.build.Builder) !void { }); src_tests.setFilter(test_filter); test_step.dependOn(&src_tests.step); + + b.modules.put(b.dupe("zls"), zls_module) catch @panic("OOM"); } diff --git a/src/DocumentStore.zig b/src/DocumentStore.zig index 9e3a86be2b..5c103f1f63 100644 --- a/src/DocumentStore.zig +++ b/src/DocumentStore.zig @@ -647,7 +647,7 @@ fn uriInImports( } /// takes ownership of the text passed in. -fn createDocument(self: *DocumentStore, uri: Uri, text: [:0]u8, open: bool) error{OutOfMemory}!Handle { +pub fn createDocument(self: *DocumentStore, uri: Uri, text: [:0]u8, open: bool) error{OutOfMemory}!Handle { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -750,7 +750,7 @@ fn createDocument(self: *DocumentStore, uri: Uri, text: [:0]u8, open: bool) erro return handle; } -fn createDocumentFromURI(self: *DocumentStore, uri: Uri, open: bool) error{OutOfMemory}!?Handle { +pub fn createDocumentFromURI(self: *DocumentStore, uri: Uri, open: bool) error{OutOfMemory}!?Handle { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -765,6 +765,20 @@ fn createDocumentFromURI(self: *DocumentStore, uri: Uri, open: bool) error{OutOf return try self.createDocument(uri, file_contents, open); } +pub fn createDocumentFromPath(self: *DocumentStore, file_path: []const u8, open: bool) error{OutOfMemory}!?Handle { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + + const uri = URI.fromPath(self.allocator, file_path) catch return null; + + var file = std.fs.openFileAbsolute(file_path, .{}) catch return null; + defer file.close(); + + const file_contents = file.readToEndAllocOptions(self.allocator, std.math.maxInt(usize), null, @alignOf(u8), 0) catch return null; + + return try self.createDocument(uri, file_contents, open); +} + /// Caller owns returned memory. fn collectImportUris(self: *const DocumentStore, handle: Handle) error{OutOfMemory}!std.ArrayListUnmanaged(Uri) { const tracy_zone = tracy.trace(@src());