From 934d87382cc8935486695aa6ca68324e5f291c54 Mon Sep 17 00:00:00 2001 From: Uladzislau Date: Thu, 6 Jun 2024 16:29:42 +0200 Subject: [PATCH] GH-2 Migrated to LSP4IJ Signed-off-by: Uladzislau --- .run/Package plugin.run.xml | 2 +- README.md | 18 +++- build.gradle.kts | 14 +-- gradle.properties | 2 +- .../zowe/cobol/init/CobolPluginListener.kt | 32 ------ .../org/zowe/cobol/init/CobolPluginState.kt | 70 ++++++------- .../zowe/cobol/init/CobolStartupActivity.kt | 29 ------ .../kotlin/org/zowe/cobol/init/InitStates.kt | 4 +- .../org/zowe/cobol/init/InitializationOnly.kt | 2 +- .../cobol/lsp/CobolLSPExtensionManager.kt | 98 ------------------- .../org/zowe/cobol/lsp/CobolLanguageClient.kt | 32 +----- .../cobol/lsp/CobolLanguageServerFactory.kt | 38 +++++++ .../zowe/cobol/lsp/CobolServerDefinition.kt | 12 --- .../lsp/debug/CobolInputStreamWrapper.kt | 31 ------ .../lsp/debug/CobolOutputStreamWrapper.kt | 30 ------ .../CobolProcessStreamConnectionProvider.kt | 30 ------ src/main/resources/META-INF/plugin.xml | 82 +++------------- 17 files changed, 113 insertions(+), 413 deletions(-) delete mode 100644 src/main/kotlin/org/zowe/cobol/init/CobolPluginListener.kt delete mode 100644 src/main/kotlin/org/zowe/cobol/init/CobolStartupActivity.kt delete mode 100644 src/main/kotlin/org/zowe/cobol/lsp/CobolLSPExtensionManager.kt create mode 100644 src/main/kotlin/org/zowe/cobol/lsp/CobolLanguageServerFactory.kt delete mode 100644 src/main/kotlin/org/zowe/cobol/lsp/CobolServerDefinition.kt delete mode 100644 src/main/kotlin/org/zowe/cobol/lsp/debug/CobolInputStreamWrapper.kt delete mode 100644 src/main/kotlin/org/zowe/cobol/lsp/debug/CobolOutputStreamWrapper.kt delete mode 100644 src/main/kotlin/org/zowe/cobol/lsp/debug/CobolProcessStreamConnectionProvider.kt diff --git a/.run/Package plugin.run.xml b/.run/Package plugin.run.xml index 6a31c22..7a6b62f 100644 --- a/.run/Package plugin.run.xml +++ b/.run/Package plugin.run.xml @@ -5,7 +5,7 @@ SPDX-License-Identifier: EPL-2.0 - Copyright IBA Group 2024 + Copyright Contributors to the Zowe Project --> diff --git a/README.md b/README.md index ba23441..f131a3a 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,20 @@ Provides: - syntax highlighting support using TextMate bundle from [eclipse-che4z/che-che4z-lsp-for-cobol](https://github.com/eclipse-che4z/che-che4z-lsp-for-cobol) by Broadcom® -- code actions using LSP technology with client from [ballerina-platform/lsp4intellij](https://github.com/ballerina-platform/lsp4intellij) and server from [eclipse-che4z/che-che4z-lsp-for-cobol](https://github.com/eclipse-che4z/che-che4z-lsp-for-cobol) by Broadcom® +- code actions using LSP technology with client from [redhat-developer/lsp4ij](https://github.com/redhat-developer/lsp4ij) and server from [eclipse-che4z/che-che4z-lsp-for-cobol](https://github.com/eclipse-che4z/che-che4z-lsp-for-cobol) by Broadcom® + +## Prerequisites + +- Java v17 +- Node.js v18 and later +- IntelliJ v2023.2 + +## How to run (user) + +- Open the folder with the project, run `./gradlew buildPlugin` (for Unix-like) or `.\gradlew.bat buildPlugin` (for Windows) to build the plugin (or run "Package plugin" configuration) +- The built plug-in will be at the `build/distributions` in .zip format, install it with Settings -> Plugins -> Install plugin from disk +- Reload your IDE + +## How to run (developer) + +- Open the folder with the project, run "Run plugin" configuration, wait for the other instance of IDE to run diff --git a/build.gradle.kts b/build.gradle.kts index 7e2f753..fac9c4c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ * * SPDX-License-Identifier: EPL-2.0 * - * Copyright IBA Group 2024 + * Copyright Contributors to the Zowe Project */ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -23,23 +23,13 @@ version = properties("pluginVersion").get() repositories { mavenCentral() - maven { - url = uri("https://jitpack.io") // lsp4intellij - } -} - -dependencies { - // TODO: update the dependency to fix the issues asap - // CVE-2023-2976 - no impact on the project (25.04.2024) - // CVE-2020-8908 - no impact on the project (25.04.2024) - implementation("com.github.ballerina-platform:lsp4intellij:0.96.0") } // Configure Gradle IntelliJ Plugin // Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html intellij { version.set(properties("platformVersion").get()) - plugins.set(listOf("org.jetbrains.plugins.textmate")) + plugins.set(listOf("org.jetbrains.plugins.textmate", "com.redhat.devtools.lsp4ij:0.0.1")) } tasks { diff --git a/gradle.properties b/gradle.properties index fce147e..4e310e4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,5 +15,5 @@ pluginVersion = 0.0.1 pluginGroup = org.zowe # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html -pluginSinceBuild = 241 +pluginSinceBuild = 232 pluginUntilBuild = 241.* diff --git a/src/main/kotlin/org/zowe/cobol/init/CobolPluginListener.kt b/src/main/kotlin/org/zowe/cobol/init/CobolPluginListener.kt deleted file mode 100644 index f7a074e..0000000 --- a/src/main/kotlin/org/zowe/cobol/init/CobolPluginListener.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 - * - * Copyright IBA Group 2024 - */ - -package org.zowe.cobol.init - -import com.intellij.ide.plugins.DynamicPluginListener -import com.intellij.ide.plugins.IdeaPluginDescriptor -import com.intellij.openapi.application.runWriteAction - -/** COBOL Language Support plug-in listener for functions before loading/unloading handling */ -@OptIn(InitializationOnly::class) -class CobolPluginListener : DynamicPluginListener { - /** Disable all the plug-in's related features before it is unloaded */ - override fun beforePluginUnload(pluginDescriptor: IdeaPluginDescriptor, isUpdate: Boolean) { - val cobolPluginStates = CobolPluginState.getAllPluginStates() - runWriteAction { - cobolPluginStates.forEach { (_, pluginState) -> - pluginState.disableTextMateBundle() - pluginState.disableLSP() - pluginState.finishDeinitialization() - } - } - super.beforePluginUnload(pluginDescriptor, isUpdate) - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/zowe/cobol/init/CobolPluginState.kt b/src/main/kotlin/org/zowe/cobol/init/CobolPluginState.kt index 721e903..c27ff5e 100644 --- a/src/main/kotlin/org/zowe/cobol/init/CobolPluginState.kt +++ b/src/main/kotlin/org/zowe/cobol/init/CobolPluginState.kt @@ -5,7 +5,7 @@ * * SPDX-License-Identifier: EPL-2.0 * - * Copyright IBA Group 2024 + * Copyright Contributors to the Zowe Project */ package org.zowe.cobol.init @@ -16,16 +16,16 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer import com.intellij.util.io.ZipUtil import com.jetbrains.rd.util.firstOrNull -import org.zowe.cobol.lsp.CobolLSPExtensionManager -import org.zowe.cobol.lsp.CobolServerDefinition import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.jetbrains.plugins.textmate.TextMateService import org.jetbrains.plugins.textmate.configuration.TextMateUserBundlesSettings import org.jetbrains.plugins.textmate.plist.JsonPlistReader -import org.wso2.lsp4intellij.IntellijLanguageClient -import org.wso2.lsp4intellij.utils.FileUtils import com.intellij.openapi.util.io.FileUtil +import com.redhat.devtools.lsp4ij.client.LanguageClientImpl +import com.redhat.devtools.lsp4ij.server.JavaProcessCommandBuilder +import com.redhat.devtools.lsp4ij.server.ProcessStreamConnectionProvider +import org.zowe.cobol.lsp.CobolLanguageClient import java.nio.file.Path import kotlin.io.path.exists import kotlin.io.path.pathString @@ -87,7 +87,7 @@ class CobolPluginState private constructor() : Disposable { */ @InitializationOnly suspend fun unpackVSIX() { - if (currState != InitStates.DOWN) throw IllegalStateException("Invalid plug-in state. Expected: ${InitStates.DOWN}, current: $currState") +// if (currState != InitStates.DOWN) throw IllegalStateException("Invalid plug-in state. Expected: ${InitStates.DOWN}, current: $currState") val doPathsAlreadyExist = computeVSIXPlacingPaths() if (!doPathsAlreadyExist) { val activeClassLoader = this::class.java.classLoader @@ -116,8 +116,8 @@ class CobolPluginState private constructor() : Disposable { * loaded to the IDE stays there */ @InitializationOnly - fun loadTextMateBundle() { - if (currState < InitStates.VSIX_UNPACKED) throw IllegalStateException("Invalid plug-in state. Expected: at least ${InitStates.VSIX_UNPACKED}, current: $currState") + fun loadLanguageClientDefinition(project: Project): LanguageClientImpl { +// if (currState < InitStates.VSIX_UNPACKED) throw IllegalStateException("Invalid plug-in state. Expected: at least ${InitStates.VSIX_UNPACKED}, current: $currState") currState = InitStates.TEXTMATE_BUNDLE_LOAD_TRIGGERED val emptyBundleName = "$TEXTMATE_BUNDLE_NAME-0.0.0" val newBundleName = "$TEXTMATE_BUNDLE_NAME-$VSIX_VERSION" @@ -133,6 +133,7 @@ class CobolPluginState private constructor() : Disposable { TextMateService.getInstance().reloadEnabledBundles() } currState = InitStates.TEXTMATE_BUNDLE_LOADED + return CobolLanguageClient(project) } /** Extract COBOL language extensions, supported for recognition, from package.json in resources */ @@ -176,35 +177,25 @@ class CobolPluginState private constructor() : Disposable { return cobolExtensions } - /** Initialize LSP server and client, setup their communication. Will get the server.jar from the unzipped .vsix */ + /** Initialize language server definition. Will run the LSP server command */ @InitializationOnly - fun loadLSP() { - if (currState < InitStates.VSIX_UNPACKED) throw IllegalStateException("Invalid plug-in state. Expected: at least ${InitStates.VSIX_UNPACKED}, current: $currState") + fun loadLanguageServerDefinition(project: Project): ProcessStreamConnectionProvider { +// if (currState < InitStates.VSIX_UNPACKED) throw IllegalStateException("Invalid plug-in state. Expected: at least ${InitStates.VSIX_UNPACKED}, current: $currState") currState = InitStates.LSP_LOAD_TRIGGERED val lspServerPathString = lspServerPath.pathString - val extensions = extractExtensionsFromPackageJson() - val manager = CobolLSPExtensionManager() - - IntellijLanguageClient - .addServerDefinition( - CobolServerDefinition( - extensions.joinToString(","), - arrayOf( - "java", - "-jar", - "\"$lspServerPathString\"", - "pipeEnabled" - ) - ) - ) - extensions.forEach { extension -> IntellijLanguageClient.addExtensionManager(extension, manager) } +// val extensions = extractExtensionsFromPackageJson() + val commands: MutableList = JavaProcessCommandBuilder(project, "cobol") + .setJar(lspServerPathString) + .create() + commands.add("pipeEnabled") currState = InitStates.LSP_LOADED + return object : ProcessStreamConnectionProvider(commands) {} } /** Initialization final step, no direct purposes for now */ @InitializationOnly fun finishInitialization(project: Project) { - if (currState < InitStates.LSP_LOADED) throw IllegalStateException("Invalid plug-in state. Expected: at least ${InitStates.LSP_LOADED}, current: $currState") + if (currState != InitStates.LSP_LOADED || currState != InitStates.TEXTMATE_BUNDLE_LOADED) throw IllegalStateException("Invalid plug-in state. Expected: at least ${InitStates.LSP_LOADED}, current: $currState") stateProject = project currState = InitStates.UP } @@ -221,16 +212,17 @@ class CobolPluginState private constructor() : Disposable { currState = InitStates.TEXTMATE_BUNDLE_UNLOADED } - /** Disable LSP server wrappers together with LSP servers for the project before the plug-in's state is disposed */ - @InitializationOnly - fun disableLSP() { - if (currState > InitStates.TEXTMATE_BUNDLE_UNLOADED) throw IllegalStateException("Invalid plug-in state. Expected: at most ${InitStates.TEXTMATE_BUNDLE_UNLOADED}, current: $currState") - currState = InitStates.LSP_UNLOAD_TRIGGERED - val projectPath = FileUtils.projectToUri(stateProject) - val serverWrappers = IntellijLanguageClient.getAllServerWrappersFor(projectPath) - serverWrappers.forEach { it.stop(true) } - currState = InitStates.LSP_UNLOADED - } + // TODO: finish, doc +// /** Disable LSP server wrappers together with LSP servers for the project before the plug-in's state is disposed */ +// @InitializationOnly +// fun disableLSP() { +// if (currState > InitStates.TEXTMATE_BUNDLE_UNLOADED) throw IllegalStateException("Invalid plug-in state. Expected: at most ${InitStates.TEXTMATE_BUNDLE_UNLOADED}, current: $currState") +// currState = InitStates.LSP_UNLOAD_TRIGGERED +// val projectPath = FileUtils.projectToUri(stateProject) +// val serverWrappers = IntellijLanguageClient.getAllServerWrappersFor(projectPath) +// serverWrappers.forEach { it.stop(true) } +// currState = InitStates.LSP_UNLOADED +// } /** Deinitialization final step, disposing purposes */ @InitializationOnly @@ -243,4 +235,4 @@ class CobolPluginState private constructor() : Disposable { override fun dispose() { Disposer.dispose(this) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/org/zowe/cobol/init/CobolStartupActivity.kt b/src/main/kotlin/org/zowe/cobol/init/CobolStartupActivity.kt deleted file mode 100644 index 4478524..0000000 --- a/src/main/kotlin/org/zowe/cobol/init/CobolStartupActivity.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 - * - * Copyright IBA Group 2024 - */ - -package org.zowe.cobol.init - -import com.intellij.openapi.project.Project -import com.intellij.openapi.startup.ProjectActivity -import kotlinx.coroutines.runBlocking - -/** COBOL Language Support plug-in for IntelliJ IDEA main activity to initialize all the things needed */ -@OptIn(InitializationOnly::class) -class CobolStartupActivity : ProjectActivity { - override suspend fun execute(project: Project) { - val cobolPluginState = CobolPluginState.getPluginState(project) - runBlocking { - cobolPluginState.unpackVSIX() - } - cobolPluginState.loadTextMateBundle() - cobolPluginState.loadLSP() - cobolPluginState.finishInitialization(project) - } -} diff --git a/src/main/kotlin/org/zowe/cobol/init/InitStates.kt b/src/main/kotlin/org/zowe/cobol/init/InitStates.kt index f2b4ddc..0094dcd 100644 --- a/src/main/kotlin/org/zowe/cobol/init/InitStates.kt +++ b/src/main/kotlin/org/zowe/cobol/init/InitStates.kt @@ -5,7 +5,7 @@ * * SPDX-License-Identifier: EPL-2.0 * - * Copyright IBA Group 2024 + * Copyright Contributors to the Zowe Project */ package org.zowe.cobol.init @@ -24,4 +24,4 @@ enum class InitStates { LSP_LOAD_TRIGGERED, LSP_LOADED, UP -} \ No newline at end of file +} diff --git a/src/main/kotlin/org/zowe/cobol/init/InitializationOnly.kt b/src/main/kotlin/org/zowe/cobol/init/InitializationOnly.kt index bfb3501..6874718 100644 --- a/src/main/kotlin/org/zowe/cobol/init/InitializationOnly.kt +++ b/src/main/kotlin/org/zowe/cobol/init/InitializationOnly.kt @@ -5,7 +5,7 @@ * * SPDX-License-Identifier: EPL-2.0 * - * Copyright IBA Group 2024 + * Copyright Contributors to the Zowe Project */ package org.zowe.cobol.init diff --git a/src/main/kotlin/org/zowe/cobol/lsp/CobolLSPExtensionManager.kt b/src/main/kotlin/org/zowe/cobol/lsp/CobolLSPExtensionManager.kt deleted file mode 100644 index 9b491fc..0000000 --- a/src/main/kotlin/org/zowe/cobol/lsp/CobolLSPExtensionManager.kt +++ /dev/null @@ -1,98 +0,0 @@ -package org.zowe.cobol.lsp - -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.editor.event.DocumentListener -import org.eclipse.lsp4j.SaveOptions -import org.eclipse.lsp4j.ServerCapabilities -import org.eclipse.lsp4j.TextDocumentSyncKind -import org.eclipse.lsp4j.TextDocumentSyncOptions -import org.eclipse.lsp4j.jsonrpc.messages.Either -import org.eclipse.lsp4j.services.LanguageClient -import org.eclipse.lsp4j.services.LanguageServer -import org.wso2.lsp4intellij.client.ClientContext -import org.wso2.lsp4intellij.client.languageserver.ServerOptions -import org.wso2.lsp4intellij.client.languageserver.requestmanager.DefaultRequestManager -import org.wso2.lsp4intellij.client.languageserver.requestmanager.RequestManager -import org.wso2.lsp4intellij.client.languageserver.wrapper.LanguageServerWrapper -import org.wso2.lsp4intellij.editor.EditorEventManager -import org.wso2.lsp4intellij.extensions.LSPExtensionManager -import org.wso2.lsp4intellij.listeners.EditorMouseListenerImpl -import org.wso2.lsp4intellij.listeners.EditorMouseMotionListenerImpl -import org.wso2.lsp4intellij.listeners.LSPCaretListenerImpl - -/** - * Transform textDocumentSync [Either] option when only left value is present - * @param serverCapabilities the server capabilities instance to get the textDocumentSync [Either] instance - * @return the right value for the textDocumentSync [Either] instance - */ -private fun transformTextDocumentSync( - serverCapabilities: ServerCapabilities? -): Either { - val textDocumentSync = serverCapabilities?.textDocumentSync - val textDocumentSyncOptions: TextDocumentSyncOptions? = - if (textDocumentSync?.isRight != true) { - when (textDocumentSync?.left) { - TextDocumentSyncKind.Full -> { - val textDocumentSyncOptions = TextDocumentSyncOptions() - textDocumentSyncOptions.openClose = true - textDocumentSyncOptions.change = textDocumentSync.left - textDocumentSyncOptions.save = Either.forRight(SaveOptions(false)) - textDocumentSyncOptions - } - TextDocumentSyncKind.None -> { - val textDocumentSyncOptions = TextDocumentSyncOptions() - textDocumentSyncOptions.openClose = false - textDocumentSyncOptions.change = textDocumentSync.left - textDocumentSyncOptions - } - else -> null - } - } else textDocumentSync.right - return Either.forRight(textDocumentSyncOptions) -} - -/** - * COBOL LSP extension manager wrapper to setup handlers for requests and events, as well as the LSP client instance - * and LSP server interface to communicate through - */ -class CobolLSPExtensionManager : LSPExtensionManager { - override fun getExtendedRequestManagerFor( - wrapper: LanguageServerWrapper?, - server: LanguageServer?, - client: LanguageClient?, - serverCapabilities: ServerCapabilities? - ): T { - serverCapabilities?.textDocumentSync = transformTextDocumentSync(serverCapabilities) - return DefaultRequestManager(wrapper, server, client, serverCapabilities) as T - } - - override fun getExtendedEditorEventManagerFor( - editor: Editor?, - documentListener: DocumentListener?, - mouseListener: EditorMouseListenerImpl?, - mouseMotionListener: EditorMouseMotionListenerImpl?, - caretListener: LSPCaretListenerImpl?, - requestManager: RequestManager?, - serverOptions: ServerOptions?, - wrapper: LanguageServerWrapper? - ): T { - return EditorEventManager( - editor, - documentListener, - mouseListener, - mouseMotionListener, - caretListener, - requestManager, - serverOptions, - wrapper - ) as T - } - - override fun getExtendedServerInterface(): Class { - return LanguageServer::class.java - } - - override fun getExtendedClientFor(context: ClientContext): LanguageClient { - return CobolLanguageClient(context) - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/zowe/cobol/lsp/CobolLanguageClient.kt b/src/main/kotlin/org/zowe/cobol/lsp/CobolLanguageClient.kt index f6452ae..9f58143 100644 --- a/src/main/kotlin/org/zowe/cobol/lsp/CobolLanguageClient.kt +++ b/src/main/kotlin/org/zowe/cobol/lsp/CobolLanguageClient.kt @@ -5,16 +5,14 @@ * * SPDX-License-Identifier: EPL-2.0 * - * Copyright IBA Group 2024 + * Copyright Contributors to the Zowe Project */ package org.zowe.cobol.lsp +import com.intellij.openapi.project.Project +import com.redhat.devtools.lsp4ij.client.LanguageClientImpl import org.eclipse.lsp4j.ConfigurationParams -import org.eclipse.lsp4j.ProgressParams -import org.eclipse.lsp4j.WorkDoneProgressCreateParams -import org.wso2.lsp4intellij.client.ClientContext -import org.wso2.lsp4intellij.client.DefaultLanguageClient import java.util.concurrent.CompletableFuture private const val DIALECT_REGISTRY_SECTION = "cobol-lsp.dialect.registry" @@ -27,7 +25,7 @@ private const val SETTINGS_CPY_FILE_ENCODING = "cobol-lsp.cpy-manager.copybook-f private const val SETTINGS_COMPILE_OPTIONS = "cobol-lsp.compiler.options" /** COBOL LSP client wrapper. Provides a comprehensive support for the COBOL LSP communications */ -class CobolLanguageClient(context: ClientContext) : DefaultLanguageClient(context) { +class CobolLanguageClient(project: Project) : LanguageClientImpl(project) { /** * "workspace/configuration" request from LSP server handler. @@ -125,24 +123,4 @@ class CobolLanguageClient(context: ClientContext) : DefaultLanguageClient(contex return CompletableFuture.completedFuture(result) } - /** - * "window/workDoneProgress/create" request from LSP server handler. - * Handles the document analysis progress message - * @param params the progress parameters - */ - // TODO: write the progress handler wrapper for the IntelliJ UI - override fun createProgress(params: WorkDoneProgressCreateParams?): CompletableFuture { - println("window/workDoneProgress/create message came with params: $params") - return CompletableFuture.completedFuture(null) - } - - /** - * "$/progress" request from LSP server handler. - * Handles the document analysis progress message - * @param params the progress parameters - */ - // TODO: write the progress handler wrapper for the IntelliJ UI - override fun notifyProgress(params: ProgressParams?) { - println("$/progress message came with params: $params") - } -} \ No newline at end of file +} diff --git a/src/main/kotlin/org/zowe/cobol/lsp/CobolLanguageServerFactory.kt b/src/main/kotlin/org/zowe/cobol/lsp/CobolLanguageServerFactory.kt new file mode 100644 index 0000000..ff3907e --- /dev/null +++ b/src/main/kotlin/org/zowe/cobol/lsp/CobolLanguageServerFactory.kt @@ -0,0 +1,38 @@ +/* + * 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 + * + * Copyright Contributors to the Zowe Project + */ + +package org.zowe.cobol.lsp + +import com.intellij.openapi.project.Project +import com.redhat.devtools.lsp4ij.LanguageServerFactory +import com.redhat.devtools.lsp4ij.client.LanguageClientImpl +import com.redhat.devtools.lsp4ij.server.StreamConnectionProvider +import kotlinx.coroutines.runBlocking +import org.zowe.cobol.init.CobolPluginState +import org.zowe.cobol.init.InitializationOnly + +// TODO: doc +@OptIn(InitializationOnly::class) +class CobolLanguageServerFactory : LanguageServerFactory { + + override fun createConnectionProvider(project: Project): StreamConnectionProvider { + val pliPluginState = CobolPluginState.getPluginState(project) + runBlocking { + pliPluginState.unpackVSIX() + } + return pliPluginState.loadLanguageServerDefinition(project) + } + + override fun createLanguageClient(project: Project): LanguageClientImpl { + val pliPluginState = CobolPluginState.getPluginState(project) + return pliPluginState.loadLanguageClientDefinition(project) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/org/zowe/cobol/lsp/CobolServerDefinition.kt b/src/main/kotlin/org/zowe/cobol/lsp/CobolServerDefinition.kt deleted file mode 100644 index 08ac311..0000000 --- a/src/main/kotlin/org/zowe/cobol/lsp/CobolServerDefinition.kt +++ /dev/null @@ -1,12 +0,0 @@ -package org.zowe.cobol.lsp - -import org.wso2.lsp4intellij.client.connection.StreamConnectionProvider -import org.wso2.lsp4intellij.client.languageserver.serverdefinition.RawCommandServerDefinition -import org.zowe.cobol.lsp.debug.CobolProcessStreamConnectionProvider - -/** COBOL LSP server definition wrapper to provide a custom connection provider for the LSP client debug purposes */ -class CobolServerDefinition(extensions: String, command: Array) : RawCommandServerDefinition(extensions, command) { - override fun createConnectionProvider(workingDir: String): StreamConnectionProvider { - return CobolProcessStreamConnectionProvider(listOf(*command), workingDir) - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/zowe/cobol/lsp/debug/CobolInputStreamWrapper.kt b/src/main/kotlin/org/zowe/cobol/lsp/debug/CobolInputStreamWrapper.kt deleted file mode 100644 index 4426ffc..0000000 --- a/src/main/kotlin/org/zowe/cobol/lsp/debug/CobolInputStreamWrapper.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 - * - * Copyright IBA Group 2024 - */ - -package org.zowe.cobol.lsp.debug - -import java.io.BufferedInputStream -import java.io.InputStream - -/** - * Input stream wrapper for COBOL LSP client. Is used for debug purposes - * @property inputStream the input stream to wrap - */ -class CobolInputStreamWrapper(inputStream: InputStream) : BufferedInputStream(inputStream) { - /** - * Read the next message in the inputStream to provide debug information. - * It will result in debug message to the [System.out] when there is a new content received by the client. - * The original processing is continued by the [BufferedInputStream]'s 'read' method - */ - override fun read(b: ByteArray, off: Int, len: Int): Int { - val read = super.read(b, off, len) - println("LSP Client receives: ${String(b, Charsets.UTF_8)}") - return read - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/zowe/cobol/lsp/debug/CobolOutputStreamWrapper.kt b/src/main/kotlin/org/zowe/cobol/lsp/debug/CobolOutputStreamWrapper.kt deleted file mode 100644 index 2849d7c..0000000 --- a/src/main/kotlin/org/zowe/cobol/lsp/debug/CobolOutputStreamWrapper.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 - * - * Copyright IBA Group 2024 - */ - -package org.zowe.cobol.lsp.debug - -import java.io.BufferedOutputStream -import java.io.OutputStream - -/** - * Output stream wrapper for COBOL LSP client. Is used for debug purposes - * @property outputStream the output stream to wrap - */ -class CobolOutputStreamWrapper(outputStream: OutputStream) : BufferedOutputStream(outputStream) { - /** - * Read the next message to the outputStream to provide debug information. - * It will result in debug message to the [System.out] when there is a new content received by the client. - * The original processing is continued by the [BufferedOutputStream]'s 'write' method - */ - override fun write(b: ByteArray, off: Int, len: Int) { - println("LSP Client sends: ${String(b, Charsets.UTF_8)}") - super.write(b, off, len) - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/zowe/cobol/lsp/debug/CobolProcessStreamConnectionProvider.kt b/src/main/kotlin/org/zowe/cobol/lsp/debug/CobolProcessStreamConnectionProvider.kt deleted file mode 100644 index a561070..0000000 --- a/src/main/kotlin/org/zowe/cobol/lsp/debug/CobolProcessStreamConnectionProvider.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 - * - * Copyright IBA Group 2024 - */ - -package org.zowe.cobol.lsp.debug - -import org.wso2.lsp4intellij.client.connection.ProcessStreamConnectionProvider - -/** - * COBOL LSP stream connection provider wrapper. Could be used for low-level debug purposes to see how the LSP client - * communicates with the LSP server - */ -class CobolProcessStreamConnectionProvider(commands: List, workingDir: String) - : ProcessStreamConnectionProvider(commands, workingDir) { -// override fun getOutputStream(): OutputStream? { -// val rawOutputStream = super.getOutputStream() -// return if (rawOutputStream != null) CobolOutputStreamWrapper(rawOutputStream) else null -// } - -// override fun getInputStream(): InputStream? { -// val rawInputStream = super.getInputStream() -// return if (rawInputStream != null) CobolInputStreamWrapper(rawInputStream) else null -// } -} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 149aa61..a9a9630 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -20,74 +20,22 @@ com.intellij.modules.platform + com.redhat.devtools.lsp4ij org.jetbrains.plugins.textmate - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - \ No newline at end of file +