fix(intellij): resolve workspace paths for multi-project windows#12919
Open
houssemzaier wants to merge 1 commit into
Open
fix(intellij): resolve workspace paths for multi-project windows#12919houssemzaier wants to merge 1 commit into
houssemzaier wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
1 issue found across 6 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
When an IntelliJ window holds several modules or attached projects and two sibling roots share a textual prefix (e.g. .../service and .../service-api), the naive String.startsWith() containment check treated one as nested in the other and dropped it from workspacePaths — so @-references, file lists, listDir and indexing were broken for that project. Containment is now computed on URI path segments (WorkspacePaths.isNestedUnder), so prefix-sharing siblings are kept as separate top-level roots. All workspace-path writers (startup + the modulesAdded / moduleRemoved / modulesRenamed listeners) and both consumers (IntelliJIDE and GitService workspaceDirectories()) route through a single resolveWorkspacePaths / resolveWorkspacePathsOrGuess helper, so the discovered roots can never drift between callers. Adds unit tests for the segment-aware de-nesting and the module-scan glue.
3ef276f to
04f23f2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When an IntelliJ window has more than one project/module open, files from one of them can silently disappear from Continue:
@-file references, the file picker,listDir, and indexing all behave as if that project isn't there.It happens when two project folders share the start of their name (e.g.
serviceandservice-api). The code decided whether one folder sat inside another with a plainstartsWithtext check, soservice-apilooked like it was insideserviceand got dropped from the workspace.This PR compares path segments instead of raw text, so
service-apiis kept as its own top-level project. It also routes every place that computes workspace paths (startup + the add / remove / rename module listeners) and both readers (IntelliJIDEandGitServiceworkspaceDirectories()) through one shared helper (resolveWorkspacePaths/resolveWorkspacePathsOrGuess), so they can't disagree.moduleRemovednow re-derives the top-level roots from the remaining modules, so removing a parent promotes a previously-nested child instead of leaving a stale list.We've been running this fix in our downstream fork (3,000+ users) and it's been stable in production.
This is the workspace discovery side of the problem in #10644. #12090 takes the related path-resolution angle (preferring the active workspace for an ambiguous relative path) — the two are complementary.
Tests
WorkspacePathsTest— pure unit tests for the segment-aware de-nesting: prefix-sharing siblings, real nesting, dedup, Windows drive paths, trailing slashes.ResolveWorkspacePathsTest— the module-scan glue (ModuleManager → content roots → de-nesting), OS-independent via mockk.serviceandservice-api,@-reference a file underservice-api→ now resolves correctly.Checklist
Summary by cubic
Fixes workspace discovery in multi-project IntelliJ windows by comparing URI path segments instead of string prefixes, so sibling projects like service and service-api no longer disappear. All writers/readers now use a shared resolver with a safe read-action scan and consistent fallback, keeping
IntelliJIDEandGitServicein sync.Bug Fixes
moduleRemovedrescans to promote previously nested children.Refactors
WorkspacePaths(topLevelWorkspacePaths,isNestedUnder) and shared helpersresolveWorkspacePaths/resolveWorkspacePathsOrGuess(stored paths → module scan →guessProjectDir).ModuleListenerwriters, and readers inIntelliJIDEandGitService, through these helpers.Written for commit 04f23f2. Summary will update on new commits.