-
Notifications
You must be signed in to change notification settings - Fork 51
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: WIP let gradle main module find templates #1240
Conversation
Signed-off-by: Fred Bricon <[email protected]>
SonarCloud Quality Gate failed. 0 Bugs No Coverage information Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
It would be really nice to copy / paste tests with Qute codelens, document link and validation from https://github.com/redhat-developer/intellij-quarkus/tree/main/src/test/java/com/redhat/devtools/intellij/qute/psi/java and adapt them for gradle by using the same templates. |
.collect(Collectors.toList()), templateBaseDir); | ||
} | ||
|
||
private static String getTemplateBaseDir(Module javaProject) { | ||
List<VirtualFile> resourcesDirs = ModuleRootManager.getInstance(javaProject).getSourceRoots(JavaResourceRootType.RESOURCE); | ||
if (!resourcesDirs.isEmpty()) { | ||
for (var dir : resourcesDirs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove TEMPLATES_BASE_DIR constants ad have:
- TEMPLATES_FOLDER_NAME = "templates"
- RESOURCES_BASE_DIR = "src/main"
List<VirtualFile> resourcesDirs = ModuleRootManager.getInstance(javaProject).getSourceRoots(JavaResourceRootType.RESOURCE); | ||
if (!resourcesDirs.isEmpty()) { | ||
for (var dir : resourcesDirs) { | ||
var templatesDir = dir.findChild("templates"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var templatesDir = dir.findChild(TEMPLATES_FOLDER_NAME);
return LSPIJUtils.toUri(templatesDir).toASCIIString(); | ||
} | ||
} | ||
return LSPIJUtils.toUri(resourcesDirs.get(0)).resolve("templates").toASCIIString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return LSPIJUtils.toUri(resourcesDirs.get(0)).resolve(TEMPLATES_FOLDER_NAME).toASCIIString();
} | ||
} | ||
return LSPIJUtils.toUri(resourcesDirs.get(0)).resolve("templates").toASCIIString(); | ||
} | ||
return LSPIJUtils.toUri(javaProject).resolve(TEMPLATES_BASE_DIR).toASCIIString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return LSPIJUtils.toUri(javaProject).rsolve(RESOURCES_BASE_DIR ).resolve(TEMPLATES_BASE_DIR).toASCIIString();
return LSPIJUtils.toUri(javaProject).resolve(TEMPLATES_BASE_DIR).toASCIIString(); | ||
} | ||
|
||
public List<VirtualFile> getSortedSourceRoots(Module module) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method seems unused
@@ -203,8 +208,12 @@ private VirtualFile getTemplateFile(Module project, String templateFilePathWitho | |||
|
|||
@Nullable | |||
private VirtualFile getVirtualFile(Module project, String templateFilePathWithoutExtension, String suffix) { | |||
VirtualFile @NotNull [] roots = ModuleRootManager.getInstance(project).getContentRoots(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the main problem is that templateFilePathWithoutExtension
starts with src/main/resources/templates
(ex : src/main/resources/templates/page
). templateFilePathWithoutExtension should not starts with src/main/resources
but just with templates
(we will need to change that in the future too to support several known templates folder to scan like web for Quarkus Web Asset, but let's keep simple for the moment)
If templateFilePathWithoutExtension doesn't contains src/main/resources, you can use the same logic than getTemplateBaseDir(Module javaProject) by using:
List<VirtualFile> resourcesDirs = ModuleRootManager.getInstance(javaProject).getSourceRoots(JavaResourceRootType.RESOURCE);
instead of using ModuleRootManager.getInstance(project).getContentRoots(); and perhaps avoid having a mergeUri method.
Close for #1237 |
Signed-off-by: Fred Bricon [email protected]