Skip to content

Commit

Permalink
format plugin project with ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Azpillaga Aldalur committed Oct 3, 2023
1 parent db80b13 commit 7b6342d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 43 deletions.
2 changes: 1 addition & 1 deletion library/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = "language-server"
rootProject.name = "language-server"
20 changes: 8 additions & 12 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<MavenPublication>("mavenJava") { from(components["java"]) } }
}
2 changes: 1 addition & 1 deletion plugin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = "language-server-plugin"
rootProject.name = "language-server-plugin"
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,33 @@ class LanguageServerPlugin : Plugin<Project?> {

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",
Expand All @@ -74,8 +79,11 @@ class LanguageServerPlugin : Plugin<Project?> {
"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)
Expand All @@ -89,20 +97,21 @@ class LanguageServerPlugin : Plugin<Project?> {
}
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"))
}
}
Expand Down

0 comments on commit 7b6342d

Please sign in to comment.