WEB-67260 TS: provide type evaluation location where needed and make service tests green

GitOrigin-RevId: 041576daa95a84f293e9960d1e3a4efe937cc2b0
This commit is contained in:
Piotr Tomiak
2024-06-26 11:17:40 +02:00
committed by intellij-monorepo-bot
parent d9112f7ece
commit f3646347f7
5 changed files with 15 additions and 9 deletions

View File

@@ -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)
}

View File

@@ -65,7 +65,7 @@ class WebSymbolAttributeDescriptorsProvider : XmlAttributeDescriptorsProvider {
this
.asSafely<WebSymbolsHtmlQueryConfigurator.HtmlAttributeDescriptorBasedSymbol>()
?.descriptor
?: WebSymbolHtmlAttributeInfo.create(attributeName, registry, this)
?: WebSymbolHtmlAttributeInfo.create(attributeName, registry, this, context)
.toAttributeDescriptor(context)
}

View File

@@ -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(

View File

@@ -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?

View File

@@ -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