[js] WEB-68097 calculate type text of jsx attributes asynchronously

(cherry picked from commit 0906a3a855f5cc0f5bb85572120aab56a67146b5)

IJ-CR-149013

GitOrigin-RevId: 83f32ee5e2e832da65d7266d2ed44611939d1998
This commit is contained in:
Konstantin Ulitin
2024-11-05 05:08:24 +00:00
committed by intellij-monorepo-bot
parent 104b266ae0
commit 085b4b654c
2 changed files with 29 additions and 19 deletions

View File

@@ -0,0 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight.completion;
public interface PsiPresentableMetaDataRenderStrategy {
boolean isExpensiveRender();
}

View File

@@ -1,22 +1,10 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.codeInsight.lookup.LookupElementPresentation;
import com.intellij.codeInsight.lookup.LookupElementRenderer;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiFile;
@@ -112,10 +100,25 @@ public class XmlAttributeReferenceCompletionProvider extends CompletionProvider<
}
LookupElementBuilder element = LookupElementBuilder.create(name);
if (descriptor instanceof PsiPresentableMetaData presentableMetaData) {
element = element.withIcon(presentableMetaData.getIcon());
String typeName = presentableMetaData.getTypeName();
if (!StringUtil.isEmpty(typeName)) {
element = element.withTypeText(typeName);
if (descriptor instanceof PsiPresentableMetaDataRenderStrategy renderStrategy && renderStrategy.isExpensiveRender()) {
element = element.withExpensiveRenderer(new LookupElementRenderer<>() {
@Override
public void renderElement(LookupElement element, LookupElementPresentation presentation) {
element.renderElement(presentation);
presentation.setIcon(presentableMetaData.getIcon());
String typeName = presentableMetaData.getTypeName();
if (!StringUtil.isEmpty(typeName)) {
presentation.setTypeText(typeName);
}
}
});
}
else {
element = element.withIcon(presentableMetaData.getIcon());
String typeName = presentableMetaData.getTypeName();
if (!StringUtil.isEmpty(typeName)) {
element = element.withTypeText(typeName);
}
}
}
final int separator = name.indexOf(':');