Resolve linked source folders when building the classpath - #1984
Open
sorteam wants to merge 1 commit into
Open
Conversation
ClasspathUtil turned a classpath entry into a filesystem location by appending the entry path to the project location. That is wrong whenever the source folder is a linked resource: the directory it computes does not exist, SpringIndexerJava.getFiles() walks nothing, and the project contributes no symbols at all - no beans, no request mappings, not even handwritten ones. Projects shaped that way are not exotic. The invisible project the Java language server creates for a plain folder links the workspace folder in, and project importers contributed by other extensions keep the project metadata outside the repository and link every source root. Ask the resource model first and fall back to the previous arithmetic for paths it does not know about. Signed-off-by: Artem <sorteam@users.noreply.github.com>
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.
ClasspathUtil.resolveWorkspacePathturns a classpath entry into a filesystem location byappending the entry path to the project location:
That is correct only while a source folder is a real directory inside the project. When the source
folder is a linked resource, the computed directory does not exist,
createSourceCPEhands thatpath to the client anyway, and
SpringIndexerJava.getFiles()-Files.walkoverIClasspathUtil.getProjectJavaSourceFolders(...)- walks nothing. The project then contributes nosymbols at all: no beans, no request mappings, not even handwritten ones.
Reproduction
A project whose
.projectdeclaresand whose
.classpathhas<classpathentry kind="src" path="main"/>, with nomaindirectory inthe project folder. The CPE that reaches the language server is
<project location>/main, which doesnot exist.
Projects shaped like this are not exotic:
folder in under
ProjectUtils.WORKSPACE_LINK;server's storage and link each source root - which is how I ran into this.
Measured on such a workspace of 116 generated projects: 228 of 244 source classpath entries pointed
at directories that do not exist, and the Spring index was empty for every project.
Fix
Ask the resource model first, and keep the existing arithmetic as a fallback for paths it does not
know about. Eight lines, no behaviour change for projects whose source folders are real directories.
Verification
I compiled the modified class against the jars shipped in
vmware.vscode-spring-boot2.3.0 togetherwith the jdt.ls plugins from
redhat.java, and confirmed the emitted bytecode callsfindMemberbefore the fallback. I have not run the project's own build or test suite (Tycho/target
platform), so please treat the change as needing your CI.