Skip to content

fix(workspace): honor project(":name").projectDir relocation in settings.gradle - #327

Merged
Hessesian merged 2 commits into
mainfrom
worktree-issue-326-nested-subprojects
Sep 29, 2026
Merged

Hessesian merged 2 commits into
mainfrom
worktree-issue-326-nested-subprojects

Conversation

@Hessesian

Copy link
Copy Markdown
Owner

Summary

Fixes #326. A project that groups its modules under a parent directory in settings.gradle.kts via project(":name").projectDir = file("modules/name") had that module's source roots silently lost: settings_subprojects derived every module's directory purely from the include(...) string, never reading a projectDir relocation. detect_build_layout_source_paths then probed a directory that doesn't exist, read_dir failed, and the module's src/*/kotlin roots never got discovered — explaining the reporter's exact symptom (highlighting fine, navigation/find-references mostly broken, since highlighting is per-file and source-root-independent while cross-file resolution depends on correct source-root scoping).

  • New parse_project_dir_overrides parses project(":name").projectDir = ... lines (Kotlin DSL file(...), Groovy new File(...), or a bare string — all just one quoted name + one quoted path per line), robust to same-line comments/interpolation (degrades to a harmless no-crash mismap, never a panic).
  • settings_subprojects now maps each include-derived directory through the override when one exists; both existing callers (detect_build_layout_source_paths, detect_android_r_class_jars) get the fix for free, untouched.
  • Zero behavior change for a project with no projectDir overrides (confirmed: empty override map → unwrap_or(dir) is a no-op for every entry).

Test plan

  • settings_gradle_relocated_module_dir_is_discovered — end-to-end, reproduces the reporter's exact settings.gradle.kts shape; confirmed genuinely RED without the fix (temporarily reverted, reran, real panic; restored)
  • Unit tests for parse_project_dir_overrides: Kotlin DSL, Groovy new File(...), bare string, two negative/decoy cases (a project(...) reference with no .projectDir at all; a project(...).projectDir-shaped line that configures something else)
  • settings_subprojects_passes_through_a_non_relocated_module_unchanged — mixed relocated + non-relocated project, exercises the real unwrap_or(dir) fallback end-to-end
  • cargo test (2020 passed), cargo clippy --all-targets -- -D warnings (clean), cargo fmt (clean)
  • Reviewed (traced token-matching heuristic against contrived self-reference/comment/interpolation shapes, confirmed key-construction parity with parse_include_calls for nested modules, confirmed cross-platform path-join correctness for the Windows separator case) — two test-coverage gaps found and fixed before this push

🤖 Generated with Claude Code

https://claude.ai/code/session_01L7ZonwYUh94VsuQphiHykF

Hessesian and others added 2 commits September 29, 2026 16:39
…ngs.gradle

Module directory discovery derived every subproject's path purely from
its include(":name") string, ignoring a subsequent
project(":name").projectDir = file("...") relocation. A project that
groups its modules under a parent directory (include(":kmp-module-one")
building from modules/kmp-module-one/, not ./kmp-module-one/) had that
module's source roots silently lost — detect_build_layout_source_paths
probed a directory that doesn't exist, read_dir failed, and the module's
src/*/kotlin dirs never became source roots. Highlighting still worked
(per-file, source-root-independent); navigation and find-references,
which depend on correct source-root scoping, mostly didn't.

Fixes #326.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L7ZonwYUh94VsuQphiHykF
Review found two gaps: no test covered a project(...) line that starts
correctly but configures something other than projectDir (only the
!starts_with("project(") disjunct was exercised); the non-relocated-module
test only checked isolated parse_project_dir_overrides output rather than
settings_subprojects' real unwrap_or(dir) fallback path end-to-end.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L7ZonwYUh94VsuQphiHykF
@Hessesian
Hessesian merged commit 1764a14 into main Sep 29, 2026
4 checks passed
@Hessesian
Hessesian deleted the worktree-issue-326-nested-subprojects branch September 29, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify support for nested subprojects

1 participant