Repository navigation
Ignore @SpringBootApplication classes in test source folders - #421
Changyong Gong (chagong) merged 7 commits into
Conversation
`vscode.java.resolveMainClass` searches every source folder of a project, so a `@SpringBootApplication` class copied into `src/test/java` — a common pattern for integration tests — was offered as an additional launch candidate. Running an app then popped up a quick pick asking the user to choose between the real main class and one that is irrelevant to launch. Filter those out by matching each resolved main class against the test source folders of the project's classpath. The Spring Tools classpath listener already reports `isTest` for each source entry (set from `IClasspathEntry.isTest()`), so no extra language server round trip is needed; the flag was just missing from the `CPE` type declaration. The unfiltered list stays available via `getMainClasses()` so that live processes launched from a test main class are still associated with their app. When every main class sits in a test source folder, the filter falls back to the full list to keep such a project launchable. Closes microsoft#420
|
@microsoft-github-policy-service agree company="Broadcom" |
Changyong Gong (chagong)
left a comment
There was a problem hiding this comment.
The ordinary Maven/Gradle case is covered, but linked test source folders can still surface as launch candidates because the two path producers use logical and physical resource locations. I added concrete suggestions that preserve the current fast path and use JDT LS classification as a linked-resource-safe fallback. The remaining implementation looks focused; GitHub checks, local compile, lint, and patch hygiene passed.
|
Changyong Gong (@chagong) Thanks a lot for taking a look. I don't think I will be able to really judge or walkthrough your suggestions in details, so I would be more than happy if you could take over from here. Would that be an option? |
Changyong Gong (chagong)
left a comment
There was a problem hiding this comment.
Revisited against the reported src/main versus src/test scenario in #420. The branch is current, the implementation and regression test cover that case, and all platform checks pass; linked-resource handling is separate follow-up scope.
There was a problem hiding this comment.
🟢 Approval recommended
The behavioral change is narrowly scoped and backed by an integration test, with only minor type/doc consistency nits noted.
Pull request overview
This PR prevents @SpringBootApplication classes under test source folders (e.g. src/test/java) from being offered as launch candidates, avoiding an unnecessary QuickPick when running Spring Boot apps from the dashboard while still keeping the full resolved list available for process association.
Changes:
- Add
isTestto the JDTLS classpath entry type and use it to filter resolved main classes that live in test source folders. - Update the run/debug flow to use the filtered “launchable” main class list, with a fallback to the full list if everything is test-scoped.
- Add an extension test asserting that only the
src/main/javamain class is offered as launchable for the petclinic sample.
File summaries
| File | Description |
|---|---|
| test/suite/extension.test.ts | Adds coverage ensuring test-folder main classes are not offered as launch candidates. |
| src/utils.ts | Introduces the helper to exclude main classes located under test source folders. |
| src/types/jdtls.d.ts | Extends the classpath entry type with the isTest flag. |
| src/LocalAppController.ts | Switches run/debug to use getLaunchableMainClasses() to avoid irrelevant QuickPick entries. |
| src/BootApp.ts | Adds getLaunchableMainClasses() with filtering + fallback behavior. |
Review details
- Files reviewed: 4/5 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Changyong Gong (chagong)
left a comment
There was a problem hiding this comment.
Final head 94fae00 addresses the consistency follow-ups and matches Java Debug's optional filePath contract. Local compile, lint, CI-mode tests, and all platform checks pass; linked-resource handling remains separate follow-up scope.
There was a problem hiding this comment.
🟡 Changes recommended
The new isInFolder containment check has an edge-case bug (relative.startsWith("..")) that can misclassify valid child paths, and should be corrected before relying on it for launch-candidate filtering.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
src/utils.ts:82
isInFoldertreats any relative path starting with ".." as outside the folder; that incorrectly classifies paths like "..foo/bar" (a valid child directory name) as outside. The outside check should only match ".." or "../..." (platform-specific separator).
- Files reviewed: 4/5 changed files
- Comments generated: 1
- Review effort level: Lite
There was a problem hiding this comment.
🟡 Changes recommended
The documented fallback for projects containing only test main classes lacks coverage.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 4/5 changed files
- Comments generated: 1
- Review effort level: Balanced
|
Martin Lippert (@martinlippert) merged, thanks for the contribution. |
|
Thanks so much Changyong Gong (@chagong) and wenyt (@wenytang-ms) for taking care of this, very much appreciated. |
|
We are going to push out a new release of the Spring Tools early next week (around September 7-9), so would be fantastic if we could get a new release of the dashboard out as well that includes this fix. |
|
Thanks Martin Lippert (@martinlippert). The earliest we could release is September 9. Our pipeline is currently waiting on a newly published dependency to become available, and the exact timing is outside our control. We’ll monitor it, release as soon as possible, and let you know promptly once it’s available. |
|
Sounds good wenyt (@wenytang-ms) and thanks for keeping us in the loop. |
|
Hi Martin Lippert (@martinlippert) we shipped the prerelease of |

vscode.java.resolveMainClasssearches every source folder of a project, so a@SpringBootApplicationclass copied intosrc/test/java— a common pattern for integration tests — was offered as an additional launch candidate. Running an app then popped up a quick pick asking the user to choose between the real main class and one that is irrelevant to launch.Filter those out by matching each resolved main class against the test source folders of the project's classpath. The Spring Tools classpath listener already reports
isTestfor each source entry (set fromIClasspathEntry.isTest()), so ordinary source roots are handled locally. For an unmatched path, such as an Eclipse linked source whose classpath entry and resolved file use logical and physical identities, the dashboard asks JDT LSjava.project.isTestFileto classify the file. Classification failures retain the candidate so Run and Debug remain available.The unfiltered list stays available via
getMainClasses()so that live processes launched from a test main class are still associated with their app. When every main class sits in a test source folder, the filter falls back to the full list to keep such a project launchable.Closes #420