Skip to content

Find main classes in projects whose sources are linked in - #633

Open
Artem (sorteam) wants to merge 1 commit into
microsoft:mainfrom
sorteam:main-class-search-linked-sources
Open

Find main classes in projects whose sources are linked in#633
Artem (sorteam) wants to merge 1 commit into
microsoft:mainfrom
sorteam:main-class-search-linked-sources

Conversation

@sorteam

Copy link
Copy Markdown

ResolveMainClassHandler.resolveMainClassUnderPaths builds the search scope by keeping only the
projects whose own location is inside the requested folder:

projects = Stream.of(ProjectUtils.getAllProjects())
    .filter(p -> ProjectUtils.isJavaProject(p) && p.getLocation() != null
                 && ResourceUtils.isContainedIn(p.getLocation(), parentPaths))

A project can instead keep its description outside that folder and reach the sources through linked
folders. Such a project is dropped before the search runs, so the folder looks as if it contained no
main class: Run and Debug generates no Java configuration for it (the launch configuration
provider calls vscode.java.resolveMainClass(folder.uri)), and anything else that resolves a main
class by folder gets an empty answer.

The code already knows about this shape. acceptSearchMatch makes an exception for the invisible
project:

if (parentPaths.isEmpty()
    || ResourceUtils.isContainedIn(project.getLocation(), parentPaths)
    || isContainedInInvisibleProject(project, parentPaths)) {

but the scope filter it depends on has no such exception, so the invisible-project branch can never
fire - the project is not in the scope to begin with.

Fix

Check the locations of the project's source folders as well, in both places: for each source entry of
the raw classpath, resolve the workspace path through IWorkspaceRoot.findMember and compare that
location against the requested folders. A project belongs to the folder its sources are in rather
than to the folder its description happens to live in.

Reproduction

Create a java project whose source folders are linked resources pointing into a workspace folder,
with the project's own location elsewhere (any importer that provisions projects outside the
repository does this; the invisible project is a one-link special case of it). Open the workspace
folder and note that Run and Debug offers no Java configuration, while the same sources in a
regular project do.

Verification

I compiled the modified class against the plugin jar shipped in vscjava.vscode-java-debug 0.59.0
and the jdt.ls plugins from redhat.java. I have not run the project's Maven build or test
suite.

resolveMainClassUnderPaths keeps a project only when its own location is
inside the requested folder. A project can instead keep its description
outside the folder and reach the sources through linked folders, and
then it is dropped before the search runs: the folder appears to contain
no main class, so the Run and Debug view generates no configuration and
the Spring Boot Dashboard cannot resolve an application's main class.

The accept-match branch already makes an exception for the invisible
project, which is one instance of this shape (a single link named after
ProjectUtils.WORKSPACE_LINK); the scope filter it depends on does not,
so that exception can never fire. Check the locations of the project's
source folders in both places instead.
@sorteam

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

1 participant