Skip to content

Commit 267f187

Browse files
committed
docs: explain build script detection
1 parent 9e81aa9 commit 267f187

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/DocumentStore.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,10 @@ fn getOrLoadBuildFile(
773773
// A filename alone is not sufficient because ordinary modules may be named `build.zig`.
774774
if (source_handle) |handle| std.debug.assert(handle.uri.eql(uri));
775775

776+
// Reuse a build file that was already classified and loaded.
776777
if (self.getBuildFile(uri)) |build_file| return build_file;
777778

779+
// Classify the current source before treating its `build.zig` filename as a build script.
778780
const handle = source_handle orelse (try self.getOrLoadHandle(uri) orelse return null);
779781
if (!isBuildScript(&handle.tree)) return null;
780782

@@ -1271,6 +1273,7 @@ pub fn isBuildScript(tree: *const Ast) bool {
12711273
return false;
12721274
}
12731275

1276+
// A module may be named `build.zig` without exposing the `zig build` entry point.
12741277
test isBuildScript {
12751278
var build_script = try Ast.parse(std.testing.allocator,
12761279
\\const std = @import("std");
@@ -1507,6 +1510,7 @@ fn collectPotentialBuildFiles(self: *DocumentStore, uri: Uri) error{ Canceled, O
15071510
const build_file_uri: Uri = try .fromPath(self.allocator, build_path);
15081511
defer build_file_uri.deinit(self.allocator);
15091512

1513+
// A module named `build.zig` cannot provide build configuration without the public entry point.
15101514
const build_file = try self.getOrLoadBuildFile(build_file_uri, null) orelse continue;
15111515
potential_build_files.appendAssumeCapacity(build_file);
15121516
}
@@ -1663,6 +1667,7 @@ fn createAndStoreDocument(
16631667
};
16641668
old_handle.deinit(store.allocator);
16651669

1670+
// Only activate build integration after the refreshed document is known to be a build script.
16661671
if (supports_build_system and options.lsp_synced and isBuildFile(uri) and !isInStd(uri) and isBuildScript(&handle_future.handle.tree)) {
16671672
switch (options.load_build_file_behaviour) {
16681673
.load_but_dont_update => {

src/Server.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,11 @@ const Workspace = struct {
833833
};
834834
defer args.server.allocator.free(workspace_path);
835835

836+
// Build-on-save is scoped to the workspace root, so check its candidate `build.zig`.
836837
const build_file_path = try std.Io.Dir.path.resolve(args.server.allocator, &.{ workspace_path, "build.zig" });
837838
defer args.server.allocator.free(build_file_path);
839+
840+
// DocumentStore works with URIs, so convert the path before reading and classifying it.
838841
const build_file_uri: Uri = try .fromPath(args.server.allocator, build_file_path);
839842
defer build_file_uri.deinit(args.server.allocator);
840843

0 commit comments

Comments
 (0)