mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[evaluation-plugin] add MultiLineCompletionStrategy with an option to invoke completion on each line of the method
GitOrigin-RevId: 42f6ecbc494a6136047bd85bf3c138875ef30a66
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c08f1be92e
commit
24d082109c
@@ -149,5 +149,8 @@ enum class TypeProperty {
|
||||
FIELD,
|
||||
ARGUMENT_NAME,
|
||||
PARAMETER_MEMBER,
|
||||
|
||||
METHOD,
|
||||
CLASS,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import kotlinx.html.*
|
||||
import kotlinx.html.stream.createHTML
|
||||
import org.apache.commons.lang3.StringEscapeUtils
|
||||
|
||||
class BasicFileReportGenerator(
|
||||
open class BasicFileReportGenerator(
|
||||
filterName: String,
|
||||
comparisonFilterName: String,
|
||||
featuresStorages: List<FeaturesStorage>,
|
||||
@@ -35,6 +35,8 @@ class BasicFileReportGenerator(
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun textToInsert(session: Session): String = session.expectedText
|
||||
|
||||
private fun getLineNumbers(linesCount: Int): String =
|
||||
(1..linesCount).joinToString("\n") { it.toString().padStart(linesCount.toString().length) }
|
||||
|
||||
@@ -64,16 +66,17 @@ class BasicFileReportGenerator(
|
||||
val commonText = StringEscapeUtils.escapeHtml4(text.substring(offset, session.offset))
|
||||
append(commonText)
|
||||
|
||||
val center = session.expectedText.length / sessions.size
|
||||
val textToInsert = textToInsert(session)
|
||||
val center = textToInsert.length / sessions.size
|
||||
var shift = 0
|
||||
for (j in 0 until sessionGroup.lastIndex) {
|
||||
val subToken = if (center == 0) session.expectedText else session.expectedText.substring(shift, shift + center)
|
||||
val subToken = if (center == 0) textToInsert else textToInsert.substring(shift, shift + center)
|
||||
append(getSpan(sessionGroup[j], subToken, lookupOrder))
|
||||
append(delimiter)
|
||||
shift += center
|
||||
}
|
||||
append(getSpan(sessionGroup.last(), session.expectedText.substring(shift), lookupOrder))
|
||||
offset = session.offset + session.expectedText.length
|
||||
append(getSpan(sessionGroup.last(), textToInsert.substring(shift), lookupOrder))
|
||||
offset = session.offset + textToInsert.length
|
||||
}
|
||||
append(StringEscapeUtils.escapeHtml4(text.substring(offset)))
|
||||
toString()
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.cce.report
|
||||
|
||||
import com.intellij.cce.core.Session
|
||||
import com.intellij.cce.workspace.storages.FeaturesStorage
|
||||
|
||||
class MultiLineFileReportGenerator(
|
||||
filterName: String,
|
||||
comparisonFilterName: String,
|
||||
featuresStorages: List<FeaturesStorage>,
|
||||
dirs: GeneratorDirectories
|
||||
) : BasicFileReportGenerator(filterName, comparisonFilterName, featuresStorages, dirs) {
|
||||
|
||||
override fun textToInsert(session: Session): String = session.expectedText.lines().first()
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<idea-plugin>
|
||||
<extensions defaultExtensionNs="com.intellij.cce">
|
||||
<completionEvaluationVisitor implementation="com.intellij.cce.visitor.KotlinCompletionEvaluationVisitor"/>
|
||||
<completionEvaluationVisitor implementation="com.intellij.cce.visitor.KotlinMultiLineEvaluationVisitor"/>
|
||||
<completionGolfVisitorFactory implementation="com.intellij.cce.visitor.KotlinCompletionGolfVisitorFactory"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.psi.*
|
||||
class KotlinCompletionGolfVisitorFactory : CompletionGolfVisitorFactory {
|
||||
override val language: Language = Language.KOTLIN
|
||||
override fun createVisitor(featureName: String, mode: CompletionGolfMode): CompletionGolfEvaluationVisitor {
|
||||
if (featureName == "multi-line-completion") return KotlinMultiLineEvaluationVisitor()
|
||||
when (mode) {
|
||||
CompletionGolfMode.ALL -> return AllVisitor(featureName)
|
||||
CompletionGolfMode.TOKENS -> return TokensVisitor(featureName)
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.cce.visitor
|
||||
|
||||
import com.intellij.cce.core.CodeFragment
|
||||
import com.intellij.cce.core.CodeToken
|
||||
import com.intellij.cce.core.Language
|
||||
import com.intellij.cce.core.*
|
||||
import com.intellij.cce.visitor.exceptions.PsiConverterException
|
||||
import org.jetbrains.kotlin.psi.KtBlockExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
@@ -13,7 +11,7 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
|
||||
|
||||
class KotlinMultiLineEvaluationVisitor : CompletionGolfEvaluationVisitor, KtTreeVisitorVoid() {
|
||||
class KotlinMultiLineEvaluationVisitor : EvaluationVisitor, KtTreeVisitorVoid() {
|
||||
private var codeFragment: CodeFragment? = null
|
||||
|
||||
override val language: Language = Language.KOTLIN
|
||||
@@ -36,10 +34,12 @@ class KotlinMultiLineEvaluationVisitor : CompletionGolfEvaluationVisitor, KtTree
|
||||
val startOffset = body.children.first().startOffset
|
||||
val endOffset = body.children.last().endOffset
|
||||
val text = file.text.substring(startOffset, endOffset)
|
||||
file.addChild(CodeToken(text, startOffset))
|
||||
file.addChild(CodeToken(text, startOffset, METHOD_PROPERTIES))
|
||||
} else {
|
||||
file.addChild(CodeToken(body.text, body.textOffset))
|
||||
file.addChild(CodeToken(body.text, body.textOffset, METHOD_PROPERTIES))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val METHOD_PROPERTIES = SimpleTokenProperties.create(TypeProperty.METHOD, SymbolLocation.UNKNOWN) {}
|
||||
|
||||
Reference in New Issue
Block a user