Skip to content

Commit

Permalink
feat: initial support for the Pact Language Server (LSP) (#26)
Browse files Browse the repository at this point in the history
* feat(ide): add a Pact file template

Signed-off-by: Luke Gareth Ribchester <luke@luke.gr>

* feat(lsp): handle path configuration changes

Signed-off-by: Luke Gareth Ribchester <luke@luke.gr>

* docs(changelog): add entry

Signed-off-by: Luke Gareth Ribchester <luke@luke.gr>

* 0.1.0

Signed-off-by: Luke Gareth Ribchester <luke@luke.gr>

---------

Signed-off-by: Luke Gareth Ribchester <luke@luke.gr>
  • Loading branch information
lukeribchester authored Jan 22, 2024
1 parent 3c60a5c commit 00bfd50
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

## [Unreleased]
### Added
- Initial scaffold created from [IntelliJ Platform Plugin Template](https://github.com/JetBrains/intellij-platform-plugin-template)
- Initial support for the [Pact Language Server (LSP)](https://github.com/kadena-io/pact-lsp)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = io.kadena.pact
pluginName = Pact
pluginRepositoryUrl = https://github.com/lukeribchester/pact-intellij
# SemVer format -> https://semver.org
pluginVersion = 0.0.7-alpha
pluginVersion = 0.1.0

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 232
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal class AppSettingsConfigurable : Configurable {
val settings: AppSettingsState = AppSettingsState.instance
settings.pactPath = appSettingsComponent?.pactPath.toString()
settings.pactLanguageServerPath = appSettingsComponent?.pactLanguageServerPath.toString()
settings.notifyAppSettingsStateChanged(settings)
}

override fun reset() {
Expand Down
18 changes: 17 additions & 1 deletion src/main/kotlin/io/kadena/pact/ide/settings/AppSettingsState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import org.jetbrains.annotations.Nullable
name = "io.kadena.pact.ide.settings.AppSettingsState",
storages = [Storage("PactPlugin.xml")]
)
internal class AppSettingsState : PersistentStateComponent<AppSettingsState> {
class AppSettingsState : PersistentStateComponent<AppSettingsState> {
var pactPath: String = ""
var pactLanguageServerPath: String = ""

private val listeners = mutableSetOf<AppSettingsStateListener>()

@Nullable
override fun getState(): AppSettingsState {
return this
Expand All @@ -35,4 +37,18 @@ internal class AppSettingsState : PersistentStateComponent<AppSettingsState> {
val instance: AppSettingsState
get() = ApplicationManager.getApplication().getService(AppSettingsState::class.java)
}

fun addAppSettingsStateListener(listener: AppSettingsStateListener) {
listeners.add(listener)
}

fun notifyAppSettingsStateChanged(state: AppSettingsState) {
for (listener in listeners) {
listener.onAppSettingsStateChanged(state)
}
}

interface AppSettingsStateListener {
fun onAppSettingsStateChanged(state: AppSettingsState)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,38 @@ package io.kadena.pact.lsp

import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.platform.lsp.api.LspServerManager
import com.intellij.platform.lsp.api.LspServerSupportProvider
import io.kadena.pact.ide.settings.AppSettingsState

class PactLspServerSupportProvider : LspServerSupportProvider, AppSettingsState.AppSettingsStateListener {

Check warning on line 9 in src/main/kotlin/io/kadena/pact/lsp/PactLspServerSupportProvider.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.intellij.platform.lsp.api.LspServerSupportProvider' is marked unstable with @ApiStatus.Experimental

private var _project: Project? = null

init {
val settings = AppSettingsState.instance
settings.addAppSettingsStateListener(this)
}

class PactLspServerSupportProvider : LspServerSupportProvider {
override fun fileOpened(

Check warning on line 18 in src/main/kotlin/io/kadena/pact/lsp/PactLspServerSupportProvider.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

Overridden method 'fileOpened(com.intellij.openapi.project.Project, com.intellij.openapi.vfs.VirtualFile, com.intellij.platform.lsp.api.LspServerSupportProvider.LspServerStarter)' is declared in unstable 'com.intellij.platform.lsp.api.LspServerSupportProvider' marked with @ApiStatus.Experimental
project: Project,
file: VirtualFile,
serverStarter: LspServerSupportProvider.LspServerStarter

Check warning on line 21 in src/main/kotlin/io/kadena/pact/lsp/PactLspServerSupportProvider.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.intellij.platform.lsp.api.LspServerSupportProvider' is marked unstable with @ApiStatus.Experimental

Check warning on line 21 in src/main/kotlin/io/kadena/pact/lsp/PactLspServerSupportProvider.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.intellij.platform.lsp.api.LspServerSupportProvider.LspServerStarter' is declared in unstable 'com.intellij.platform.lsp.api.LspServerSupportProvider' marked with @ApiStatus.Experimental
) {
if (file.extension == "pact") {
_project = project
serverStarter.ensureServerStarted(PactLspServerDescriptor(project))

Check warning on line 25 in src/main/kotlin/io/kadena/pact/lsp/PactLspServerSupportProvider.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'ensureServerStarted(com.intellij.platform.lsp.api.LspServerDescriptor)' is declared in unstable 'com.intellij.platform.lsp.api.LspServerSupportProvider' marked with @ApiStatus.Experimental
}
}

override fun onAppSettingsStateChanged(state: AppSettingsState) {
restart()
}

private fun restart() {
_project?.let { project ->
val server = LspServerManager.getInstance(project)

Check warning on line 35 in src/main/kotlin/io/kadena/pact/lsp/PactLspServerSupportProvider.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.intellij.platform.lsp.api.LspServerManager.Companion' is declared in unstable 'com.intellij.platform.lsp.api.LspServerManager' marked with @ApiStatus.Experimental

Check warning on line 35 in src/main/kotlin/io/kadena/pact/lsp/PactLspServerSupportProvider.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'getInstance(com.intellij.openapi.project.Project)' is declared in unstable 'com.intellij.platform.lsp.api.LspServerManager' marked with @ApiStatus.Experimental
server.stopAndRestartIfNeeded(PactLspServerSupportProvider::class.java)

Check warning on line 36 in src/main/kotlin/io/kadena/pact/lsp/PactLspServerSupportProvider.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'stopAndRestartIfNeeded(java.lang.Class)' is declared in unstable 'com.intellij.platform.lsp.api.LspServerManager' marked with @ApiStatus.Experimental
}
}
}
Empty file.

0 comments on commit 00bfd50

Please sign in to comment.