From f3646347f7fe4e70d630ce4faa984645785d6bd6 Mon Sep 17 00:00:00 2001 From: Piotr Tomiak Date: Wed, 26 Jun 2024 11:17:40 +0200 Subject: [PATCH] WEB-67260 TS: provide type evaluation location where needed and make service tests green GitOrigin-RevId: 041576daa95a84f293e9960d1e3a4efe937cc2b0 --- .../WebSymbolAttributeNameCompletionProvider.kt | 2 +- .../WebSymbolAttributeDescriptorsProvider.kt | 2 +- .../attributes/WebSymbolHtmlAttributeInfo.kt | 5 +++-- .../WebSymbolHtmlAttributeValueTypeSupport.kt | 3 ++- .../impl/WebSymbolHtmlAttributeInfoImpl.kt | 12 ++++++++---- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/xml/impl/src/com/intellij/html/webSymbols/attributes/WebSymbolAttributeNameCompletionProvider.kt b/xml/impl/src/com/intellij/html/webSymbols/attributes/WebSymbolAttributeNameCompletionProvider.kt index 35e3cc9adb60..468f7855e128 100644 --- a/xml/impl/src/com/intellij/html/webSymbols/attributes/WebSymbolAttributeNameCompletionProvider.kt +++ b/xml/impl/src/com/intellij/html/webSymbols/attributes/WebSymbolAttributeNameCompletionProvider.kt @@ -78,7 +78,7 @@ class WebSymbolAttributeNameCompletionProvider : WebSymbolsCompletionProviderBas val fullName = name.substring(0, item.offset) + item.name val match = freshRegistry.runNameMatchQuery(NAMESPACE_HTML, KIND_HTML_ATTRIBUTES, fullName) .asSingleSymbol() ?: return@withInsertHandlerAdded - val info = WebSymbolHtmlAttributeInfo.create(fullName, freshRegistry, match) + val info = WebSymbolHtmlAttributeInfo.create(fullName, freshRegistry, match, insertionContext.file) if (info.acceptsValue && !info.acceptsNoValue) { XmlAttributeInsertHandler.INSTANCE.handleInsert(insertionContext, lookupItem) } diff --git a/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/WebSymbolAttributeDescriptorsProvider.kt b/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/WebSymbolAttributeDescriptorsProvider.kt index c05d4c5faf20..a9851a3bd56d 100644 --- a/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/WebSymbolAttributeDescriptorsProvider.kt +++ b/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/WebSymbolAttributeDescriptorsProvider.kt @@ -65,7 +65,7 @@ class WebSymbolAttributeDescriptorsProvider : XmlAttributeDescriptorsProvider { this .asSafely() ?.descriptor - ?: WebSymbolHtmlAttributeInfo.create(attributeName, registry, this) + ?: WebSymbolHtmlAttributeInfo.create(attributeName, registry, this, context) .toAttributeDescriptor(context) } \ No newline at end of file diff --git a/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/WebSymbolHtmlAttributeInfo.kt b/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/WebSymbolHtmlAttributeInfo.kt index 1f2c1898e1d9..552edf2d3474 100644 --- a/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/WebSymbolHtmlAttributeInfo.kt +++ b/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/WebSymbolHtmlAttributeInfo.kt @@ -88,8 +88,9 @@ interface WebSymbolHtmlAttributeInfo { @JvmStatic fun create(name: String, queryExecutor: WebSymbolsQueryExecutor, - symbol: WebSymbol): WebSymbolHtmlAttributeInfo = - WebSymbolHtmlAttributeInfoImpl.create(name, queryExecutor, symbol) + symbol: WebSymbol, + context: PsiElement): WebSymbolHtmlAttributeInfo = + WebSymbolHtmlAttributeInfoImpl.create(name, queryExecutor, symbol, context) @JvmStatic fun create( diff --git a/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/WebSymbolHtmlAttributeValueTypeSupport.kt b/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/WebSymbolHtmlAttributeValueTypeSupport.kt index 7d202cb46294..9ea5d5be5acf 100644 --- a/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/WebSymbolHtmlAttributeValueTypeSupport.kt +++ b/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/WebSymbolHtmlAttributeValueTypeSupport.kt @@ -1,6 +1,7 @@ // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.html.webSymbols.attributes +import com.intellij.psi.PsiElement import com.intellij.util.ThreeState import com.intellij.webSymbols.WebSymbol import com.intellij.webSymbols.WebSymbolTypeSupport @@ -13,7 +14,7 @@ interface WebSymbolHtmlAttributeValueTypeSupport : WebSymbolTypeSupport { * [ThreeState.UNSURE] if the boolean is assignable to the type and * [ThreeState.NO] if boolean is not assignable to the type */ - fun isBoolean(symbol: WebSymbol, type: Any?): ThreeState + fun isBoolean(symbol: WebSymbol, type: Any?, context: PsiElement): ThreeState fun createStringType(symbol: WebSymbol): Any? diff --git a/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/impl/WebSymbolHtmlAttributeInfoImpl.kt b/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/impl/WebSymbolHtmlAttributeInfoImpl.kt index cb7e194c7f59..d5cea8757e55 100644 --- a/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/impl/WebSymbolHtmlAttributeInfoImpl.kt +++ b/xml/xml-psi-impl/src/com/intellij/html/webSymbols/attributes/impl/WebSymbolHtmlAttributeInfoImpl.kt @@ -3,6 +3,7 @@ package com.intellij.html.webSymbols.attributes.impl import com.intellij.html.webSymbols.attributes.WebSymbolHtmlAttributeInfo import com.intellij.html.webSymbols.attributes.WebSymbolHtmlAttributeValueTypeSupport +import com.intellij.psi.PsiElement import com.intellij.util.ThreeState import com.intellij.webSymbols.WebSymbol import com.intellij.webSymbols.completion.WebSymbolCodeCompletionItem @@ -81,9 +82,12 @@ internal data class WebSymbolHtmlAttributeInfoImpl( priority = priority) companion object { - fun create(name: String, - queryExecutor: WebSymbolsQueryExecutor, - symbol: WebSymbol): WebSymbolHtmlAttributeInfo { + fun create( + name: String, + queryExecutor: WebSymbolsQueryExecutor, + symbol: WebSymbol, + context: PsiElement, + ): WebSymbolHtmlAttributeInfo { val typeSupport = symbol.origin.typeSupport as? WebSymbolHtmlAttributeValueTypeSupport val attrValue = symbol.attributeValue val kind = attrValue?.kind ?: WebSymbolHtmlAttributeValue.Kind.PLAIN @@ -113,7 +117,7 @@ internal data class WebSymbolHtmlAttributeInfoImpl( if (type == WebSymbolHtmlAttributeValue.Type.BOOLEAN) ThreeState.YES else - typeSupport?.isBoolean(symbol, langType) ?: ThreeState.YES + typeSupport?.isBoolean(symbol, langType, context) ?: ThreeState.YES else ThreeState.NO val valueRequired = attrValue?.required != false && isHtmlBoolean == ThreeState.NO && kind != WebSymbolHtmlAttributeValue.Kind.NO_VALUE