-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Package name not recognized when opening standalone java files #1766
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,9 @@ | |
|
||
package org.eclipse.jdt.ls.core.internal.managers; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.core.resources.IFolder; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IPath; | ||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
import org.eclipse.jdt.core.IClasspathEntry; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; | ||
import org.eclipse.jdt.ls.core.internal.ProjectUtils; | ||
|
@@ -37,29 +31,13 @@ public void preferencesChange(Preferences oldPreferences, Preferences newPrefere | |
if (!Objects.equals(oldPreferences.getInvisibleProjectOutputPath(), newPreferences.getInvisibleProjectOutputPath()) || | ||
!Objects.equals(oldPreferences.getInvisibleProjectSourcePaths(), newPreferences.getInvisibleProjectSourcePaths())) { | ||
for (IJavaProject javaProject : ProjectUtils.getJavaProjects()) { | ||
IProject project = javaProject.getProject(); | ||
if (ProjectUtils.isVisibleProject(project)) { | ||
continue; | ||
} | ||
if (project.equals(ProjectsManager.getDefaultProject())) { | ||
continue; | ||
} | ||
|
||
try { | ||
IFolder workspaceLinkFolder = javaProject.getProject().getFolder(ProjectUtils.WORKSPACE_LINK); | ||
IPath rootPath = ProjectUtils.findBelongedWorkspaceRoot(workspaceLinkFolder.getLocation()); | ||
if (rootPath == null) { | ||
continue; | ||
} | ||
List<IPath> sourcePaths = InvisibleProjectImporter.getSourcePaths(newPreferences.getInvisibleProjectSourcePaths(), 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()); | ||
InvisibleProjectImporter.updateSourcePaths(javaProject); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will always use the trigger files to update source paths, regardless of the sourcePaths preference. It's a breaking change. Only if sourcePaths preference is explicitly changed, then need to update source paths. Otherwise, just update project output path directly via javaProject.setOutputLocation. See @jdneo's PR https://github.com/eclipse/eclipse.jdt.ls/pull/1767/files |
||
} catch (CoreException e) { | ||
JavaLanguageServerPlugin.getProjectsManager().getConnection().showMessage(new MessageParams(MessageType.Error, e.getMessage())); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.io.Writer; | ||
import java.util.Collection; | ||
import java.util.Hashtable; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
|
@@ -25,6 +26,7 @@ | |
import org.apache.commons.lang3.StringUtils; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IPath; | ||
import org.eclipse.core.runtime.ISafeRunnable; | ||
import org.eclipse.core.runtime.ListenerList; | ||
import org.eclipse.core.runtime.SafeRunner; | ||
|
@@ -68,6 +70,7 @@ public class PreferenceManager { | |
private ListenerList<IPreferencesChangeListener> preferencesChangeListeners; | ||
private IEclipsePreferences eclipsePrefs; | ||
private static Map<String, Template> templates = new LinkedHashMap<>(); | ||
private static Collection<IPath> triggerFiles; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not persist the trigger files. They should be used only once. And only use them to calculate a default source path when initializing a new invisible project. If the user modifies the source paths in a subsequent action, such as changing the workspace setting This means that if the user sets sourcePaths to null, we should just clean up all the source paths. There is no need to fall back and use trigger files to calculate the source paths again. Since the user knows the settings to change the source paths, he/she can change them back if he/she wants. |
||
|
||
public PreferenceManager() { | ||
preferences = new Preferences(); | ||
|
@@ -315,4 +318,12 @@ public boolean isClientSupportsCompletionDocumentationMarkDown() { | |
return getClientPreferences() != null && getClientPreferences().isSupportsCompletionDocumentationMarkdown(); | ||
} | ||
|
||
public static Collection<IPath> getTriggerFiles() { | ||
return triggerFiles; | ||
} | ||
|
||
public static void setTriggerFiles(Collection<IPath> triggerPaths) { | ||
triggerFiles = triggerPaths; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package mypackage; | ||
|
||
public class Bar { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package mypackage; | ||
|
||
public class Foo extends Bar { | ||
|
||
public static void main(String[] args) { | ||
System.err.println("Foo"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this support the usage of triggerFiles or is this some separate issue discovered ? I think we should avoid having requests from the client waiting on each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes VS Code calls BuildWorkspaceHandler.buildWorkspace(boolean, IProgressMonitor) before initializing a workspace.
@rgrunber you have try the following:
https://github.com/snjeza/vscode-test/raw/master/java-0.79.3.vsix includes this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rgrunber @jdneo See redhat-developer/vscode-java#1941 (comment)