Closed jjohnstn closed 1 year ago
@mickaelistria Please review.
This sound very promising! I wonder if this might be optimized by doing the following and only fallback to your search if the IFile
is not a local files:
IFile#getLoaction().getFile()
and check it is not null
IWorkspaceRoot.findFilesForLocation
to get a list of all items mapping to that physical fileIt might even worth it to think about a new IFile#getInnermostProject()
method, then you can even work on the internal state of the object what might be more efficient (or at laest can be optimized later on) and it would be usable on other places as well.
+1 with what @laeubi says, this is already implemented in multiple places with
URI locationUri = resource.getLocationURI();
return locationUri == null ? resource : //
Arrays.stream(resource.getWorkspace().getRoot().findFilesForLocationURI(locationUri)) //
.sorted(Comparator.comparingInt(aFile -> aFile.getFullPath().segments().length)) //
.findFirst() // shortest workspace (project reletive) full path means most nested project
.orElse(resource);
It might even worth it to think about a new IFile#getInnermostProject() method, then you can even work on the internal state of the object what might be more efficient (or at laest can be optimized later on) and it would be usable on other places as well.
The "innermost" is not related to the state of the file, but to the state of the workspace root, so such API would be IWorkspaceRoot.findInnerMostFile(IFile)
. It would be welcome as this code is already repeated in multiple places.
.sorted(Comparator.comparingInt(aFile -> aFile.getFullPath().segments().length)) //
Even though there are not many locations (on avg), it might be worthwhile to consider using min(Comparator)
rather than sorted.
Even though there are not many locations (on avg), it might be worthwhile to consider using min(Comparator) rather than sorted.
Indeed, and thanks for noting! That's one more reason to have a good API for it, so we optimize it in one place instead of repeating less efficient constructs in multiple places ;)
The "innermost" is not related to the state of the file, but to the state of the workspace root, so such API would be IWorkspaceRoot.findInnerMostFile(IFile). It would be welcome as this code is already repeated in multiple places.
Each file belongs to a Workspace that has a workspace root, so I would at least want a delegate in IFile
so it is easier to find/use, to be honest, as a user I would exspect that IFile#getProject
aslready return exactly that value, but thats nothing one can change I assume so IFile#get<whateveritsnamed>Project()
+ a hint on getProject
would make this more obvious and hopefully improve the overall userexperience over time.
Just an FYI. People do bad things and some of those people are "us":
org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.ContributionDataFile
Thank you all for your work. I know I will enjoy this improvement a lot.