From ef7569726973f0caa9773a4e1a78db295b0123f1 Mon Sep 17 00:00:00 2001 From: azerr Date: Thu, 8 Jun 2023 19:58:18 +0200 Subject: [PATCH] fix: Read access problem with Qute getJavadoc (#932) Fixes #932 Signed-off-by: azerr --- .../qute/psi/QuteSupportForTemplate.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) 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 d90ab42c0..744749f25 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 @@ -11,12 +11,14 @@ *******************************************************************************/ package com.redhat.devtools.intellij.qute.psi; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.JavaModuleType; 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.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.IPsiUtils; @@ -51,7 +53,7 @@ /** * Qute support for Template file. - * + * * @author Angelo ZERR * */ @@ -69,11 +71,11 @@ public static QuteSupportForTemplate getInstance() { /** * Returns the project information for the given project Uri. - * + * * @param params the project information parameters. * @param utils the JDT LS utility. * @param monitor the progress monitor. - * + * * @return the project information for the given project Uri and null otherwise. */ public ProjectInfo getProjectInfo(QuteProjectParams params, IPsiUtils utils, ProgressIndicator monitor) { @@ -90,7 +92,7 @@ public ProjectInfo getProjectInfo(QuteProjectParams params, IPsiUtils utils, Pro /** * Collect data model templates from the given project Uri. A data model * template can be declared with: - * + * * - * + * * @param params the project uri. * @param utils JDT LS utilities * @param monitor the progress monitor - * + * * @return data model templates from the given project Uri. */ public DataModelProject> getDataModelProject( @@ -121,11 +123,11 @@ public DataModelProject> getDataModelProje /** * Collect user tags from the given project Uri. - * + * * @param params the project uri. * @param utils JDT LS utilities * @param monitor the progress monitor - * + * * @return user tags from the given project Uri. */ public List getUserTags(QuteUserTagParams params, IPsiUtils utils, ProgressIndicator monitor) @@ -141,11 +143,11 @@ public List getUserTags(QuteUserTagParams params, IPsiUtils utils, /** * Returns Java types for the given pattern which belong to the given project * Uri. - * + * * @param params the java types parameters. * @param utils the JDT LS utility. * @param monitor the progress monitor. - * + * * @return list of Java types. */ public List getJavaTypes(QuteJavaTypesParams params, IPsiUtils utils, ProgressIndicator monitor) { @@ -163,11 +165,11 @@ public List getJavaTypes(QuteJavaTypesParams params, IPsiUtils uti /** * Returns the Java definition of the given Java type, method, field, method * parameter, method invocation parameter and null otherwise. - * + * * @param params the Java element information. * @param utils the JDT LS utility. * @param monitor the progress monitor. - * + * * @return the Java definition of the given Java type, method, field, method * parameter, method invocation parameter and null otherwise. */ @@ -249,11 +251,11 @@ private PsiMethod findMethod(PsiClass type, String sourceMethod) { /** * Returns the resolved type (fields and methods) for the given Java type. - * + * * @param params the Java type to resolve. * @param utils the JDT LS utility. * @param monitor the progress monitor. - * + * * @return the resolved type (fields and methods) for the given Java type. */ public ResolvedJavaTypeInfo getResolvedJavaType(QuteResolvedJavaTypeParams params, IPsiUtils utils, @@ -370,8 +372,10 @@ public String getJavadoc(QuteJavadocParams params, IPsiUtils utils, ProgressIndi if (type == null) { return null; } - return getJavadoc(type, params.getDocumentFormat(), params.getMemberName(), params.getSignature(), utils, - monitor, new HashSet<>()); + final var finalUtils = utils; + return ApplicationManager.getApplication() + .runReadAction((Computable) () -> getJavadoc(type, params.getDocumentFormat(), params.getMemberName(), params.getSignature(), finalUtils, + monitor, new HashSet<>())); } catch (Exception e) { LOGGER.log(Level.WARNING, "Error while collecting Javadoc for " + params.getSourceType() + "#" + params.getMemberName(), e);