Skip to content

Commit 9e13ec6

Browse files
committed
refactor: Fix plugin version retrieval and element range calculation
- Replace PluginManagerCore with PluginManager for version retrieval - Fix element range calculation using textRange property - Make editor retrieval null-safe in TriggerCompletion action
1 parent 4ced38d commit 9e13ec6

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/main/kotlin/ai/devchat/plugin/IDEServer.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerEx
99
import com.intellij.codeInsight.daemon.impl.HighlightInfo
1010
import com.intellij.codeInsight.intention.IntentionAction
1111
import com.intellij.codeInsight.navigation.actions.GotoTypeDeclarationAction
12+
import com.intellij.ide.plugins.PluginManager
1213
import com.intellij.lang.Language
1314
import com.intellij.lang.annotation.HighlightSeverity.INFORMATION
1415
import com.intellij.openapi.Disposable
@@ -30,6 +31,8 @@ import com.intellij.openapi.vfs.VirtualFile
3031
import com.intellij.psi.*
3132
import com.intellij.psi.search.searches.ReferencesSearch
3233
import com.intellij.psi.util.PsiTreeUtil
34+
import com.intellij.psi.PsiElement
35+
import com.intellij.psi.PsiDocumentManager
3336
import com.intellij.refactoring.suggested.endOffset
3437
import com.intellij.refactoring.suggested.startOffset
3538
import io.ktor.http.*
@@ -49,7 +52,6 @@ import java.awt.Point
4952
import java.io.File
5053
import java.net.ServerSocket
5154
import kotlin.reflect.full.memberFunctions
52-
import com.intellij.ide.plugins.PluginManagerCore
5355

5456

5557
@Serializable
@@ -101,7 +103,7 @@ class IDEServer(private var project: Project): Disposable {
101103
routing {
102104
post("/get_extension_version") {
103105
val currentPlugin = try {
104-
PluginManagerCore.getLoadedPlugins().find { plugin ->
106+
PluginManager.getPlugins().find { plugin ->
105107
plugin.pluginClassLoader == IDEServer::class.java.classLoader
106108
}
107109
} catch (e: Exception) {
@@ -548,7 +550,7 @@ fun PsiElement.getRange(): Range? {
548550
}
549551

550552
return try {
551-
Range(calculatePosition(this.startOffset), calculatePosition(this.endOffset))
553+
Range(calculatePosition(this.textRange.startOffset), calculatePosition(this.textRange.endOffset))
552554
} catch (e: Exception) {
553555
Log.warn(e.toString())
554556
null

src/main/kotlin/ai/devchat/plugin/completion/actions/TriggerCompletion.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import com.intellij.openapi.components.service
1313
class TriggerCompletion : AnAction() {
1414
override fun actionPerformed(e: AnActionEvent) {
1515
val completionScheduler = service<CompletionProvider>()
16-
val editor = e.getRequiredData(CommonDataKeys.EDITOR)
16+
val editor = e.getData(CommonDataKeys.EDITOR) ?: return
1717
val offset = editor.caretModel.primaryCaret.offset
1818
completionScheduler.provideCompletion(editor, offset, manually = true)
1919
}

0 commit comments

Comments
 (0)