Skip to content

Commit

Permalink
Libraryify
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperAuguste committed Mar 3, 2023
1 parent c6eab4b commit 36c1bad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
7 changes: 2 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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(.{});

Expand Down Expand Up @@ -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");
}
18 changes: 16 additions & 2 deletions src/DocumentStore.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand All @@ -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());
Expand Down

0 comments on commit 36c1bad

Please sign in to comment.