diff --git a/CHANGELOG.md b/CHANGELOG.md index d9658a7..67ab709 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/gradle.properties b/gradle.properties index 952c041..8239988 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/kotlin/io/kadena/pact/ide/settings/AppSettingsConfigurable.kt b/src/main/kotlin/io/kadena/pact/ide/settings/AppSettingsConfigurable.kt index 1624068..ba8ab9e 100644 --- a/src/main/kotlin/io/kadena/pact/ide/settings/AppSettingsConfigurable.kt +++ b/src/main/kotlin/io/kadena/pact/ide/settings/AppSettingsConfigurable.kt @@ -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() { diff --git a/src/main/kotlin/io/kadena/pact/ide/settings/AppSettingsState.kt b/src/main/kotlin/io/kadena/pact/ide/settings/AppSettingsState.kt index c524c7f..15efbdf 100644 --- a/src/main/kotlin/io/kadena/pact/ide/settings/AppSettingsState.kt +++ b/src/main/kotlin/io/kadena/pact/ide/settings/AppSettingsState.kt @@ -18,10 +18,12 @@ import org.jetbrains.annotations.Nullable name = "io.kadena.pact.ide.settings.AppSettingsState", storages = [Storage("PactPlugin.xml")] ) -internal class AppSettingsState : PersistentStateComponent { +class AppSettingsState : PersistentStateComponent { var pactPath: String = "" var pactLanguageServerPath: String = "" + private val listeners = mutableSetOf() + @Nullable override fun getState(): AppSettingsState { return this @@ -35,4 +37,18 @@ internal class AppSettingsState : PersistentStateComponent { 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) + } } diff --git a/src/main/kotlin/io/kadena/pact/lsp/PactLspServerSupportProvider.kt b/src/main/kotlin/io/kadena/pact/lsp/PactLspServerSupportProvider.kt index 7049516..7c49db6 100644 --- a/src/main/kotlin/io/kadena/pact/lsp/PactLspServerSupportProvider.kt +++ b/src/main/kotlin/io/kadena/pact/lsp/PactLspServerSupportProvider.kt @@ -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 { + + private var _project: Project? = null + + init { + val settings = AppSettingsState.instance + settings.addAppSettingsStateListener(this) + } -class PactLspServerSupportProvider : LspServerSupportProvider { override fun fileOpened( project: Project, file: VirtualFile, serverStarter: LspServerSupportProvider.LspServerStarter ) { if (file.extension == "pact") { + _project = project serverStarter.ensureServerStarted(PactLspServerDescriptor(project)) } } + + override fun onAppSettingsStateChanged(state: AppSettingsState) { + restart() + } + + private fun restart() { + _project?.let { project -> + val server = LspServerManager.getInstance(project) + server.stopAndRestartIfNeeded(PactLspServerSupportProvider::class.java) + } + } } diff --git a/src/main/resources/fileTemplates/Pact Smart Contract.pact.ft b/src/main/resources/fileTemplates/Pact Smart Contract.pact.ft new file mode 100644 index 0000000..e69de29