FIR LT: extract syntax diagnostic info from error element
#KT-56701 fixed
This commit is contained in:
committed by
Space Team
parent
e39eb62e6e
commit
27db8ce1bb
+7
@@ -4931,4 +4931,11 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
|||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
add(FirSyntaxErrors.SYNTAX_WITH_MESSAGE) { firDiagnostic ->
|
||||||
|
SyntaxWithMessageImpl(
|
||||||
|
firDiagnostic.a,
|
||||||
|
firDiagnostic as KtPsiDiagnostic,
|
||||||
|
token,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -3428,4 +3428,9 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
|||||||
override val diagnosticClass get() = Syntax::class
|
override val diagnosticClass get() = Syntax::class
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class SyntaxWithMessage : KtFirDiagnostic<PsiElement>() {
|
||||||
|
override val diagnosticClass get() = SyntaxWithMessage::class
|
||||||
|
abstract val message: String
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -4150,3 +4150,9 @@ internal class SyntaxImpl(
|
|||||||
override val token: KtLifetimeToken,
|
override val token: KtLifetimeToken,
|
||||||
) : KtFirDiagnostic.Syntax(), KtAbstractFirDiagnostic<PsiElement>
|
) : KtFirDiagnostic.Syntax(), KtAbstractFirDiagnostic<PsiElement>
|
||||||
|
|
||||||
|
internal class SyntaxWithMessageImpl(
|
||||||
|
override val message: String,
|
||||||
|
override val firDiagnostic: KtPsiDiagnostic,
|
||||||
|
override val token: KtLifetimeToken,
|
||||||
|
) : KtFirDiagnostic.SyntaxWithMessage(), KtAbstractFirDiagnostic<PsiElement>
|
||||||
|
|
||||||
|
|||||||
+3
@@ -14,5 +14,8 @@ import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.DiagnosticL
|
|||||||
object SYNTAX_DIAGNOSTIC_LIST : DiagnosticList("FirSyntaxErrors") {
|
object SYNTAX_DIAGNOSTIC_LIST : DiagnosticList("FirSyntaxErrors") {
|
||||||
val Syntax by object : DiagnosticGroup("Syntax") {
|
val Syntax by object : DiagnosticGroup("Syntax") {
|
||||||
val SYNTAX by error<PsiElement>()
|
val SYNTAX by error<PsiElement>()
|
||||||
|
val SYNTAX_WITH_MESSAGE by error<PsiElement>() {
|
||||||
|
parameter<String>("message")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+7
-1
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.lightTree.converter
|
package org.jetbrains.kotlin.fir.lightTree.converter
|
||||||
|
|
||||||
import com.intellij.lang.LighterASTNode
|
import com.intellij.lang.LighterASTNode
|
||||||
|
import com.intellij.lang.impl.PsiBuilderImpl
|
||||||
import com.intellij.psi.TokenType
|
import com.intellij.psi.TokenType
|
||||||
import com.intellij.util.diff.FlyweightCapableTreeStructure
|
import com.intellij.util.diff.FlyweightCapableTreeStructure
|
||||||
import org.jetbrains.kotlin.*
|
import org.jetbrains.kotlin.*
|
||||||
@@ -91,7 +92,12 @@ class DeclarationsConverter(
|
|||||||
private val expressionConverter = ExpressionsConverter(session, tree, this, context)
|
private val expressionConverter = ExpressionsConverter(session, tree, this, context)
|
||||||
|
|
||||||
override fun reportSyntaxError(node: LighterASTNode) {
|
override fun reportSyntaxError(node: LighterASTNode) {
|
||||||
diagnosticsReporter?.reportOn(node.toFirSourceElement(), FirSyntaxErrors.SYNTAX, diagnosticContext!!)
|
val message = PsiBuilderImpl.getErrorMessage(node)
|
||||||
|
if (message == null) {
|
||||||
|
diagnosticsReporter?.reportOn(node.toFirSourceElement(), FirSyntaxErrors.SYNTAX, diagnosticContext!!)
|
||||||
|
} else {
|
||||||
|
diagnosticsReporter?.reportOn(node.toFirSourceElement(), FirSyntaxErrors.SYNTAX_WITH_MESSAGE, message, diagnosticContext!!)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
|
|||||||
object FirSyntaxErrors {
|
object FirSyntaxErrors {
|
||||||
// Syntax
|
// Syntax
|
||||||
val SYNTAX by error0<PsiElement>()
|
val SYNTAX by error0<PsiElement>()
|
||||||
|
val SYNTAX_WITH_MESSAGE by error1<PsiElement, String>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
RootDiagnosticRendererFactory.registerFactory(FirSyntaxErrorsDefaultMessages)
|
RootDiagnosticRendererFactory.registerFactory(FirSyntaxErrorsDefaultMessages)
|
||||||
|
|||||||
+3
@@ -6,11 +6,14 @@
|
|||||||
package org.jetbrains.kotlin.fir.builder
|
package org.jetbrains.kotlin.fir.builder
|
||||||
|
|
||||||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
|
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
|
||||||
|
import org.jetbrains.kotlin.diagnostics.KtDiagnosticRenderers.TO_STRING
|
||||||
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
|
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
|
||||||
|
import org.jetbrains.kotlin.diagnostics.rendering.Renderer
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object FirSyntaxErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
object FirSyntaxErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
||||||
override val MAP = KtDiagnosticFactoryToRendererMap("FIR").also { map ->
|
override val MAP = KtDiagnosticFactoryToRendererMap("FIR").also { map ->
|
||||||
map.put(FirSyntaxErrors.SYNTAX, "Syntax error")
|
map.put(FirSyntaxErrors.SYNTAX, "Syntax error")
|
||||||
|
map.put(FirSyntaxErrors.SYNTAX_WITH_MESSAGE, "Syntax error: {0}", TO_STRING)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
|
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
|
||||||
compiler/testData/cli/jvm/firSyntaxError.kt:1:10: error: syntax error
|
compiler/testData/cli/jvm/firSyntaxError.kt:1:10: error: syntax error: Expecting '}'
|
||||||
fun a() {
|
fun a() {
|
||||||
^
|
^
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
Reference in New Issue
Block a user