1212package com .redhat .devtools .intellij .qute .psi .utils ;
1313
1414import com .intellij .java .library .JavaLibraryUtil ;
15+ import com .intellij .openapi .application .ApplicationManager ;
16+ import com .intellij .openapi .application .ReadAction ;
1517import com .intellij .openapi .module .Module ;
1618import com .intellij .openapi .module .ModuleUtilCore ;
1719import com .intellij .openapi .project .Project ;
1820import com .intellij .openapi .roots .ModuleRootManager ;
1921import com .intellij .openapi .vfs .VfsUtilCore ;
2022import com .intellij .openapi .vfs .VirtualFile ;
2123import com .redhat .devtools .intellij .quarkus .QuarkusModuleUtil ;
24+ import com .redhat .devtools .intellij .qute .psi .internal .QuteJavaConstants ;
2225import com .redhat .devtools .intellij .qute .psi .internal .template .rootpath .TemplateRootPathProviderRegistry ;
2326import com .redhat .devtools .lsp4ij .LSPIJUtils ;
24- import com .redhat .devtools .intellij .qute .psi .internal .QuteJavaConstants ;
25- import com .redhat .qute .commons .FileUtils ;
2627import com .redhat .qute .commons .ProjectInfo ;
2728import com .redhat .qute .commons .TemplateRootPath ;
2829import io .quarkus .runtime .util .StringUtil ;
3233
3334import java .nio .file .Path ;
3435import java .nio .file .Paths ;
35- import java .util .*;
36+ import java .util .HashSet ;
37+ import java .util .Iterator ;
38+ import java .util .List ;
39+ import java .util .Set ;
3640import java .util .stream .Collectors ;
3741
3842/**
@@ -62,7 +66,7 @@ public static ProjectInfo getProjectInfo(Module javaProject) {
6266 // Template root paths
6367 List <TemplateRootPath > templateRootPaths = TemplateRootPathProviderRegistry .getInstance ()
6468 .getTemplateRootPaths (javaProject );
65- return new ProjectInfo (projectUri , projectDependencies
69+ return new ProjectInfo (projectUri , projectDependencies
6670 .stream ()
6771 .filter (projectDependency -> !javaProject .equals (projectDependency ))
6872 .map (LSPIJUtils ::getProjectUri )
@@ -82,6 +86,7 @@ public static String getTemplateBaseDir(Module javaProject, String templateFolde
8286 }
8387 return LSPIJUtils .toUri (javaProject ).resolve (RESOURCES_BASE_DIR ).resolve (templateFolderName ).toASCIIString ();
8488 }
89+
8590 /**
8691 * Returns the full path of the Qute templates base dir '$base-dir-of-module/src/main/resources/templates' for the given module.
8792 *
@@ -236,12 +241,17 @@ public static void appendAndSlash(@NotNull StringBuilder path, @NotNull String s
236241 }
237242
238243 public static boolean isQuteTemplate (VirtualFile file , Module module ) {
239- String templateFileUri = file .getPath ();
240- if (file .getPath ().contains (TEMPLATES_FOLDER_NAME ) &&
244+ return ApplicationManager .getApplication ().isReadAccessAllowed () ?
245+ internalIsQuteTemplate (file , module ) :
246+ (Boolean ) ReadAction .compute (() -> internalIsQuteTemplate (file , module ));
247+ }
248+
249+ private static boolean internalIsQuteTemplate (VirtualFile file , Module module ) {
250+ if (file .getPath ().contains (TEMPLATES_FOLDER_NAME ) &&
241251 ModuleRootManager .getInstance (module ).getFileIndex ().isInSourceContent (file )) {
242252 return true ;
243253 }
244- ProjectInfo projectInfo = PsiQuteProjectUtils .getProjectInfo (module );
254+ ProjectInfo projectInfo = PsiQuteProjectUtils .getProjectInfo (module );
245255 if (projectInfo == null ) {
246256 return false ;
247257 }
0 commit comments