Skip to content

Commit

Permalink
GH-1 Plug-in uninstallation is corrected, LanguageSupportState added …
Browse files Browse the repository at this point in the history
…to manage the plug-in's state, some reworks for the plug-in's state management, added full unit tests coverage

Signed-off-by: Uladzislau <[email protected]>
  • Loading branch information
KUGDev committed Jul 8, 2024
1 parent 811550b commit 8d6836d
Show file tree
Hide file tree
Showing 22 changed files with 2,111 additions and 307 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ jobs:
shell: bash
run: pwd && ls -la

- name: Build plugin
- name: Test plugin
shell: bash
run: ./gradlew test

- name: Build plugin's binary
shell: bash
run: ./gradlew buildPlugin

Expand Down
18 changes: 18 additions & 0 deletions .idea/LanguageServersSettings.xml

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

7 changes: 7 additions & 0 deletions .idea/copyright/profiles_settings.xml

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

6 changes: 6 additions & 0 deletions .idea/copyright/zowe_ijmp.xml

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

27 changes: 26 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ plugins {
id("java")
id("org.jetbrains.kotlin.jvm") version "1.9.21"
id("org.jetbrains.intellij") version "1.16.1"
id("org.jetbrains.kotlinx.kover") version "0.8.1"
}

group = properties("pluginGroup").get()
version = properties("pluginVersion").get()
val kotestVersion = "5.9.1"
val mockkVersion = "1.13.11"
val junitVersion = ""

repositories {
mavenCentral()
Expand All @@ -32,7 +36,20 @@ intellij {
// pluginsRepositories {
// custom("https://plugins.jetbrains.com/plugins/nightly/23257")
// }
plugins.set(listOf("org.jetbrains.plugins.textmate", "com.redhat.devtools.lsp4ij:0.0.1"))
plugins.set(listOf("org.jetbrains.plugins.textmate", "com.redhat.devtools.lsp4ij:0.0.2"))
}

dependencies {
// ===== Test env setup =====
// Kotest
testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion")
testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
// MockK
testImplementation("io.mockk:mockk:$mockkVersion")
// JUnit Platform (needed for Kotest)
testImplementation("org.junit.platform:junit-platform-launcher:1.10.2")
// ==========================

}

tasks {
Expand All @@ -50,4 +67,12 @@ tasks {
sinceBuild.set(properties("pluginSinceBuild").get())
untilBuild.set(properties("pluginUntilBuild").get())
}

test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
finalizedBy("koverHtmlReport")
}
}
48 changes: 48 additions & 0 deletions src/main/kotlin/org/zowe/cobol/CobolProjectManagerListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2024 IBA Group.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBA Group
* Zowe Community
*/

package org.zowe.cobol

import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.project.ProjectManagerListener
import org.zowe.cobol.state.CobolPluginState
import org.zowe.cobol.state.InitializationOnly
import org.zowe.cobol.state.LanguageSupportStateService

/** COBOL project manager listener. Listens to projects changes and react to them respectively */
class CobolProjectManagerListener : ProjectManagerListener {

/**
* Delete TextMate bundle if the last opened project is being closed
* (the only possible way to handle plug-in's TextMate bundle to be deleted when the plug-in is uninstalled)
*/
@OptIn(InitializationOnly::class)
override fun projectClosing(project: Project) {
val lsStateService = LanguageSupportStateService.instance
val pluginState = lsStateService.getPluginState(project) { CobolPluginState(project) }

if (isLastProjectClosing() && (pluginState.isLSPClientReady() || pluginState.isLSPServerConnectionReady())) {
pluginState.unloadLSPClient {}
pluginState.finishDeinitialization {}
}
}

/** Check if the project being closed is the last one that was opened */
private fun isLastProjectClosing(): Boolean {
return ProjectManager.getInstance().openProjects.size == 1
}

}
238 changes: 0 additions & 238 deletions src/main/kotlin/org/zowe/cobol/init/CobolPluginState.kt

This file was deleted.

Loading

0 comments on commit 8d6836d

Please sign in to comment.