Skip to content

Ignore @SpringBootApplication classes in test source folders - #421

Merged
Changyong Gong (chagong) merged 7 commits into
microsoft:mainfrom
martinlippert:gh-420-ignore-test-main-classes
Sep 4, 2026
Merged

Changyong Gong (chagong) merged 7 commits into
microsoft:mainfrom
martinlippert:gh-420-ignore-test-main-classes

Conversation

@martinlippert

@martinlippert Martin Lippert (martinlippert) commented Aug 24, 2026 •

Copy link
Copy Markdown
Collaborator

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 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 LS java.project.isTestFile to 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

`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
@martinlippert

Copy link
Copy Markdown
Collaborator Author

@microsoft-github-policy-service agree company="Broadcom"

@chagong Changyong Gong (chagong) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/utils.ts Resolved
Comment thread src/BootApp.ts Resolved
@martinlippert

Copy link
Copy Markdown
Collaborator Author

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?

@chagong Changyong Gong (chagong) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 isTest to 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/java main 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.

Comment thread src/utils.ts Resolved
Comment thread src/utils.ts Resolved

@chagong Changyong Gong (chagong) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

  • isInFolder treats 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

Comment thread test/suite/extension.test.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread src/BootApp.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation matches the reported behavior, handles relevant edge cases, and passes all platform checks.

Review details
  • Files reviewed: 4/5 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation matches the stated behavior and includes appropriate boundary and integration coverage.

Review details
  • Files reviewed: 4/5 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Comment thread src/utils.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation matches the reported behavior and handles linked sources, failures, and test-only projects.

Review details
  • Files reviewed: 4/5 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@chagong
Changyong Gong (chagong) merged commit dad2838 into microsoft:main Sep 4, 2026
4 checks passed
@chagong

Copy link
Copy Markdown
Contributor

Martin Lippert (@martinlippert) merged, thanks for the contribution.

@martinlippert

Copy link
Copy Markdown
Collaborator Author

Thanks so much Changyong Gong (@chagong) and wenyt (@wenytang-ms) for taking care of this, very much appreciated.

@martinlippert

Copy link
Copy Markdown
Collaborator Author

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.

@wenytang-ms

wenyt (wenytang-ms) commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

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.

@martinlippert

Martin Lippert (martinlippert) commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

Sounds good wenyt (@wenytang-ms) and thanks for keeping us in the loop.

@wenytang-ms

wenyt (wenytang-ms) commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Hi Martin Lippert (@martinlippert) we shipped the prerelease of 0.14.2026091000 to this extension, please verify.
image

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.

Wrong multiple choices of SpringBootApplication

4 participants