Skip to content
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

Recognize new maven, gradle, eclipse project(s) after first init #144

Closed
svarlamov opened this issue Feb 6, 2017 · 9 comments
Closed

Recognize new maven, gradle, eclipse project(s) after first init #144

svarlamov opened this issue Feb 6, 2017 · 9 comments
Assignees
Milestone

Comments

@svarlamov
Copy link
Contributor

I initialize the server with a top-level workspace directory, that may or may not have projects in it. This top-level directory does not contain a pom.xml, since it's just a workspace. After the langserver gets initialized, I create a project under this top-level workspace, and it contains my pom.xml, plus a full Eclipse-ready project. Once this new project is created, I also send a workspace/didChangeWatchedFiles notification to the langserver that contains the created FileEdit objects, followed by a java/projectConfigurationUpdate notification where the URI is set to the new pom.xml that I just created. Then, once I call textDocument/didOpen on a Java file in that project's Maven src directory, I get the "Classpath is incomplete" error. However, if I restart the server, and just open that same Java file, everything works -- I also get the importing Maven projects msg on init, etc. So I'm assuming that I must be missing some sort of call to the server to have it import this newly created Maven project. Please let me know how I should proceed, and if this functionality requires me to customize the langserver project. Thanks so much for the help!

@fbricon
Copy link
Contributor

fbricon commented Feb 6, 2017

At the moment project initialization/import only occurs during language server (JLS) startup. So what you see is expected.
Late project initialization (after JLS init) is doable, I think. We just need to make sure we do it right.

However I don't consider that feature a priority item, compared to proper java support (intellisense, refactoring. ..).

@svarlamov
Copy link
Contributor Author

Thanks, so in order to implement this, would it be possible for me to add another method in the ProjectsManager to add a project post-startup?

@gorkem
Copy link
Contributor

gorkem commented Feb 7, 2017

@svarlamov Yes method is needed. Also you need to have the logic in proper place that triggers the method. Feel free to send an early pull request to discuss. @fbricon and I can help you mature it.

@svarlamov
Copy link
Contributor Author

I've added a function in to handle this, however, it seems that as long as the data path is the same as the workspace root, then this is handled automatically. How is this happening behind the scenes? Feels like an Eclipse-handled process

@fbricon
Copy link
Contributor

fbricon commented Feb 14, 2017

I'm not sure I understand that last comment. What is handled automatically?

The only build related part that is handled automatically is updating the project configuration automatically, when a pom.xm or gradle file changes, if the java.configuration.updateBuildConfiguration setting is set to automatic

@svarlamov
Copy link
Contributor Author

So first of all, I'm using this outside of the vscode ext context, however, I'm currently setting the updateBuildConfiguration property to automatic in the workspace/didChangeConfiguration method just after I initialize the server. I'm not sure if that setting has anything to do with it -- haven't really explored that yet. What I did so far is write a method (and surrounding handlers, etc.) that adds a project to the workspace.

public IStatus addProject(final String projRootPath, IProgressMonitor monitor) {
		SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
		try {
			File userProjectRoot = new File(projRootPath);
			IProjectImporter importer = getImporter(userProjectRoot, subMonitor.split(20));
			if (importer != null) {
				importer.importToWorkspace(subMonitor.split(70));
			}
			return Status.OK_STATUS;
		} catch (CoreException e) {
			JavaLanguageServerPlugin.logException("Problem importing to workspace", e);
			return StatusFactory.newErrorStatus("Import failed: " + e.getMessage(), e);
		} catch (InterruptedException e) {
			JavaLanguageServerPlugin.logInfo("Import cancelled");
			return Status.CANCEL_STATUS;
		}
	}

I'm finding that the importer (maven) just passes over actually doing anything with the 'new' project, because the IProject project = importResult.getProject(); is not null. So I'm assuming that somehow the project is getting automatically recognised by the underlying Eclipse library, prior to me actually adding it in anywhere? Also, perhaps this project is getting imported by the default Eclipse importer prior to the Maven importer? Haven't done enough digging here to really understand all of the aspects at work here

@fbricon
Copy link
Contributor

fbricon commented Nov 13, 2018

@snjeza can you please take a look at that one. This is needed by Che, among other clients.

@tsmaeder
Copy link
Contributor

I think the title is a bit misleading: if we start recognizing new build files, it should include all build files we understand: maven, gradle, eclipse...

@fbricon
Copy link
Contributor

fbricon commented May 20, 2020

Fixed with 6e09b58
A new java.project.import is available that automatically imports newfound projects

@fbricon fbricon closed this as completed May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants