generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
142 additions
and
14 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.gradle | ||
.idea | ||
build | ||
out |
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
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,23 @@ | ||
<idea-plugin> | ||
<id>ai.serenade.intellij</id> | ||
<name>Serenade</name> | ||
<vendor>Serenade</vendor> | ||
|
||
<!-- Product and plugin compatibility requirements --> | ||
<!-- https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html --> | ||
<depends>com.intellij.modules.platform</depends> | ||
<depends>com.intellij.modules.java</depends> | ||
|
||
<extensions defaultExtensionNs="com.intellij"> | ||
<applicationService serviceImplementation="ai.serenade.intellij.services.MyApplicationService"/> | ||
<projectService serviceImplementation="ai.serenade.intellij.services.MyProjectService"/> | ||
|
||
<toolWindow id="My Sample Tool Window" anchor="right" factoryClass="ai.serenade.intellij.MainToolWindow"/> | ||
</extensions> | ||
|
||
<projectListeners> | ||
<listener class="ai.serenade.intellij.listeners.MyProjectManagerListener" | ||
topic="com.intellij.openapi.wm.ex.ToolWindowManagerListener"/> | ||
</projectListeners> | ||
|
||
</idea-plugin> |
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 ai.serenade.intellij | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.wm.ToolWindow | ||
import com.intellij.openapi.wm.ToolWindowFactory | ||
import com.intellij.ui.content.Content | ||
import com.intellij.ui.content.ContentFactory | ||
import com.intellij.ui.layout.panel | ||
|
||
class MainToolWindow : ToolWindowFactory { | ||
override fun createToolWindowContent(p0: Project, p1: ToolWindow) { | ||
val contentFactory: ContentFactory = ContentFactory.SERVICE.getInstance() | ||
val content: Content = contentFactory.createContent(panel { | ||
noteRow("Welcome to Serenade!") | ||
noteRow("With Serenade, you can write code faster—by speaking in plain English, rather than typing. Use Serenade as your coding assistant, or abandon your keyboard entirely.") | ||
noteRow("To get started, download the Serenade app and run it alongside IntelliJ.") | ||
noteRow("<a class=\"serenade-download\" href=\"https://serenade.ai/\">Download</a>") | ||
}, "", false) | ||
p1.contentManager.addContent(content) | ||
} | ||
} |
88 changes: 83 additions & 5 deletions
88
src/main/kotlin/ai/serenade/intellij/listeners/MyProjectManagerListener.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 |
---|---|---|
@@ -1,12 +1,90 @@ | ||
package ai.serenade.intellij.listeners | ||
|
||
import ai.serenade.intellij.services.MyProjectService | ||
import com.google.gson.Gson | ||
import com.intellij.notification.NotificationDisplayType | ||
import com.intellij.notification.NotificationGroup | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.notification.Notifications | ||
import com.intellij.openapi.fileEditor.FileEditorManager | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.project.ProjectManagerListener | ||
import com.intellij.openapi.wm.ToolWindow | ||
import com.intellij.openapi.wm.ex.ToolWindowManagerListener | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.features.websocket.WebSockets | ||
import io.ktor.client.features.websocket.ws | ||
import io.ktor.http.HttpMethod | ||
import io.ktor.http.cio.websocket.Frame | ||
import io.ktor.http.cio.websocket.readText | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.channels.consumeEach | ||
import kotlinx.coroutines.launch | ||
|
||
internal class MyProjectManagerListener : ProjectManagerListener { | ||
data class Result( | ||
val source: String, | ||
val cursor: Int, | ||
val filename: String, | ||
val files: List<String>, | ||
var roots: List<String>, | ||
var tabs: List<String> | ||
) | ||
|
||
override fun projectOpened(project: Project) { | ||
project.getService(MyProjectService::class.java) | ||
data class Data( | ||
val app: String, | ||
val id: String | ||
) | ||
|
||
data class Message( | ||
val message: String, | ||
val data: Any | ||
) | ||
|
||
class MyProjectManagerListener(private val project: Project) : ToolWindowManagerListener { | ||
|
||
override fun toolWindowShown(id: String, toolWindow: ToolWindow) { | ||
val notificationGroup = NotificationGroup("Serenade", NotificationDisplayType.BALLOON, true) | ||
val gson = Gson(); | ||
val editor = FileEditorManager.getInstance(project).selectedTextEditor | ||
val document = editor?.document | ||
val source = document?.text ?: "" | ||
|
||
GlobalScope.launch { | ||
val client = HttpClient { | ||
install(WebSockets) | ||
} | ||
client.ws( | ||
method = HttpMethod.Get, | ||
host = "localhost", | ||
port = 17373, path = "/" | ||
) { | ||
// Send text frame. | ||
send(Frame.Text(gson.toJson( | ||
Message("heartbeat", Data( | ||
"/users/cheng/.gradle/caches/modules-2/files-2.1/com.jetbrains/jbre/jbr-11_0_7-osx-x64-b944.20/jbr/contents/home/bin/java", | ||
java.util.UUID.randomUUID().toString() | ||
)) | ||
))) | ||
|
||
// Receive frames | ||
incoming.consumeEach { frame -> | ||
if (frame is Frame.Text) { | ||
val notification = notificationGroup.createNotification( | ||
frame.readText(), NotificationType.INFORMATION | ||
) | ||
Notifications.Bus.notify(notification, project) | ||
|
||
send(Frame.Text(gson.toJson( | ||
Message("editorState", Result( | ||
source, | ||
0, | ||
"", | ||
emptyList(), | ||
emptyList(), | ||
emptyList() | ||
)) | ||
))) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
src/main/kotlin/ai/serenade/intellij/services/MyApplicationService.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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
package ai.serenade.intellij.services | ||
|
||
import ai.serenade.intellij.MyBundle | ||
|
||
class MyApplicationService { | ||
|
||
init { | ||
println(MyBundle.message("applicationService")) | ||
} | ||
} |
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