From ae4ede8a3c06647eb28ef2390aee3f515d544ee7 Mon Sep 17 00:00:00 2001 From: azerr Date: Fri, 22 Sep 2023 14:21:49 +0200 Subject: [PATCH] fix: Qute support for multi module project doesn't work Fixes #1164 Signed-off-by: azerr --- gradle.properties | 2 +- .../intellij/qute/lsp/QuteLanguageClient.java | 12 ++++--- .../qute/psi/QuteSupportForTemplate.java | 33 ++++++++++++++----- .../qute/psi/utils/PsiQuteProjectUtils.java | 18 ++++++++-- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/gradle.properties b/gradle.properties index b5514150c..461b63679 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,5 +5,5 @@ jetBrainsChannel=stable quarkusVersion=3.1.2.Final lsp4mpVersion=0.9.0 quarkusLsVersion=0.16.0 -quteLsVersion=0.16.0 +quteLsVersion=0.17.0-SNAPSHOT kotlin.stdlib.default.dependency = false diff --git a/src/main/java/com/redhat/devtools/intellij/qute/lsp/QuteLanguageClient.java b/src/main/java/com/redhat/devtools/intellij/qute/lsp/QuteLanguageClient.java index 0d339a4fa..558e3ec23 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/lsp/QuteLanguageClient.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/lsp/QuteLanguageClient.java @@ -40,10 +40,7 @@ import org.eclipse.lsp4j.*; import org.jetbrains.annotations.NotNull; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -136,6 +133,13 @@ public void sourceFilesChanged(Set> sources) { } } + @Override + public CompletableFuture> getProjects() { + Project project = getProject(); + var coalesceBy = new CoalesceByKey("qute/template/projects"); + return runAsBackground("Load Qute projects", monitor -> QuteSupportForTemplate.getInstance().getProjects(project, PsiUtilsLSImpl.getInstance(project), monitor), coalesceBy); + } + @Override public CompletableFuture getProjectInfo(QuteProjectParams params) { var coalesceBy = new CoalesceByKey("qute/template/project", params.getTemplateFileUri()); diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/QuteSupportForTemplate.java b/src/main/java/com/redhat/devtools/intellij/qute/psi/QuteSupportForTemplate.java index 53afa9f24..88e505283 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/psi/QuteSupportForTemplate.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/psi/QuteSupportForTemplate.java @@ -12,13 +12,12 @@ package com.redhat.devtools.intellij.qute.psi; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.module.JavaModuleType; +import com.intellij.openapi.module.*; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleManager; -import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.IndexNotReadyException; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; @@ -43,10 +42,7 @@ import org.eclipse.lsp4j.WorkspaceEdit; import java.io.IOException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -71,6 +67,27 @@ public static QuteSupportForTemplate getInstance() { return INSTANCE; } + /** + * Returns the list of Qute projects from the workspace. + * + * @param utils the JDT LS utility. + * @param monitor the progress monitor. + * + * @return the list of Qute projects from the workspace. + */ + public List getProjects(Project project, IPsiUtils utils, ProgressIndicator monitor) { + List quteProjects = new ArrayList<>(); + // Loop for module from the given project + Module[] modules = ModuleManager.getInstance(project).getModules(); + for (Module javaProject: modules) { + if (PsiQuteProjectUtils.hasQuteSupport(javaProject)) { + // It is a Qute project + quteProjects.add(PsiQuteProjectUtils.getProjectInfo(javaProject)); + } + } + return quteProjects; + } + /** * Returns the project information for the given project Uri. * @@ -477,6 +494,4 @@ private PsiClass getTypeFromParams(String typeName, String projectUri,Module jav return type; } - - } diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/utils/PsiQuteProjectUtils.java b/src/main/java/com/redhat/devtools/intellij/qute/psi/utils/PsiQuteProjectUtils.java index 27078f817..65d3681f2 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/psi/utils/PsiQuteProjectUtils.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/psi/utils/PsiQuteProjectUtils.java @@ -12,6 +12,7 @@ package com.redhat.devtools.intellij.qute.psi.utils; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.project.Project; import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil; import com.redhat.devtools.intellij.lsp4ij.LSPIJUtils; @@ -19,6 +20,12 @@ import com.redhat.qute.commons.ProjectInfo; import org.jetbrains.annotations.NotNull; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + /** * JDT Qute utilities. * @@ -39,8 +46,15 @@ private PsiQuteProjectUtils() { public static ProjectInfo getProjectInfo(Module javaProject) { String projectUri = getProjectURI(javaProject); - String templateBaseDir = LSPIJUtils.toUriAsString(QuarkusModuleUtil.getModuleDirPath(javaProject)) + TEMPLATES_BASE_DIR; - return new ProjectInfo(projectUri, templateBaseDir); + String templateBaseDir = LSPIJUtils.toUri(javaProject).resolve(TEMPLATES_BASE_DIR).toASCIIString(); + // Project dependencies + Set projectDependencies = new HashSet<>(); + ModuleUtilCore.getDependencies(javaProject, projectDependencies); + return new ProjectInfo(projectUri, projectDependencies + .stream() + .filter(projectDependency -> !javaProject.equals(projectDependency)) + .map(projectDependency -> LSPIJUtils.getProjectUri(projectDependency)) + .collect(Collectors.toList()), templateBaseDir); } /**