Skip to content

Commit

Permalink
Make lazy collectiing of Workspace Artifacts in completion
Browse files Browse the repository at this point in the history
Make Maven Projects to be loaded/cached lazily when collecting the Workspace Artifacts
when gathering completions n order to make content assist faster and more responsive

Issue: eclipse-lemminx#444
  • Loading branch information
vrubezhny committed Aug 2, 2023
1 parent 1ef318b commit 43bd0bd
Show file tree
Hide file tree
Showing 5 changed files with 575 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,17 @@ private synchronized CompletableFuture<Void> getOrCreateMavenInitializer() {
// while Maven component is initializing.
if (mavenInitializer == null) {
if (isUnitTestMode()) {
mavenInitializer = new CompletableFuture<>();
doInitialize(() -> {});
mavenInitializer = CompletableFuture.completedFuture(null);
mavenInitializer.complete(null);
} else
mavenInitializer = CompletableFutures.computeAsync(cancelChecker -> {
doInitialize(cancelChecker);
return null;
});
}
// Start Maven Project Cache
mavenInitializer.thenAccept(t -> cache.initialized());
return mavenInitializer;
}

Expand Down Expand Up @@ -693,12 +696,28 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
/**
* Returns the list of Maven Projects currently added to the Workspace
*
* @param buildIfNecessary A boolean 'true' indicates that all projects are to
* be returned, not only the cached ones at the moment,
* method should wait for the final build result,
* otherwise the only project that are already built and
* cached are to be returned, the rest of the projects
* are to be built in background
* @return List of Maven Projects
*/
public List<MavenProject> getCurrentWorkspaceProjects() {
return workspaceReader.getCurrentWorkspaceArtifactFiles().stream()
.map(f -> getProjectCache().getLastSuccessfulMavenProject(f))
.filter(Objects::nonNull).toList();
public List<MavenProject> getCurrentWorkspaceProjects(boolean wait) {
if (wait) {
return workspaceReader.getCurrentWorkspaceArtifactFiles().stream()
.map(file -> getProjectCache().getLastSuccessfulMavenProject(file))
.filter(Objects::nonNull)
.toList();
} else {
return workspaceReader.getCurrentWorkspaceArtifactFiles().stream()
.map(file -> getProjectCache().assyncGetLoadedMavenProject(file))
.map(f -> f.getNow(null))
.filter(Objects::nonNull)
.map(LoadedMavenProject::getMavenProject)
.toList();
}
}

/**
Expand Down
Loading

0 comments on commit 43bd0bd

Please sign in to comment.