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

fix: Qute support for multi module project doesn't work #1177

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -136,6 +133,13 @@ public void sourceFilesChanged(Set<Pair<VirtualFile, Module>> sources) {
}
}

@Override
public CompletableFuture<Collection<ProjectInfo>> 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<ProjectInfo> getProjectInfo(QuteProjectParams params) {
var coalesceBy = new CoalesceByKey("qute/template/project", params.getTemplateFileUri());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand All @@ -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<ProjectInfo> getProjects(Project project, IPsiUtils utils, ProgressIndicator monitor) {
List<ProjectInfo> 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.
*
Expand Down Expand Up @@ -477,6 +494,4 @@ private PsiClass getTypeFromParams(String typeName, String projectUri,Module jav
return type;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
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;
import com.redhat.devtools.intellij.qute.psi.internal.QuteJavaConstants;
import com.redhat.qute.commons.ProjectInfo;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* JDT Qute utilities.
*
Expand All @@ -33,8 +40,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<Module> 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);
}

/**
Expand Down
Loading