mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[full-line] ML-2900 Remove deprecated InlineContextFeatures.kt in favor of ML API
GitOrigin-RevId: 0f548a2af76335a524419d4e28084b7f66e0deba
This commit is contained in:
committed by
intellij-monorepo-bot
parent
df81c6f946
commit
382f7cbf72
-12
@@ -14,8 +14,6 @@ import com.intellij.openapi.diagnostic.thisLogger
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.util.PsiUtilCore
|
||||
import com.intellij.util.application
|
||||
import kotlin.system.measureNanoTime
|
||||
|
||||
/**
|
||||
* This tracker lives from the moment the inline completion is invoked until the end of generation.
|
||||
@@ -31,7 +29,6 @@ internal class InlineCompletionInvocationTracker(
|
||||
|
||||
private var finished = false
|
||||
private val data = mutableListOf<EventPair<*>>()
|
||||
private val contextFeatures = mutableListOf<EventPair<*>>()
|
||||
private var hasSuggestions: Boolean? = null
|
||||
private var canceled: Boolean = false
|
||||
private var exception: Boolean = false
|
||||
@@ -53,11 +50,6 @@ internal class InlineCompletionInvocationTracker(
|
||||
fileLanguage = psiFile.language
|
||||
data.add(EventFields.Language.with(language))
|
||||
data.add(EventFields.CurrentFile.with(fileLanguage))
|
||||
val computationTime = measureNanoTime {
|
||||
contextFeatures.addAll(InlineContextFeatures.capture(psiFile, editor, offset))
|
||||
request.putUserData(InlineContextFeatures.KEY, contextFeatures)
|
||||
}
|
||||
data.add(InvokedEvents.CONTEXT_FEATURES_COMPUTATION_TIME.with(computationTime))
|
||||
assert(!finished)
|
||||
}
|
||||
|
||||
@@ -98,10 +90,6 @@ internal class InlineCompletionInvocationTracker(
|
||||
data.add(InvokedEvents.ADDITIONAL.with(ObjectEventData(it)))
|
||||
}
|
||||
|
||||
if (contextFeatures.isNotEmpty()) {
|
||||
data.add(InvokedEvents.CONTEXT_FEATURES.with(ObjectEventData(contextFeatures)))
|
||||
}
|
||||
|
||||
InlineCompletionUsageTracker.INVOKED_EVENT.log(listOf(
|
||||
InvokedEvents.REQUEST_ID.with(requestId),
|
||||
*data.toTypedArray(),
|
||||
|
||||
-21
@@ -42,25 +42,6 @@ object InlineCompletionUsageTracker : CounterUsagesCollector() {
|
||||
}
|
||||
|
||||
val ADDITIONAL: ObjectEventField = createAdditionalDataField(GROUP.id, INVOKED_EVENT_ID)
|
||||
val CONTEXT_FEATURES = ObjectEventField(
|
||||
"context_features",
|
||||
InlineContextFeatures.LINE_NUMBER,
|
||||
InlineContextFeatures.COLUMN_NUMBER,
|
||||
InlineContextFeatures.SYMBOLS_IN_LINE_BEFORE_CARET,
|
||||
InlineContextFeatures.SYMBOLS_IN_LINE_AFTER_CARET,
|
||||
InlineContextFeatures.IS_WHITE_SPACE_BEFORE_CARET,
|
||||
InlineContextFeatures.IS_WHITE_SPACE_AFTER_CARET,
|
||||
InlineContextFeatures.NON_SPACE_SYMBOL_BEFORE_CARET,
|
||||
InlineContextFeatures.NON_SPACE_SYMBOL_AFTER_CARET,
|
||||
InlineContextFeatures.PREVIOUS_EMPTY_LINES_COUNT,
|
||||
InlineContextFeatures.PREVIOUS_NON_EMPTY_LINE_LENGTH,
|
||||
InlineContextFeatures.FOLLOWING_EMPTY_LINES_COUNT,
|
||||
InlineContextFeatures.FOLLOWING_NON_EMPTY_LINE_LENGTH,
|
||||
InlineContextFeatures.TIME_SINCE_LAST_TYPING,
|
||||
*InlineContextFeatures.PARENT_FEATURES,
|
||||
*TypingSpeedTracker.getEventFields(),
|
||||
)
|
||||
val CONTEXT_FEATURES_COMPUTATION_TIME = EventFields.Long("context_features_computation_time")
|
||||
}
|
||||
|
||||
internal val INVOKED_EVENT: VarargEventId = GROUP.registerVarargEvent(
|
||||
@@ -73,8 +54,6 @@ object InlineCompletionUsageTracker : CounterUsagesCollector() {
|
||||
InvokedEvents.TIME_TO_COMPUTE,
|
||||
InvokedEvents.OUTCOME,
|
||||
InvokedEvents.ADDITIONAL,
|
||||
InvokedEvents.CONTEXT_FEATURES,
|
||||
InvokedEvents.CONTEXT_FEATURES_COMPUTATION_TIME,
|
||||
)
|
||||
|
||||
@ApiStatus.Internal
|
||||
|
||||
-139
@@ -1,139 +0,0 @@
|
||||
// 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.codeInsight.inline.completion.logs
|
||||
|
||||
import com.intellij.internal.statistic.eventLog.events.EventFields
|
||||
import com.intellij.internal.statistic.eventLog.events.EventPair
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.util.parents
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
@ApiStatus.Internal
|
||||
@Deprecated(
|
||||
"""
|
||||
Old format for ML model and analytical features.
|
||||
Please make sure the feature you have added is also present in
|
||||
org.jetbrains.completion.full.line.mlApi.description.ContextFeatures
|
||||
""",
|
||||
replaceWith = ReplaceWith("org.jetbrains.completion.full.line.platform.mlApi.description.ContextFeatures")
|
||||
)
|
||||
object InlineContextFeatures {
|
||||
|
||||
fun capture(psiFile: PsiFile, editor: Editor, offset: Int): List<EventPair<*>> {
|
||||
val contextFeatures = mutableListOf<EventPair<*>>()
|
||||
try {
|
||||
doCapture(psiFile, editor, offset, contextFeatures)
|
||||
}
|
||||
catch (e: Exception) {
|
||||
LOG.error(e)
|
||||
}
|
||||
return contextFeatures
|
||||
}
|
||||
|
||||
private fun doCapture(psiFile: PsiFile, editor: Editor, offset: Int, contextFeatures: MutableList<EventPair<*>>) {
|
||||
val logicalPosition = editor.offsetToLogicalPosition(offset)
|
||||
val lineNumber = logicalPosition.line
|
||||
val columnNumber = logicalPosition.column
|
||||
|
||||
contextFeatures.add(LINE_NUMBER.with(lineNumber))
|
||||
contextFeatures.add(COLUMN_NUMBER.with(columnNumber))
|
||||
|
||||
val lineStartOffset = editor.document.getLineStartOffset(lineNumber)
|
||||
val lineEndOffset = editor.document.getLineEndOffset(lineNumber)
|
||||
|
||||
val linePrefix = editor.document.getText(TextRange(lineStartOffset, offset))
|
||||
val lineSuffix = editor.document.getText(TextRange(offset, lineEndOffset))
|
||||
|
||||
if (linePrefix.isNotBlank()) {
|
||||
contextFeatures.add(IS_WHITE_SPACE_BEFORE_CARET.with(linePrefix.last().isWhitespace()))
|
||||
val trimmedPrefix = linePrefix.trim()
|
||||
contextFeatures.add(SYMBOLS_IN_LINE_BEFORE_CARET.with(trimmedPrefix.length))
|
||||
CharCategory.find(trimmedPrefix.last())?.let {
|
||||
contextFeatures.add(NON_SPACE_SYMBOL_BEFORE_CARET.with(it))
|
||||
}
|
||||
}
|
||||
if (lineSuffix.isNotBlank()) {
|
||||
contextFeatures.add(IS_WHITE_SPACE_AFTER_CARET.with(lineSuffix.first().isWhitespace()))
|
||||
val trimmedSuffix = lineSuffix.trim()
|
||||
contextFeatures.add(SYMBOLS_IN_LINE_AFTER_CARET.with(trimmedSuffix.length))
|
||||
CharCategory.find(trimmedSuffix.last())?.let {
|
||||
contextFeatures.add(NON_SPACE_SYMBOL_AFTER_CARET.with(it))
|
||||
}
|
||||
}
|
||||
val document = editor.document
|
||||
val (previousNonEmptyLineNumber, previousNonEmptyLineText) = document.findNonBlankLine(lineNumber, false)
|
||||
contextFeatures.add(PREVIOUS_EMPTY_LINES_COUNT.with(lineNumber - previousNonEmptyLineNumber - 1))
|
||||
if (previousNonEmptyLineText != null) {
|
||||
contextFeatures.add(PREVIOUS_NON_EMPTY_LINE_LENGTH.with(previousNonEmptyLineText.length))
|
||||
}
|
||||
val (followingNonEmptyLineNumber, followingNonEmptyLineText) = document.findNonBlankLine(lineNumber, true)
|
||||
contextFeatures.add(FOLLOWING_EMPTY_LINES_COUNT.with(followingNonEmptyLineNumber - lineNumber - 1))
|
||||
if (followingNonEmptyLineText != null) {
|
||||
contextFeatures.add(FOLLOWING_NON_EMPTY_LINE_LENGTH.with(followingNonEmptyLineText.length))
|
||||
}
|
||||
|
||||
psiFile.findElementAt(offset - 1)?.let { contextFeatures.addPsiParents(it) }
|
||||
contextFeatures.addTypingFeatures()
|
||||
}
|
||||
|
||||
private fun Document.findNonBlankLine(lineNumber: Int, following: Boolean): Pair<Int, String?> {
|
||||
val delta = if (following) 1 else -1
|
||||
var n = lineNumber
|
||||
var text: String? = null
|
||||
while (n in 0..<lineCount && text == null) {
|
||||
n += delta
|
||||
text = getNonBlankLineOrNull(n)
|
||||
}
|
||||
return n to text
|
||||
}
|
||||
|
||||
private fun Document.getNonBlankLineOrNull(line: Int): String? {
|
||||
if (line !in 0..<lineCount) return null
|
||||
val res = getText(TextRange(getLineStartOffset(line), getLineEndOffset(line)))
|
||||
return res.trim().ifEmpty { null }
|
||||
}
|
||||
|
||||
private fun MutableList<EventPair<*>>.addPsiParents(element: PsiElement) {
|
||||
element.parents(false)
|
||||
.take(PARENT_FEATURES.size)
|
||||
.withIndex()
|
||||
.forEach { (i, element) -> add(PARENT_FEATURES[i].with(element.javaClass)) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure you have updated [com.intellij.codeInsight.inline.completion.ml.TypingFeatures], when added new features here
|
||||
*/
|
||||
@Deprecated("Obsolete way to compute typing features, the new ml api should do that")
|
||||
private fun MutableList<EventPair<*>>.addTypingFeatures() {
|
||||
val typingSpeedTracker = TypingSpeedTracker.getInstance()
|
||||
val timeSinceLastTyping = typingSpeedTracker.getTimeSinceLastTyping()
|
||||
if (timeSinceLastTyping != null) {
|
||||
add(TIME_SINCE_LAST_TYPING.with(timeSinceLastTyping))
|
||||
addAll(typingSpeedTracker.getTypingSpeedEventPairs().map { it.first })
|
||||
}
|
||||
}
|
||||
|
||||
val KEY: Key<List<EventPair<*>>> = Key.create("inline_context_features")
|
||||
private val LOG = logger<InlineContextFeatures>()
|
||||
|
||||
val LINE_NUMBER = EventFields.Int("line_number")
|
||||
val COLUMN_NUMBER = EventFields.Int("column_number")
|
||||
val SYMBOLS_IN_LINE_BEFORE_CARET = EventFields.Int("symbols_in_line_before_caret")
|
||||
val SYMBOLS_IN_LINE_AFTER_CARET = EventFields.Int("symbols_in_line_after_caret")
|
||||
val IS_WHITE_SPACE_BEFORE_CARET = EventFields.Boolean("is_white_space_before_caret")
|
||||
val IS_WHITE_SPACE_AFTER_CARET = EventFields.Boolean("is_white_space_after_caret")
|
||||
val NON_SPACE_SYMBOL_BEFORE_CARET = EventFields.Enum("non_space_symbol_before_caret", CharCategory::class.java)
|
||||
val NON_SPACE_SYMBOL_AFTER_CARET = EventFields.Enum("non_space_symbol_after_caret", CharCategory::class.java)
|
||||
val PREVIOUS_EMPTY_LINES_COUNT = EventFields.Int("previous_empty_lines_count")
|
||||
val PREVIOUS_NON_EMPTY_LINE_LENGTH = EventFields.Int("previous_non_empty_line_length")
|
||||
val FOLLOWING_EMPTY_LINES_COUNT = EventFields.Int("following_empty_lines_count")
|
||||
val FOLLOWING_NON_EMPTY_LINE_LENGTH = EventFields.Int("following_non_empty_line_length")
|
||||
val TIME_SINCE_LAST_TYPING = EventFields.Long("time_since_last_typing")
|
||||
|
||||
val PARENT_FEATURES = listOf("first", "second", "third", "forth", "fifth").map { EventFields.Class("${it}_parent") }.toTypedArray()
|
||||
}
|
||||
Reference in New Issue
Block a user