Skip to content

fix: disable textmate bundle when JetBrains plugin is uninstalled #918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/ide/jetbrains/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/ide/jetbrains/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/ide/jetbrains/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "dev.zenstack"
version = "0.5.0"
version = "1.6.0"

repositories {
mavenCentral()
Expand Down
28 changes: 28 additions & 0 deletions packages/ide/jetbrains/src/main/kotlin/dev/zenstack/Utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.zenstack

import com.intellij.lang.javascript.service.JSLanguageServiceUtil
import org.jetbrains.plugins.textmate.TextMateService
import org.jetbrains.plugins.textmate.configuration.TextMateUserBundlesSettings

class Utils {
companion object {
fun addTextMateBundle() {
println("Adding ZenStack textmate bundle")
val textMateBundle = JSLanguageServiceUtil.getPluginDirectory(javaClass, "res/zmodel.tmbundle")
TextMateUserBundlesSettings.instance?.addBundle(textMateBundle.path, "zmodel")
reloadTextMateBundles()
}

fun disableTextMateBundle() {
println("Disabling ZenStack textmate bundle")
val textMateBundle = JSLanguageServiceUtil.getPluginDirectory(javaClass, "res/zmodel.tmbundle")
TextMateUserBundlesSettings.instance?.disableBundle(textMateBundle.path)
reloadTextMateBundles()
}

private fun reloadTextMateBundles() {
val textMateService = TextMateService.getInstance();
textMateService.reloadEnabledBundles()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.zenstack.lsp

import com.intellij.codeInsight.completion.CompletionParameters
import com.intellij.execution.ExecutionException
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.javascript.nodejs.interpreter.NodeCommandLineConfigurator
Expand All @@ -11,23 +10,17 @@ import com.intellij.lang.javascript.service.JSLanguageServiceUtil
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.platform.lsp.api.ProjectWideLspServerDescriptor
import com.intellij.platform.lsp.api.customization.LspCompletionSupport
import com.intellij.platform.lsp.api.customization.LspFormattingSupport
import org.jetbrains.plugins.textmate.configuration.TextMateUserBundlesSettings
import org.jetbrains.plugins.textmate.TextMateService;
import dev.zenstack.lang.ZModelFileType
import dev.zenstack.Utils

class ZenStackLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(project, "ZenStack") {

override fun isSupportedFile(file: VirtualFile) = file.fileType == ZModelFileType

override fun createCommandLine(): GeneralCommandLine {

// install TextMate bundle
val textMateBundle = JSLanguageServiceUtil.getPluginDirectory(javaClass, "res/zmodel.tmbundle")
TextMateUserBundlesSettings.instance?.addBundle(textMateBundle.path, "zmodel")
val textMateService = TextMateService.getInstance();
textMateService.reloadEnabledBundles()
Utils.Companion.addTextMateBundle()

// start language server
val interpreter = NodeJsInterpreterManager.getInstance(project).interpreter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.zenstack.plugin

import com.intellij.ide.plugins.DynamicPluginListener
import com.intellij.ide.plugins.IdeaPluginDescriptor
import dev.zenstack.Utils
import org.jetbrains.plugins.textmate.TextMateService

class PluginStateListener: DynamicPluginListener {
override fun beforePluginLoaded(pluginDescriptor: IdeaPluginDescriptor) {
// install TextMate bundle
Utils.Companion.addTextMateBundle()
}

override fun beforePluginUnload(pluginDescriptor: IdeaPluginDescriptor, isUpdate: Boolean) {
// uninstall TextMate bundle
Utils.disableTextMateBundle()
}
}
10 changes: 10 additions & 0 deletions packages/ide/jetbrains/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

<ul>
<li>Syntax highlighting</li>
<li>Error highlighting</li>
<li>Go to definition</li>
<li>Code completion</li>
<li>Formatting</li>
</ul>
]]></description>

Expand Down Expand Up @@ -54,4 +56,12 @@
implementationClass="org.jetbrains.plugins.textmate.language.syntax.highlighting.TextMateSyntaxHighlighterFactory"/>

</extensions>

<applicationListeners>
<listener
class="dev.zenstack.plugin.PluginStateListener"
topic="com.intellij.ide.plugins.DynamicPluginListener"/>
</applicationListeners>

<idea-version since-build="233.2" />
</idea-plugin>