Skip to content

Conversation

@treilhes
Copy link
Contributor

@treilhes treilhes commented Oct 16, 2022

Hello,

I will try to be the most precise possible.

The issue exhibited here only happens when the eclipse workspace contains a file accessible from more than one project which is a common case when working on maven multi modules projects (i think gradle multi modules projects are also impacted but i did not check)

Eclipse workspace with 2 projects : parent_project, nested_project
Where nested_project is contained in parent_project

parent_project
|
-- nested_project
    |
    -- file.ext

nested_project
|
-- file.ext   

With this kind of workspace, we have two cases:

  • When the projects presentation is "Hierarchical", the file edited is the most nested and the method LSPEclipseUtils.findResourceFor(uri) will return the correct IResource (provided the function LSPEclipseUtils.findMostNested works properly)
  • When the projects presentation is "Flat", the method is totaly unreliable because more than one valid value can be returned and the most nested is not necessarily the one edited or the only one edited. (the test LSPEclipseUtilsTest.testURIToResourceMappingWithNestedProject provided in pull request to see the issue)

The bug in LSPEclipseUtils.findMostNested was realy simple like you can see in the code.
The function was returning the first processed IFile instead of the most nested which may leads to return an incorrect IResource from LSPEclipseUtils.findResourceFor(uri)

I think this pull request solves the issues #32, #112

Why?

Because while editing a file and temporary errors pop up then a non empty diagnostic is returned by the language server.
Provided we have a multi modules workspace like described earlier then:

  • the call to LSPEclipseUtils.findResourceFor(uri) in LSPDiagnosticsToMarkers.accept(PublishDiagnosticsParams diagnostics) may return the wrong IResource
  • then in LSPDiagnosticsToMarkers.updateMarkers(PublishDiagnosticsParams diagnostics, IResource resource) the disconnected boolean will be set to true because the IResource provided is not the one edited :
// A language server can scan the whole project and generate diagnostics for files that are not currently open in the IDE
// (the markers will show up in the problem view). If so, need to open the document temporarily but be sure to release it
// when we're done
final boolean disconnect = !diagnostics.getDiagnostics().isEmpty() && LSPEclipseUtils.getExistingDocument(resource) == null;
  • if only one file is connected to the language server, the server will be shut down and subsequent calls will return:
    java.io.IOException: Stream closed

This pull request may solve issues related to multi modules workspace but only for users using the "Hierarchycal" project presentation. For those using the "Flat" project presentation, i created the issue #258 but i think it won't be a trivial one as LSP4E does not seem to currently support multiple editors for the same file opened from multiple projects.

@mickaelistria
Copy link
Contributor

1 test is failing, it looks like your proposed fix is incomplete.

@mickaelistria mickaelistria merged commit 53cfa49 into eclipse-lsp4e:master Oct 19, 2022
@mickaelistria
Copy link
Contributor

Thanks!

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.

2 participants