Skip to content

Commit

Permalink
Migrate to platform version 223
Browse files Browse the repository at this point in the history
  • Loading branch information
dpomianbuff committed Dec 23, 2023
1 parent 4fb9104 commit f477be9
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 217 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
pluginGroup=com.intellij.ml.llm.template
pluginName=LLM Extract Function
pluginRepositoryUrl=https://github.com/JetBrains/intellij-platform-plugin-template
pluginVersion=0.6.0
pluginVersion=0.7.0

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 231
pluginUntilBuild = 233.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
platformVersion = 2023.1
platformVersion = 2023.3

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.intellij.ml.llm.template.customextractors

data class FunctionName(val name: String)
class FunctionNameProvider(private val functionName: String) {
fun getFunctionName(): FunctionName {
return FunctionName(functionName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.intellij.ml.llm.template.customextractors

import com.intellij.codeInsight.template.impl.TemplateManagerImpl
import com.intellij.java.refactoring.JavaRefactoringBundle
import com.intellij.ml.llm.template.models.FunctionNameProvider
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.command.impl.FinishMarkAction
import com.intellij.openapi.command.impl.StartMarkAction
Expand Down Expand Up @@ -56,7 +55,7 @@ class MyInplaceExtractionHelper(private val allContainersEnabled: Boolean, priva
val commonParent = descriptor.extractionData.commonParent
val container = commonParent.takeIf { commonParent != elements.firstOrNull() } ?: commonParent.parent
val callRangeProvider: () -> TextRange? = createSmartRangeProvider(container, callTextRange)
val editorState = EditorState(editor)
val editorState = EditorState(project, editor)
val disposable = Disposer.newDisposable()
WriteCommandAction.writeCommandAction(project).run<Throwable> {
val startMarkAction = StartMarkAction.start(editor, project, EXTRACT_FUNCTION)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ import com.intellij.util.io.createDirectories
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import okio.Path.Companion.toPath

class TelemetryDataObserver : Observer {
companion object {
private const val LOG_DIR_NAME = "ef_plugin_logs"
private const val LOG_FILE_NAME = "ef_telemetry_data.log"
}

private val logFile = PathManager.getLogPath().toNioPath()
private val logFile = PathManager.getLogPath().toPath()
.resolve(LOG_DIR_NAME)
.resolve(LOG_FILE_NAME).toFile()

init {
runBlocking {
withContext(Dispatchers.IO) {
if (!logFile.exists()) {
logFile.parent.toNioPath().createDirectories()
logFile.parentFile.mkdirs()
logFile.createNewFile()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.intellij.lang.java.JavaLanguage
import com.intellij.ml.llm.template.LLMBundle
import com.intellij.ml.llm.template.extractfunction.EFCandidate
import com.intellij.ml.llm.template.extractfunction.MethodExtractionType
import com.intellij.ml.llm.template.models.FunctionNameProvider
import com.intellij.ml.llm.template.models.MyMethodExtractor
import com.intellij.ml.llm.template.customextractors.FunctionNameProvider
import com.intellij.ml.llm.template.customextractors.MyMethodExtractor
import com.intellij.ml.llm.template.telemetry.EFTelemetryDataElapsedTimeNotificationPayload
import com.intellij.ml.llm.template.telemetry.EFTelemetryDataManager
import com.intellij.ml.llm.template.telemetry.EFTelemetryDataUtils
Expand Down Expand Up @@ -52,13 +52,13 @@ import javax.swing.table.DefaultTableModel


class ExtractFunctionPanel(
project: Project,
editor: Editor,
file: PsiFile,
candidates: List<EFCandidate>,
codeTransformer: CodeTransformer,
highlighter: AtomicReference<ScopeHighlighter>,
efTelemetryDataManager: EFTelemetryDataManager? = null
project: Project,
editor: Editor,
file: PsiFile,
candidates: List<EFCandidate>,
codeTransformer: CodeTransformer,
highlighter: AtomicReference<ScopeHighlighter>,
efTelemetryDataManager: EFTelemetryDataManager? = null
) : Observable() {
val myExtractFunctionsCandidateTable: JBTable
private val myExtractFunctionsScrollPane: JBScrollPane
Expand Down Expand Up @@ -93,8 +93,8 @@ class ExtractFunctionPanel(
}

private fun buildExtractFunctionCandidateTable(
tableModel: DefaultTableModel,
candidateSignatureMap: Map<EFCandidate, String>
tableModel: DefaultTableModel,
candidateSignatureMap: Map<EFCandidate, String>
): JBTable {
val extractFunctionCandidateTable = object : JBTable(tableModel) {
override fun processKeyBinding(ks: KeyStroke, e: KeyEvent, condition: Int, pressed: Boolean): Boolean {
Expand Down Expand Up @@ -185,7 +185,7 @@ class ExtractFunctionPanel(

private fun buildMethodSignaturePreview(): MethodSignatureComponent {
val methodSignaturePreview =
MethodSignatureComponent("", myProject, com.intellij.ide.highlighter.JavaFileType.INSTANCE)
MethodSignatureComponent("", myProject, com.intellij.ide.highlighter.JavaFileType.INSTANCE)
methodSignaturePreview.isFocusable = false
methodSignaturePreview.minimumSize = Dimension(500, 120)
methodSignaturePreview.preferredSize = Dimension(500, 150)
Expand All @@ -202,18 +202,18 @@ class ExtractFunctionPanel(

row {
cell(myMethodSignaturePreview)
.align(AlignX.FILL)
.applyToComponent { minimumSize = JBDimension(100, 120) }
.align(AlignX.FILL)
.applyToComponent { minimumSize = JBDimension(100, 120) }
}

row {
button(LLMBundle.message("ef.candidates.popup.extract.function.button.title"), actionListener = {
doExtractMethod(myExtractFunctionsCandidateTable.selectedRow)
}).comment(
LLMBundle.message(
"ef.candidates.popup.invoke.extract.function",
KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction("ExtractMethod"))
)
LLMBundle.message(
"ef.candidates.popup.invoke.extract.function",
KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction("ExtractMethod"))
)
)
button("Exit", actionListener = {
myPopup?.cancel()
Expand Down Expand Up @@ -243,8 +243,8 @@ class ExtractFunctionPanel(
// Add the parameters
builder.append("(")
psiMethod.parameterList.parameters.joinTo(
buffer = builder,
separator = ", \n\t"
buffer = builder,
separator = ", \n\t"
) { "${it.type.presentableText} ${it.name}" }
builder.append(")")

Expand All @@ -260,10 +260,11 @@ class ExtractFunctionPanel(
when (myFile.language) {
JavaLanguage.INSTANCE ->
MyMethodExtractor(FunctionNameProvider(efCandidate.functionName)).findAndSelectExtractOption(
myEditor,
myFile,
TextRange(efCandidate.offsetStart, efCandidate.offsetEnd),
MethodExtractionType.PARENT_CLASS
myProject,
myEditor,
myFile,
TextRange(efCandidate.offsetStart, efCandidate.offsetEnd),
MethodExtractionType.PARENT_CLASS
)?.thenApply { options ->
val elementsToReplace = MethodExtractor().prepareRefactoringElements(options)
elementsToReplace.method.setName(efCandidate.functionName)
Expand All @@ -272,23 +273,23 @@ class ExtractFunctionPanel(

KotlinLanguage.INSTANCE -> {
fun computeKotlinFunctionSignature(
functionName: String,
file: KtFile,
elements: List<PsiElement>,
targetSibling: PsiElement
functionName: String,
file: KtFile,
elements: List<PsiElement>,
targetSibling: PsiElement
): @Nls String {
var kotlinSignature = LLMBundle.message("ef.candidates.popup.cannot.compute.function.signature")
val extractionData = ExtractionData(file, elements.toRange(false), targetSibling)
try {
val analysisResult = extractionData.performAnalysis()
if (analysisResult.status == AnalysisResult.Status.SUCCESS) {
val config = ExtractionGeneratorConfiguration(
analysisResult.descriptor!!,
ExtractionGeneratorOptions(
inTempFile = true,
target = ExtractionTarget.FUNCTION,
dummyName = functionName,
)
analysisResult.descriptor!!,
ExtractionGeneratorOptions(
inTempFile = true,
target = ExtractionTarget.FUNCTION,
dummyName = functionName,
)
)
kotlinSignature = config.getDeclarationPattern().replace(Regex("[\\w.]+${efCandidate.functionName}"), efCandidate.functionName)
val regex = Regex("\\b(\\w+)(?:\\.\\w+)+\\b")
Expand All @@ -311,10 +312,10 @@ class ExtractFunctionPanel(
val targetSibling = PsiUtils.getParentFunctionOrNull(elements[0], myFile.language)
if (targetSibling != null) {
signature = computeKotlinFunctionSignature(
efCandidate.functionName,
myFile as KtFile,
elements,
targetSibling
efCandidate.functionName,
myFile as KtFile,
elements,
targetSibling
)
}
}
Expand All @@ -338,12 +339,12 @@ class ExtractFunctionPanel(
val efCandidate = myCandidates[index]
val hostFunctionTelemetryData = myEFTelemetryDataManager?.getData()?.hostFunctionTelemetryData
myEFTelemetryDataManager?.addUserSelectionTelemetryData(
EFTelemetryDataUtils.buildUserSelectionTelemetryData(
efCandidate,
index,
hostFunctionTelemetryData,
myFile
)
EFTelemetryDataUtils.buildUserSelectionTelemetryData(
efCandidate,
index,
hostFunctionTelemetryData,
myFile
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.intellij.ml.llm.template.LLMBundle
import com.intellij.ml.llm.template.customextractors.MyInplaceExtractionHelper
import com.intellij.ml.llm.template.extractfunction.EFCandidate
import com.intellij.ml.llm.template.extractfunction.MethodExtractionType
import com.intellij.ml.llm.template.models.FunctionNameProvider
import com.intellij.ml.llm.template.models.MyMethodExtractor
import com.intellij.ml.llm.template.customextractors.FunctionNameProvider
import com.intellij.ml.llm.template.customextractors.MyMethodExtractor
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.EditorEx
Expand Down

0 comments on commit f477be9

Please sign in to comment.