From 7b6342d0fb3cedefd6413a4c5161f715e0796751 Mon Sep 17 00:00:00 2001 From: Martin Azpillaga Aldalur Date: Tue, 3 Oct 2023 16:21:25 +0200 Subject: [PATCH] format plugin project with ktlint --- library/settings.gradle.kts | 2 +- plugin/build.gradle.kts | 20 +++--- plugin/settings.gradle.kts | 2 +- .../languageserver/LanguageServerPlugin.kt | 67 +++++++++++-------- 4 files changed, 48 insertions(+), 43 deletions(-) diff --git a/library/settings.gradle.kts b/library/settings.gradle.kts index 581a089..08926eb 100644 --- a/library/settings.gradle.kts +++ b/library/settings.gradle.kts @@ -1 +1 @@ -rootProject.name = "language-server" \ No newline at end of file +rootProject.name = "language-server" diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 2894dc2..2f4ae98 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -1,23 +1,19 @@ plugins { - id("java-gradle-plugin") - id("maven-publish") - id("org.jetbrains.kotlin.jvm") version "1.8.22" + id("java-gradle-plugin") + id("maven-publish") + id("org.jetbrains.kotlin.jvm") version "1.8.22" + id("org.jlleitschuh.gradle.ktlint") version "11.6.0" } repositories { - mavenCentral() + mavenCentral() } gradlePlugin { - plugins { - create("language-server-plugin") {id = "language-server-plugin"; implementationClass = "com.strumenta.languageserver.LanguageServerPlugin"} - } + plugins { + create("language-server-plugin") { id = "language-server-plugin"; implementationClass = "com.strumenta.languageserver.LanguageServerPlugin" } + } } group = "com.strumenta" version = "0.0.0" - -publishing { - repositories {mavenLocal()} - publications { create("mavenJava") { from(components["java"]) } } -} diff --git a/plugin/settings.gradle.kts b/plugin/settings.gradle.kts index 15f575b..0e983f0 100644 --- a/plugin/settings.gradle.kts +++ b/plugin/settings.gradle.kts @@ -1 +1 @@ -rootProject.name = "language-server-plugin" \ No newline at end of file +rootProject.name = "language-server-plugin" diff --git a/plugin/src/main/kotlin/com/strumenta/languageserver/LanguageServerPlugin.kt b/plugin/src/main/kotlin/com/strumenta/languageserver/LanguageServerPlugin.kt index b574a4e..2e7af47 100644 --- a/plugin/src/main/kotlin/com/strumenta/languageserver/LanguageServerPlugin.kt +++ b/plugin/src/main/kotlin/com/strumenta/languageserver/LanguageServerPlugin.kt @@ -38,28 +38,33 @@ class LanguageServerPlugin : Plugin { private fun addLaunchVscodeEditorTask(project: Project) { project.tasks.create("launchVscodeEditor").apply { - this.group = "language server"; - this.description = "Launch the configured vscode editor with the language server installed (defaults to code)"; - this.actions = listOf(Action { _ -> - try { - ProcessBuilder(extension.editor, "--extensionDevelopmentPath", "${project.projectDir}/build/extension", "${project.projectDir}/examples").start().waitFor() - } catch (exception: Exception) { - System.err.println(exception.message) + this.group = "language server" + this.description = "Launch the configured vscode editor with the language server installed (defaults to code)" + this.actions = listOf( + Action { _ -> + try { + ProcessBuilder(extension.editor, "--extensionDevelopmentPath", "${project.projectDir}/build/extension", "${project.projectDir}/examples").start().waitFor() + } catch (exception: Exception) { + System.err.println(exception.message) + } } - }) + ) this.dependsOn(project.tasks.getByName("createVscodeExtension")) - }; + } } private fun addCreateVscodeExtensionTask(project: Project) { project.tasks.create("createVscodeExtension").apply { - this.group = "language server"; - this.description = "Create language server extension folder for vscode under build/extension"; - this.actions = listOf(Action { _ -> - try { - val name = extension.language - Files.createDirectories(Paths.get("build", "extension")) - Files.writeString(Paths.get("build", "extension", "package.json"), """ + this.group = "language server" + this.description = "Create language server extension folder for vscode under build/extension" + this.actions = listOf( + Action { _ -> + try { + val name = extension.language + Files.createDirectories(Paths.get("build", "extension")) + Files.writeString( + Paths.get("build", "extension", "package.json"), + """ { "name": "${name.lowercase(Locale.getDefault())}", "version": "0.0.0", @@ -74,8 +79,11 @@ class LanguageServerPlugin : Plugin { "activationEvents": ["onLanguage:$name"], "main": "client.js" } - """.trimIndent()) - Files.writeString(Paths.get("build", "extension", "client.js"), """ + """.trimIndent() + ) + Files.writeString( + Paths.get("build", "extension", "client.js"), + """ let {LanguageClient} = require("../node_modules/vscode-languageclient/node"); async function activate (context) @@ -89,20 +97,21 @@ class LanguageServerPlugin : Plugin { } module.exports = {activate}; - """.trimIndent()) + """.trimIndent() + ) - if (extension.shadowJarName == "") - { - extension.shadowJarName = project.name - } - Files.copy(Paths.get("build", "libs", extension.shadowJarName+".jar"), Paths.get("build", "extension", "server.jar"), StandardCopyOption.REPLACE_EXISTING) + if (extension.shadowJarName == "") { + extension.shadowJarName = project.name + } + Files.copy(Paths.get("build", "libs", extension.shadowJarName + ".jar"), Paths.get("build", "extension", "server.jar"), StandardCopyOption.REPLACE_EXISTING) - ProcessBuilder("npm", "install", "--prefix", "build", "vscode-languageclient").start().waitFor() - ProcessBuilder("npx", "esbuild", "build/extension/client.js", "--bundle", "--external:vscode", "--format=cjs", "--platform=node", "--outfile=build/extension/client.js", "--allow-overwrite").start().waitFor() - } catch (exception: Exception) { - System.err.println(exception.message) + ProcessBuilder("npm", "install", "--prefix", "build", "vscode-languageclient").start().waitFor() + ProcessBuilder("npx", "esbuild", "build/extension/client.js", "--bundle", "--external:vscode", "--format=cjs", "--platform=node", "--outfile=build/extension/client.js", "--allow-overwrite").start().waitFor() + } catch (exception: Exception) { + System.err.println(exception.message) + } } - }) + ) this.dependsOn.add(project.tasks.getByName("shadowJar")) } }