@@ -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.
12741277test 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 = > {
0 commit comments