12
12
package com .redhat .devtools .intellij .qute .psi .utils ;
13
13
14
14
import com .intellij .java .library .JavaLibraryUtil ;
15
+ import com .intellij .openapi .application .ApplicationManager ;
16
+ import com .intellij .openapi .application .ReadAction ;
15
17
import com .intellij .openapi .module .Module ;
16
18
import com .intellij .openapi .module .ModuleUtilCore ;
17
19
import com .intellij .openapi .project .Project ;
18
20
import com .intellij .openapi .roots .ModuleRootManager ;
19
21
import com .intellij .openapi .vfs .VfsUtilCore ;
20
22
import com .intellij .openapi .vfs .VirtualFile ;
21
23
import com .redhat .devtools .intellij .quarkus .QuarkusModuleUtil ;
24
+ import com .redhat .devtools .intellij .qute .psi .internal .QuteJavaConstants ;
22
25
import com .redhat .devtools .intellij .qute .psi .internal .template .rootpath .TemplateRootPathProviderRegistry ;
23
26
import com .redhat .devtools .lsp4ij .LSPIJUtils ;
24
- import com .redhat .devtools .intellij .qute .psi .internal .QuteJavaConstants ;
25
- import com .redhat .qute .commons .FileUtils ;
26
27
import com .redhat .qute .commons .ProjectInfo ;
27
28
import com .redhat .qute .commons .TemplateRootPath ;
28
29
import io .quarkus .runtime .util .StringUtil ;
32
33
33
34
import java .nio .file .Path ;
34
35
import 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 ;
36
40
import java .util .stream .Collectors ;
37
41
38
42
/**
@@ -62,7 +66,7 @@ public static ProjectInfo getProjectInfo(Module javaProject) {
62
66
// Template root paths
63
67
List <TemplateRootPath > templateRootPaths = TemplateRootPathProviderRegistry .getInstance ()
64
68
.getTemplateRootPaths (javaProject );
65
- return new ProjectInfo (projectUri , projectDependencies
69
+ return new ProjectInfo (projectUri , projectDependencies
66
70
.stream ()
67
71
.filter (projectDependency -> !javaProject .equals (projectDependency ))
68
72
.map (LSPIJUtils ::getProjectUri )
@@ -82,6 +86,7 @@ public static String getTemplateBaseDir(Module javaProject, String templateFolde
82
86
}
83
87
return LSPIJUtils .toUri (javaProject ).resolve (RESOURCES_BASE_DIR ).resolve (templateFolderName ).toASCIIString ();
84
88
}
89
+
85
90
/**
86
91
* Returns the full path of the Qute templates base dir '$base-dir-of-module/src/main/resources/templates' for the given module.
87
92
*
@@ -236,12 +241,17 @@ public static void appendAndSlash(@NotNull StringBuilder path, @NotNull String s
236
241
}
237
242
238
243
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 ) &&
241
251
ModuleRootManager .getInstance (module ).getFileIndex ().isInSourceContent (file )) {
242
252
return true ;
243
253
}
244
- ProjectInfo projectInfo = PsiQuteProjectUtils .getProjectInfo (module );
254
+ ProjectInfo projectInfo = PsiQuteProjectUtils .getProjectInfo (module );
245
255
if (projectInfo == null ) {
246
256
return false ;
247
257
}
0 commit comments