Skip to content

Commit

Permalink
Fix failed to find root path when workspace changes (#1689)
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo authored Mar 16, 2021
1 parent bb30215 commit d72b545
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ public void preferencesChange(Preferences oldPreferences, Preferences newPrefere

try {
IFolder workspaceLinkFolder = javaProject.getProject().getFolder(ProjectUtils.WORKSPACE_LINK);
if (!workspaceLinkFolder.exists()) {
IPath rootPath = ProjectUtils.findBelongedWorkspaceRoot(workspaceLinkFolder.getLocation());
if (rootPath == null) {
continue;
}
List<IPath> sourcePaths = InvisibleProjectImporter.getSourcePaths(newPreferences.getInvisibleProjectSourcePaths(), workspaceLinkFolder);
List<IPath> excludingPaths = InvisibleProjectImporter.getExcludingPath(javaProject, null, workspaceLinkFolder);
List<IPath> excludingPaths = InvisibleProjectImporter.getExcludingPath(javaProject, rootPath, workspaceLinkFolder);
IPath outputPath = InvisibleProjectImporter.getOutputPath(javaProject, newPreferences.getInvisibleProjectOutputPath(), true /*isUpdate*/);
IClasspathEntry[] classpathEntries = InvisibleProjectImporter.resolveClassPathEntries(javaProject, sourcePaths, excludingPaths, outputPath);
javaProject.setRawClasspath(classpathEntries, outputPath, new NullProgressMonitor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
Expand Down Expand Up @@ -117,4 +118,25 @@ public void testUpdateSourcePaths() throws Exception {
assertTrue(sourcePaths.contains("src"));
assertTrue(sourcePaths.contains("src2"));
}
}

@Test
public void testWhenRootPathChanged() throws Exception {
JavaLanguageClient client = mock(JavaLanguageClient.class);
ProjectsManager pm = JavaLanguageServerPlugin.getProjectsManager();
pm.setConnection(client);
doNothing().when(client).showMessage(any(MessageParams.class));
copyAndImportFolder("singlefile/simple", "src/App.java");

List<IPath> rootPaths = new ArrayList<>(preferenceManager.getPreferences().getRootPaths());
rootPaths.remove(0);
preferenceManager.getPreferences().setRootPaths(rootPaths);

Preferences newPreferences = new Preferences();
initPreferences(newPreferences);
newPreferences.setInvisibleProjectSourcePaths(Arrays.asList("src", "src2"));
InvisibleProjectPreferenceChangeListener listener = new InvisibleProjectPreferenceChangeListener();
listener.preferencesChange(preferenceManager.getPreferences(), newPreferences);

verify(client, times(0)).showMessage(any(MessageParams.class));
}
}

0 comments on commit d72b545

Please sign in to comment.