-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* idea plugin baseline * selection code send ok * selection code replace ready * clean when plugin upgrade * remove same not necessary
- Loading branch information
1 parent
612c76d
commit 4e665f7
Showing
28 changed files
with
578 additions
and
31 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/gpt-runner-intellij/.fastRequest/config/fastRequestCurrentProjectConfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"dataList":[], | ||
"envList":[], | ||
"headerList":[], | ||
"maxDescriptionLength":-1, | ||
"postScript":"", | ||
"preScript":"", | ||
"projectList":[], | ||
"syncModel":{ | ||
"branch":"master", | ||
"domain":"https://github.com", | ||
"enabled":false, | ||
"namingPolicy":"byDoc", | ||
"owner":"", | ||
"repo":"", | ||
"repoUrl":"", | ||
"syncAfterRun":false, | ||
"token":"", | ||
"type":"github" | ||
}, | ||
"urlEncodedKeyValueList":[], | ||
"urlParamsKeyValueList":[], | ||
"urlSuffix":"" | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/gpt-runner-intellij/.fastRequest/config/fastRequestCurrentProjectEnvironment.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"environment":{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!-- Keep a Changelog guide -> https://keepachangelog.com --> | ||
|
||
# Changelog | ||
|
||
## [Unreleased] | ||
|
||
## [0.0.1] - 2023-06-30 | ||
|
||
### Added | ||
- Initial project scaffold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/gpt-runner-intellij/src/main/kotlin/cn/nicepkg/gptrunner/intellij/LangBundle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cn.nicepkg.gptrunner.intellij | ||
|
||
import com.intellij.DynamicBundle | ||
import org.jetbrains.annotations.NonNls | ||
import org.jetbrains.annotations.PropertyKey | ||
|
||
@NonNls | ||
private const val BUNDLE = "messages.LangBundle" | ||
|
||
object LangBundle : DynamicBundle(BUNDLE) { | ||
|
||
@Suppress("SpreadOperator") | ||
@JvmStatic | ||
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = | ||
getMessage(key, *params) | ||
|
||
@Suppress("SpreadOperator", "unused") | ||
@JvmStatic | ||
fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = | ||
getLazyMessage(key, *params) | ||
} |
24 changes: 24 additions & 0 deletions
24
...runner-intellij/src/main/kotlin/cn/nicepkg/gptrunner/intellij/actions/OpenInEditorMode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cn.nicepkg.gptrunner.intellij.actions | ||
|
||
import com.intellij.openapi.actionSystem.ActionUpdateThread | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
|
||
// TODO: impl it | ||
class OpenInEditorMode : AnAction() { | ||
override fun actionPerformed(e: AnActionEvent) { | ||
if (e.project == null) return | ||
// val project = e.project!! | ||
// val gptRunnerService = project.service<IGPTRunnerService>() | ||
// project.projectFile | ||
} | ||
|
||
override fun update(e: AnActionEvent) { | ||
e.presentation.isEnabled = e.project != null | ||
super.update(e) | ||
} | ||
|
||
override fun getActionUpdateThread(): ActionUpdateThread { | ||
return ActionUpdateThread.EDT | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...unner-intellij/src/main/kotlin/cn/nicepkg/gptrunner/intellij/listeners/ClientEventName.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cn.nicepkg.gptrunner.intellij.listeners | ||
|
||
/** | ||
* 事件名称 | ||
*/ | ||
enum class ClientEventName(val value: String) { | ||
InitSuccess("initSuccess"), | ||
RefreshTree("refreshTree"), | ||
RefreshChatTree("refreshChatTree"), | ||
RefreshFileTree("refreshFileTree"), | ||
InsertCodes("insertCodes"), | ||
DiffCodes("diffCodes"), | ||
UpdateIdeOpeningFiles("updateIdeOpeningFiles"), | ||
UpdateIdeActiveFilePath("updateIdeActiveFilePath"), | ||
UpdateUserSelectedText("updateUserSelectedText"), | ||
OpenFileInIde("openFileInIde"), | ||
OpenFileInFileEditor("openFileInFileEditor"), | ||
GoToChatPanel("goToChatPanel") | ||
|
||
|
||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...tellij/src/main/kotlin/cn/nicepkg/gptrunner/intellij/listeners/EditorMouseListenerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cn.nicepkg.gptrunner.intellij.listeners | ||
|
||
import cn.nicepkg.gptrunner.intellij.listeners.publish.AppEventPublisher | ||
import com.intellij.openapi.editor.event.EditorMouseEvent | ||
import com.intellij.openapi.editor.event.EditorMouseListener | ||
import com.intellij.openapi.editor.impl.EditorImpl | ||
import java.util.regex.Pattern | ||
|
||
/** | ||
* monitor selected text | ||
*/ | ||
class EditorMouseListenerImpl : EditorMouseListener { | ||
|
||
override fun mouseReleased(event: EditorMouseEvent) { | ||
super.mouseReleased(event) | ||
val selectedText = event.editor.selectionModel.getSelectedText() | ||
val length = selectedText?.trim()?.length | ||
if (length != null && length > 0) { | ||
// Markdown format | ||
val editorImpl = event.editor as EditorImpl | ||
val fileExtension = getFileExtension(editorImpl.virtualFile.name) | ||
val fullPrompt = getFullPrompt(fileExtension, selectedText) | ||
|
||
// send | ||
AppEventPublisher.updateUserSelectedText(fullPrompt) | ||
} | ||
} | ||
|
||
|
||
private fun getFileExtension(filename: String): String { | ||
val pattern = Pattern.compile("[^.]+$") | ||
val matcher = pattern.matcher(filename) | ||
if (matcher.find()) { | ||
return matcher.group() | ||
} | ||
return "" | ||
} | ||
|
||
private fun getFullPrompt(fileExtension: String?, selectedText: String): String { | ||
return String.format("\n```%s\n%s\n```", fileExtension, selectedText) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...j/src/main/kotlin/cn/nicepkg/gptrunner/intellij/listeners/PluginInstallerStateListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cn.nicepkg.gptrunner.intellij.listeners | ||
|
||
import cn.nicepkg.gptrunner.intellij.services.IGPTRunnerExecutableService | ||
import com.intellij.ide.plugins.IdeaPluginDescriptor | ||
import com.intellij.ide.plugins.PluginStateListener | ||
import com.intellij.openapi.components.service | ||
|
||
class PluginInstallerStateListener : PluginStateListener { | ||
override fun install(descriptor: IdeaPluginDescriptor) { | ||
service<IGPTRunnerExecutableService>() | ||
} | ||
|
||
override fun uninstall(descriptor: IdeaPluginDescriptor) { | ||
super.uninstall(descriptor) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...-intellij/src/main/kotlin/cn/nicepkg/gptrunner/intellij/listeners/ProjectStateListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cn.nicepkg.gptrunner.intellij.listeners | ||
|
||
import cn.nicepkg.gptrunner.intellij.services.IGPTRunnerService | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.diagnostic.thisLogger | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.project.ProjectManagerListener | ||
import kotlinx.coroutines.runBlocking | ||
import kotlin.concurrent.thread | ||
|
||
class ProjectStateListener : ProjectManagerListener { | ||
override fun projectOpened(project: Project) { | ||
thisLogger().debug("project: ${project.name}") | ||
thisLogger().debug("project.isInitialized: ${project.isInitialized}") | ||
thisLogger().debug("project.isOpen: ${project.isOpen}") | ||
thread { | ||
runBlocking { | ||
project.service<IGPTRunnerService>().startNodeServer() | ||
} | ||
} | ||
super.projectOpened(project) | ||
} | ||
|
||
override fun projectClosed(project: Project) { | ||
runBlocking { project.service<IGPTRunnerService>().closeNodeServer() } | ||
super.projectClosed(project) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...rc/main/kotlin/cn/nicepkg/gptrunner/intellij/listeners/handler/BaseBrowserEventHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package cn.nicepkg.gptrunner.intellij.listeners.handler | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.ui.jcef.JBCefJSQuery | ||
|
||
abstract class BaseBrowserEventHandler<T>(val project: Project) : java.util.function.Function<T, JBCefJSQuery.Response> { | ||
|
||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...j/src/main/kotlin/cn/nicepkg/gptrunner/intellij/listeners/handler/BrowserEventHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cn.nicepkg.gptrunner.intellij.listeners.handler | ||
|
||
import cn.nicepkg.gptrunner.intellij.listeners.ClientEventName | ||
import com.google.gson.Gson | ||
import com.google.gson.JsonArray | ||
import com.google.gson.JsonElement | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.ui.jcef.JBCefJSQuery | ||
import java.util.* | ||
import kotlin.collections.HashMap | ||
|
||
/** | ||
* handle browser events | ||
*/ | ||
class BrowserEventHandlers(project: Project) : BaseBrowserEventHandler<String>(project) { | ||
|
||
private val handlers: HashMap<String, BaseBrowserEventHandler<JsonElement>> = HashMap() | ||
|
||
@Volatile | ||
var initFlag: Boolean = false | ||
|
||
override fun apply(t: String): JBCefJSQuery.Response { | ||
if (!initFlag) { | ||
synchronized(this) { | ||
if (!initFlag) { | ||
handlers[ClientEventName.InsertCodes.value] = CodeReplaceHandler(project) | ||
} | ||
initFlag = true | ||
} | ||
} | ||
|
||
val gson = Gson() | ||
val any = gson.fromJson(t, Any::class.java) | ||
if (any is JsonArray) { | ||
val eventName = any.get(0) | ||
if (handlers.contains(eventName.asString)){ | ||
return handlers.get(eventName.asString)!!.apply(any.get(1)) | ||
} | ||
} | ||
|
||
return JBCefJSQuery.Response("Done") | ||
} | ||
|
||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...lij/src/main/kotlin/cn/nicepkg/gptrunner/intellij/listeners/handler/CodeReplaceHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cn.nicepkg.gptrunner.intellij.listeners.handler | ||
|
||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonObject | ||
import com.intellij.openapi.fileEditor.FileEditorManager | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.ui.jcef.JBCefJSQuery | ||
|
||
/** | ||
* TODO 验证 | ||
* | ||
* @author shield | ||
*/ | ||
class CodeReplaceHandler(project: Project) : BaseBrowserEventHandler<JsonElement>(project) { | ||
|
||
override fun apply(t: JsonElement): JBCefJSQuery.Response { | ||
val editor = FileEditorManager.getInstance(project).getSelectedTextEditor() | ||
if (editor != null) { | ||
val selectionModel = editor.selectionModel | ||
|
||
if (t is JsonObject && t.has("codes")) { | ||
val content = t.get("codes").asString | ||
editor.document.replaceString(selectionModel.selectionStart, selectionModel.selectionEnd, content) | ||
} | ||
} | ||
|
||
return JBCefJSQuery.Response("Done") | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...nner-intellij/src/main/kotlin/cn/nicepkg/gptrunner/intellij/listeners/publish/AppEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package cn.nicepkg.gptrunner.intellij.listeners.publish | ||
|
||
import cn.nicepkg.gptrunner.intellij.listeners.ClientEventName | ||
import kotlinx.serialization.Serializable | ||
|
||
|
||
@Serializable | ||
class AppEvent(value: String?, eventData: Any?, type: String?) { | ||
|
||
private val eventName: String? = null | ||
private val type: String? = null | ||
private val eventData: Any? = null | ||
|
||
|
||
private var text: String? = null | ||
private val codes: String? = null | ||
|
||
companion object { | ||
fun of(eventName: ClientEventName, eventData: Any, type: String): AppEvent { | ||
return AppEvent(eventName.value, eventData, type) | ||
} | ||
|
||
fun of(text: String): AppEvent { | ||
val event = AppEvent() | ||
event.text = text | ||
return event | ||
} | ||
} | ||
|
||
constructor() : this(null, null, null) | ||
|
||
} |
Oops, something went wrong.