Skip to content

Commit

Permalink
ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
ummcheng committed Aug 11, 2020
1 parent 55ca3f4 commit 3f23896
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 78 deletions.
29 changes: 10 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,19 @@
- [ ] Click the <kbd>Watch</kbd> button on the top of the [IntelliJ Platform Plugin Template][template] to be notified about releases containing new features and fixes.

<!-- Plugin description -->
This Fancy IntelliJ Platform Plugin is going to be your implementation of the brilliant ideas that you have.

This specific section is a source for the [plugin.xml](/src/main/resources/META-INF/plugin.xml) file which will be
extracted by the [Gradle](/build.gradle.kts) during the build process.

To keep everything working, do not remove `<!-- ... -->` sections.
<!-- Plugin description end -->

## Installation

- Using IDE built-in plugin system:

<kbd>Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>Marketplace</kbd> > <kbd>Search for "intellij"</kbd> >
<kbd>Install Plugin</kbd>

- Manually:

Download the [latest release](https://github.com/serenadeai/intellij/releases/latest) and install it manually using
<kbd>Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>⚙️</kbd> > <kbd>Install plugin from disk...</kbd>
## Prerequisites

1. IntelliJ IDEA 2020.2 (latest)
1.
```
brew install ktlint
ktlint installGitPreCommitHook
```
---
Plugin based on the [IntelliJ Platform Plugin Template][template].
## Development
[template]: https://github.com/JetBrains/intellij-platform-plugin-template
1. In IntelliJ IDEA, add the Plugin SDK: https://jetbrains.org/intellij/sdk/docs/basics/getting_started/setting_up_environment.html
1. `ktlint -F "**/*.kt*"` should find and fix any lint issues.
25 changes: 17 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ intellij {
detekt {
config = files("./detekt-config.yml")
buildUponDefaultConfig = true
ignoreFailures = true

reports {
html.enabled = false
Expand All @@ -76,6 +77,10 @@ detekt {
}
}

ktlint {
disabledRules.set(setOf("import-ordering"))
}

tasks {
// Set the compatibility versions to 1.8
withType<JavaCompile> {
Expand All @@ -98,16 +103,20 @@ tasks {
untilBuild(pluginUntilBuild)

// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
pluginDescription(closure {
File("./README.md").readText().lines().run {
subList(indexOf("<!-- Plugin description -->") + 1, indexOf("<!-- Plugin description end -->"))
}.joinToString("\n").run { markdownToHTML(this) }
})
pluginDescription(
closure {
File("./README.md").readText().lines().run {
subList(indexOf("<!-- Plugin description -->") + 1, indexOf("<!-- Plugin description end -->"))
}.joinToString("\n").run { markdownToHTML(this) }
}
)

// Get the latest available change notes from the changelog file
changeNotes(closure {
changelog.getLatest().toHTML()
})
changeNotes(
closure {
changelog.getLatest().toHTML()
}
)
}

publishPlugin {
Expand Down
6 changes: 1 addition & 5 deletions detekt-config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Default detekt configuration:
# https://github.com/detekt/detekt/blob/master/detekt-core/src/main/resources/default-detekt-config.yml
build:
maxIssues: 100

formatting:
Indentation:
active: true
maxIssues: 2
19 changes: 12 additions & 7 deletions src/main/kotlin/ai/serenade/intellij/MainToolWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ 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&mdash;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)
val content: Content = contentFactory.createContent(
panel {
noteRow("Welcome to Serenade!")
noteRow(
"With Serenade, you can write code faster&mdash;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)
}
}
49 changes: 28 additions & 21 deletions src/main/kotlin/ai/serenade/intellij/services/CommandHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import kotlinx.serialization.json.JsonConfiguration
class CommandHandler(private val project: Project) {
private val notifier = Notifier(project)

private val json = Json(JsonConfiguration.Default.copy(
encodeDefaults = false, // don't include all the null values
ignoreUnknownKeys = true, // don't break on parsing unknown responses
isLenient = true // empty strings
))
private val json = Json(
JsonConfiguration.Default.copy(
encodeDefaults = false, // don't include all the null values
ignoreUnknownKeys = true, // don't break on parsing unknown responses
isLenient = true // empty strings
)
)

fun closeTab() {
val read: () -> Unit = read@{
Expand Down Expand Up @@ -62,24 +64,29 @@ class CommandHandler(private val project: Project) {
val roots: List<String> = listOf(project.basePath ?: "")
val tabs: List<String> = manager.currentWindow.files.map { it.name }

val frame = Frame.Text(json.stringify(
Response.serializer(),
Response("callback", ResponseData(
null, null,
callback,
CallbackData(
"editorState",
NestedData(
source,
cursor,
filename,
files,
roots,
tabs
val frame = Frame.Text(
json.stringify(
Response.serializer(),
Response(
"callback",
ResponseData(
null, null,
callback,
CallbackData(
"editorState",
NestedData(
source,
cursor,
filename,
files,
roots,
tabs
)
)
)
)
))
))
)
)

GlobalScope.launch {
webSocketSession.send(frame)
Expand Down
36 changes: 21 additions & 15 deletions src/main/kotlin/ai/serenade/intellij/services/IpcService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import io.ktor.client.features.websocket.ws
import io.ktor.http.cio.websocket.Frame
import io.ktor.http.cio.websocket.readText
import io.ktor.util.KtorExperimentalAPI
import java.net.ConnectException
import java.util.UUID
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.consumeEach
import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import java.net.ConnectException
import java.util.UUID

@ExperimentalCoroutinesApi
@kotlinx.serialization.UnstableDefault
Expand All @@ -31,11 +31,13 @@ class IpcService(private val project: Project) {
}
private var webSocketSession: DefaultClientWebSocketSession? = null

private val json = Json(JsonConfiguration.Default.copy(
encodeDefaults = false, // don't include all the null values
ignoreUnknownKeys = true, // don't break on parsing unknown responses
isLenient = true // empty strings
))
private val json = Json(
JsonConfiguration.Default.copy(
encodeDefaults = false, // don't include all the null values
ignoreUnknownKeys = true, // don't break on parsing unknown responses
isLenient = true // empty strings
)
)

fun start() {
notifier.notify("id: $project.name")
Expand All @@ -60,16 +62,20 @@ class IpcService(private val project: Project) {
webSocketSession = this

// Send text frame of heartbeat
send(Frame.Text(json.stringify(
Response.serializer(),
Response(
"heartbeat",
ResponseData(
appName,
UUID.randomUUID().toString()
send(
Frame.Text(
json.stringify(
Response.serializer(),
Response(
"heartbeat",
ResponseData(
appName,
UUID.randomUUID().toString()
)
)
)
)
)))
)

notifier.notify("Connected")

Expand Down
4 changes: 1 addition & 3 deletions src/main/resources/messages/MyBundle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
name=My Plugin
applicationService=Application service
projectService=Project service: {0}
name=Serenade

0 comments on commit 3f23896

Please sign in to comment.