From e7c474a44258fb89091ff92b71f290b8fd2da3cb Mon Sep 17 00:00:00 2001 From: Lorenzo Addazi Date: Mon, 11 Mar 2024 10:42:27 +0100 Subject: [PATCH 1/3] fix: fixes #73 (and some ktlint violations) Signed-off-by: Lorenzo Addazi --- gradle.properties | 7 +- library/build.gradle.kts | 17 +- .../kolasu/languageserver/KolasuServer.kt | 171 +++++++++++++---- plugin/build.gradle.kts | 25 ++- .../plugin/LanguageServerPlugin.kt | 180 +++++++++++++----- testing/build.gradle.kts | 14 +- .../testing/DiagnosticListenerClient.kt | 6 +- .../main/kotlin/testing/TestKolasuServer.kt | 31 ++- 8 files changed, 355 insertions(+), 96 deletions(-) diff --git a/gradle.properties b/gradle.properties index bf5fa0e..59d6fdd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,6 @@ -version=1.0.4-SNAPSHOT \ No newline at end of file +version=1.0.4-SNAPSHOT +kotlinVersion=1.8.22 +kolasuVersion=1.5.45 +lsp4jVersion=0.21.1 +luceneVersion=9.8.0 +junitVersion=5.7.1 \ No newline at end of file diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 0ea7ae4..287708a 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -11,11 +11,16 @@ repositories { mavenCentral() } +val kotlinVersion: String by project +val kolasuVersion: String by project +val lsp4jVersion: String by project +val luceneVersion: String by project + dependencies { - implementation("org.jetbrains.kotlin:kotlin-reflect:1.5.21") - implementation("com.strumenta.kolasu:kolasu-core:1.5.45") - implementation("org.eclipse.lsp4j:org.eclipse.lsp4j:0.21.1") - implementation("org.apache.lucene:lucene-core:9.8.0") + implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") + implementation("com.strumenta.kolasu:kolasu-core:$kolasuVersion") + implementation("org.eclipse.lsp4j:org.eclipse.lsp4j:$lsp4jVersion") + implementation("org.apache.lucene:lucene-core:$luceneVersion") } java { @@ -78,3 +83,7 @@ publishing { signing { sign(publishing.publications.getByName("language-server-library")) } + +ktlint { + version = "1.2.1" +} diff --git a/library/src/main/kotlin/com/strumenta/kolasu/languageserver/KolasuServer.kt b/library/src/main/kotlin/com/strumenta/kolasu/languageserver/KolasuServer.kt index 295b94f..8ebce87 100644 --- a/library/src/main/kotlin/com/strumenta/kolasu/languageserver/KolasuServer.kt +++ b/library/src/main/kotlin/com/strumenta/kolasu/languageserver/KolasuServer.kt @@ -98,9 +98,8 @@ open class KolasuServer( protected open val extensions: List = listOf(), protected open val enableDefinitionCapability: Boolean = false, protected open val enableReferencesCapability: Boolean = false, - protected open val generator: CodeGenerator? = null + protected open val generator: CodeGenerator? = null, ) : LanguageServer, TextDocumentService, WorkspaceService, LanguageClientAware { - protected open lateinit var client: LanguageClient protected open var configuration: JsonObject = JsonObject() protected open var traceLevel: String = "off" @@ -112,9 +111,13 @@ open class KolasuServer( protected open val uuid = mutableMapOf() override fun getTextDocumentService() = this + override fun getWorkspaceService() = this - open fun startCommunication(inputStream: InputStream = System.`in`, outputStream: OutputStream = System.out) { + open fun startCommunication( + inputStream: InputStream = System.`in`, + outputStream: OutputStream = System.out, + ) { val launcher = LSPLauncher.createServerLauncher(this, inputStream, outputStream) connect(launcher.remoteProxy) launcher.startListening() @@ -134,9 +137,20 @@ open class KolasuServer( val capabilities = ServerCapabilities() - capabilities.workspace = WorkspaceServerCapabilities(WorkspaceFoldersOptions().apply { supported = true; changeNotifications = Either.forLeft("didChangeWorkspaceFoldersRegistration"); }) - - capabilities.setTextDocumentSync(TextDocumentSyncOptions().apply { openClose = true; change = TextDocumentSyncKind.Full }) + capabilities.workspace = + WorkspaceServerCapabilities( + WorkspaceFoldersOptions().apply { + supported = true + changeNotifications = Either.forLeft("didChangeWorkspaceFoldersRegistration") + }, + ) + + capabilities.setTextDocumentSync( + TextDocumentSyncOptions().apply { + openClose = true + change = TextDocumentSyncKind.Full + }, + ) capabilities.setDocumentSymbolProvider(true) capabilities.setDefinitionProvider(this.enableDefinitionCapability) capabilities.setReferencesProvider(this.enableReferencesCapability) @@ -149,9 +163,31 @@ open class KolasuServer( for (folder in folders) { watchers.add(FileSystemWatcher(Either.forLeft(URI(folder).path + """/**/*{${extensions.joinToString(","){".$it"}}}"""))) } - client.registerCapability(RegistrationParams(listOf(Registration("workspace/didChangeWatchedFiles", "workspace/didChangeWatchedFiles", DidChangeWatchedFilesRegistrationOptions(watchers))))) - - client.registerCapability(RegistrationParams(listOf(Registration("workspace/didChangeConfiguration", "workspace/didChangeConfiguration", object { val section = language })))) + client.registerCapability( + RegistrationParams( + listOf( + Registration( + "workspace/didChangeWatchedFiles", + "workspace/didChangeWatchedFiles", + DidChangeWatchedFilesRegistrationOptions(watchers), + ), + ), + ), + ) + + client.registerCapability( + RegistrationParams( + listOf( + Registration( + "workspace/didChangeConfiguration", + "workspace/didChangeConfiguration", + object { + val section = language + }, + ), + ), + ), + ) } override fun didChangeConfiguration(params: DidChangeConfigurationParams?) { @@ -167,7 +203,9 @@ open class KolasuServer( commitIndex() client.createProgress(WorkDoneProgressCreateParams(Either.forLeft("indexing"))) - client.notifyProgress(ProgressParams(Either.forLeft("indexing"), Either.forLeft(WorkDoneProgressBegin().apply { title = "indexing" }))) + client.notifyProgress( + ProgressParams(Either.forLeft("indexing"), Either.forLeft(WorkDoneProgressBegin().apply { title = "indexing" })), + ) for (folder in folders) { val projectFiles = File(URI(folder)).walk().filter { extensions.contains(it.extension) }.toList() val totalBytes = projectFiles.sumOf { it.length() } @@ -176,7 +214,16 @@ open class KolasuServer( parse(file.toURI().toString(), Files.readString(file.toPath())) parsedBytes += file.length() val percentage = (parsedBytes * 100 / totalBytes).toInt() - client.notifyProgress(ProgressParams(Either.forLeft("indexing"), Either.forLeft(WorkDoneProgressReport().apply { this.percentage = percentage }))) + client.notifyProgress( + ProgressParams( + Either.forLeft("indexing"), + Either.forLeft( + WorkDoneProgressReport().apply { + this.percentage = percentage + }, + ), + ), + ) } } client.notifyProgress(ProgressParams(Either.forLeft("indexing"), Either.forLeft(WorkDoneProgressEnd()))) @@ -208,7 +255,10 @@ open class KolasuServer( parse(uri, text) } - open fun parse(uri: String, text: String) { + open fun parse( + uri: String, + text: String, + ) { if (!::indexWriter.isInitialized) return val parsingResult = parser?.parse(text) ?: return @@ -270,11 +320,27 @@ open class KolasuServer( if (node.children.isNotEmpty() || node.position == null) continue if (showASTWarnings && tree.findByPosition(node.position!!) != node) { - diagnostics.add(Diagnostic(toLSPRange(node.position!!), "Leaf type: ${node.simpleNodeType} but findByPositionType: ${tree.findByPosition(node.position!!)?.simpleNodeType}").apply { severity = DiagnosticSeverity.Warning }) + diagnostics.add( + Diagnostic( + toLSPRange(node.position!!), + "Leaf type: ${node.simpleNodeType} but findByPositionType: ${tree.findByPosition( + node.position!!, + )?.simpleNodeType}", + ).apply { + severity = DiagnosticSeverity.Warning + }, + ) } if (showLeafPositions) { - diagnostics.add(Diagnostic(toLSPRange(node.position!!), "Leaf position: ${node.position}, Source text: ${node.sourceText}").apply { severity = DiagnosticSeverity.Information }) + diagnostics.add( + Diagnostic( + toLSPRange(node.position!!), + "Leaf position: ${node.position}, Source text: ${node.sourceText}", + ).apply { + severity = DiagnosticSeverity.Information + }, + ) } } } @@ -301,7 +367,10 @@ open class KolasuServer( return CompletableFuture.completedFuture(mutableListOf(Either.forRight(namedTree))) } - protected open fun appendNamedChildren(node: Node, parent: DocumentSymbol) { + protected open fun appendNamedChildren( + node: Node, + parent: DocumentSymbol, + ) { var nextParent = parent if (node is PossiblyNamed && node.name != null) { val range = toLSPRange(node.position!!) @@ -322,11 +391,17 @@ open class KolasuServer( return SymbolKind.Variable } - override fun definition(params: DefinitionParams?): CompletableFuture, MutableList>> { + override fun definition( + params: DefinitionParams?, + ): CompletableFuture, MutableList>> { val document = getDocument(params) ?: return CompletableFuture.completedFuture(null) val symbolID = document.fields.find { it.name() == "reference" }?.stringValue() ?: return CompletableFuture.completedFuture(null) - val result = indexSearcher.search(TermQuery(Term("uuid", symbolID)), 1).scoreDocs.firstOrNull() ?: return CompletableFuture.completedFuture(null) + val result = + indexSearcher.search( + TermQuery(Term("uuid", symbolID)), + 1, + ).scoreDocs.firstOrNull() ?: return CompletableFuture.completedFuture(null) val definition = indexSearcher.storedFields().document(result.doc) if (definition.fields.none { it.name() == "startLine" }) return CompletableFuture.completedFuture(null) @@ -348,7 +423,11 @@ open class KolasuServer( } if (params?.context?.isIncludeDeclaration == true) { - val result = indexSearcher.search(TermQuery(Term("uuid", symbolID)), 1).scoreDocs.firstOrNull() ?: return CompletableFuture.completedFuture(null) + val result = + indexSearcher.search( + TermQuery(Term("uuid", symbolID)), + 1, + ).scoreDocs.firstOrNull() ?: return CompletableFuture.completedFuture(null) val definition = indexSearcher.storedFields().document(result.doc) list.add(toLSPLocation(definition)) @@ -362,13 +441,14 @@ open class KolasuServer( val uri = params?.textDocument?.uri ?: return null val position = params.position - val query = BooleanQuery.Builder() - .add(TermQuery(Term("uri", uri)), BooleanClause.Occur.MUST) - .add(IntPoint.newExactQuery("startLine", position.line + 1), BooleanClause.Occur.MUST) - .add(IntPoint.newExactQuery("endLine", position.line + 1), BooleanClause.Occur.MUST) - .add(IntPoint.newRangeQuery("startColumn", Int.MIN_VALUE, position.character), BooleanClause.Occur.MUST) - .add(IntPoint.newRangeQuery("endColumn", position.character, Int.MAX_VALUE), BooleanClause.Occur.MUST) - .build() + val query = + BooleanQuery.Builder() + .add(TermQuery(Term("uri", uri)), BooleanClause.Occur.MUST) + .add(IntPoint.newExactQuery("startLine", position.line + 1), BooleanClause.Occur.MUST) + .add(IntPoint.newExactQuery("endLine", position.line + 1), BooleanClause.Occur.MUST) + .add(IntPoint.newRangeQuery("startColumn", Int.MIN_VALUE, position.character), BooleanClause.Occur.MUST) + .add(IntPoint.newRangeQuery("endColumn", position.character, Int.MAX_VALUE), BooleanClause.Occur.MUST) + .build() val sortingField = SortedNumericSortField("size", SortField.Type.INT, true) val results = indexSearcher.search(query, 100, Sort(sortingField)) @@ -386,7 +466,11 @@ open class KolasuServer( protected open fun toLSPLocation(document: Document): Location { val uri = document.get("uri") - val range = Range(Position(document.get("startLine").toInt() - 1, document.get("startColumn").toInt()), Position(document.get("endLine").toInt() - 1, document.get("endColumn").toInt())) + val range = + Range( + Position(document.get("startLine").toInt() - 1, document.get("startColumn").toInt()), + Position(document.get("endLine").toInt() - 1, document.get("endColumn").toInt()), + ) return Location(uri, range) } @@ -446,21 +530,32 @@ open class KolasuServer( exitProcess(0) } - protected open fun log(text: String, verboseExplanation: String? = null) { + protected open fun log( + text: String, + verboseExplanation: String? = null, + ) { client.logTrace(LogTraceParams(text, verboseExplanation)) } - protected open fun showNotification(text: String, messageType: MessageType = MessageType.Info) { + protected open fun showNotification( + text: String, + messageType: MessageType = MessageType.Info, + ) { client.showMessage(MessageParams(messageType, text)) } - protected open fun askClient(messageText: String, options: List = listOf("Yes", "No"), messageType: MessageType = MessageType.Info): CompletableFuture { + protected open fun askClient( + messageText: String, + options: List = listOf("Yes", "No"), + messageType: MessageType = MessageType.Info, + ): CompletableFuture { val future = CompletableFuture() - val request = ShowMessageRequestParams(options.map { MessageActionItem(it) }).apply { - type = messageType - message = messageText - } + val request = + ShowMessageRequestParams(options.map { MessageActionItem(it) }).apply { + type = messageType + message = messageText + } client.showMessageRequest(request).thenApply { item -> future.complete(item.title) } @@ -475,9 +570,15 @@ open class KolasuServer( } interface CodeGenerator { - fun generate(tree: T, uri: String) + fun generate( + tree: T, + uri: String, + ) } interface SymbolResolver { - fun resolveSymbols(tree: Node?, uri: String) + fun resolveSymbols( + tree: Node?, + uri: String, + ) } diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 7b0fa33..0d039ac 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -4,6 +4,7 @@ plugins { id("maven-publish") id("java-gradle-plugin") id("com.gradle.plugin-publish") version "1.2.1" + id("com.github.gmazzo.buildconfig") version "5.3.5" } repositories { @@ -11,9 +12,15 @@ repositories { gradlePluginPortal() } +val kotlinVersion: String by project +val kolasuVersion: String by project +val luceneVersion: String by project +val lsp4jVersion: String by project +val junitVersion: String by project + dependencies { implementation("com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:7.1.2") - implementation("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.6.0-M1") + implementation("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:$kotlinVersion") } gradlePlugin { @@ -30,3 +37,19 @@ gradlePlugin { } } } + +buildConfig { + packageName = "com.strumenta.kolasu.languageserver.plugin" + buildConfigField("KOLASU_LSP_VERSION", "${project.version}") + buildConfigField("KOLASU_VERSION", kolasuVersion) + buildConfigField("LUCENE_VERSION", luceneVersion) + buildConfigField("LSP4J_VERSION", lsp4jVersion) + buildConfigField("JUNIT_VERSION", junitVersion) +} + +ktlint { + version = "1.2.1" + filter { + exclude("**/generated/**") + } +} diff --git a/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt b/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt index 69d69c5..c32ce17 100644 --- a/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt +++ b/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt @@ -11,10 +11,9 @@ import org.jetbrains.kotlin.konan.file.File import java.nio.file.Files import java.nio.file.Paths import java.nio.file.StandardCopyOption -import java.util.* +import java.util.Locale class LanguageServerPlugin : Plugin { - private lateinit var configuration: Configuration override fun apply(project: Project?) { @@ -28,15 +27,15 @@ class LanguageServerPlugin : Plugin { if (project.rootProject.subprojects.any { it.name == "ast" }) { project.dependencies.add("implementation", project.dependencies.project(mapOf("path" to ":ast"))) } - project.dependencies.add("implementation", "com.strumenta.kolasu:language-server:${project.version}") - project.dependencies.add("implementation", "com.strumenta.kolasu:kolasu-core:1.5.31") - project.dependencies.add("implementation", "org.eclipse.lsp4j:org.eclipse.lsp4j:0.21.1") - project.dependencies.add("implementation", "org.apache.lucene:lucene-core:9.8.0") - project.dependencies.add("implementation", "org.apache.lucene:lucene-codecs:9.8.0") - project.dependencies.add("implementation", "org.apache.lucene:lucene-queryparser:9.8.0") + project.dependencies.add("implementation", "com.strumenta.kolasu:language-server:${BuildConfig.KOLASU_LSP_VERSION}") + project.dependencies.add("implementation", "com.strumenta.kolasu:kolasu-core:${BuildConfig.KOLASU_VERSION}") + project.dependencies.add("implementation", "org.eclipse.lsp4j:org.eclipse.lsp4j:${BuildConfig.LSP4J_VERSION}") + project.dependencies.add("implementation", "org.apache.lucene:lucene-core:${BuildConfig.LUCENE_VERSION}") + project.dependencies.add("implementation", "org.apache.lucene:lucene-codecs:${BuildConfig.LUCENE_VERSION}") + project.dependencies.add("implementation", "org.apache.lucene:lucene-queryparser:${BuildConfig.LUCENE_VERSION}") - project.dependencies.add("testImplementation", "com.strumenta.kolasu:language-server-testing:${project.version}") - project.dependencies.add("testImplementation", "org.junit.jupiter:junit-jupiter:5.+") + project.dependencies.add("testImplementation", "com.strumenta.kolasu:language-server-testing:${BuildConfig.KOLASU_LSP_VERSION}") + project.dependencies.add("testImplementation", "org.junit.jupiter:junit-jupiter:${BuildConfig.JUNIT_VERSION}") val projectPath = project.projectDir.toString() val language = project.rootProject.name @@ -52,7 +51,18 @@ class LanguageServerPlugin : Plugin { configuration.textmateGrammarScope = "main" configuration.serverJarPath = Paths.get(projectPath, "build", "libs", "$language.jar") configuration.examplesPath = Paths.get(project.rootDir.toString(), "examples") - configuration.entryPointPath = Paths.get(projectPath, "src", "main", "kotlin", "com", "strumenta", language, "languageserver", "Main.kt") + configuration.entryPointPath = + Paths.get( + projectPath, + "src", + "main", + "kotlin", + "com", + "strumenta", + language, + "languageserver", + "Main.kt", + ) configuration.textmateGrammarPath = Paths.get(projectPath, "src", "main", "resources", "grammar.tmLanguage") configuration.logoPath = Paths.get(projectPath, "src", "main", "resources", "logo.png") configuration.fileIconPath = Paths.get(projectPath, "src", "main", "resources", "fileIcon.png") @@ -64,7 +74,8 @@ class LanguageServerPlugin : Plugin { val shadowJar = project.tasks.getByName("shadowJar") as ShadowJar shadowJar.manifest.attributes["Main-Class"] = "com.strumenta.$language.languageserver.MainKt" shadowJar.manifest.attributes["Multi-Release"] = "true" - shadowJar.manifest.attributes["Class-Path"] = "lucene-core-9.8.0.jar lucene-codecs-9.8.0.jar" + shadowJar.manifest.attributes["Class-Path"] = + "lucene-core-${BuildConfig.LUCENE_VERSION}.jar lucene-codecs-${BuildConfig.LUCENE_VERSION}.jar" shadowJar.archiveFileName.set("$language.jar") shadowJar.excludes.add("org/apache/lucene/**/*") @@ -79,22 +90,55 @@ class LanguageServerPlugin : Plugin { project.tasks.create("launchVscodeEditor").apply { group = "language server" description = "Launch the configured vscode editor with the language server installed (defaults to code)" - actions = listOf(Action { _ -> try { launchVscodeEditor(project) } catch (exception: Exception) { System.err.println(exception.message) } }) + actions = + listOf( + Action { + _ -> + try { + launchVscodeEditor(project) + } catch (exception: Exception) { + System.err.println(exception.message) + } + }, + ) dependsOn(project.tasks.getByName("createVscodeExtension")) } } private fun launchVscodeEditor(project: Project) { - ProcessBuilder(configuration.editor, "--extensionDevelopmentPath", "${project.projectDir}${File.separator}build${File.separator}vscode", configuration.examplesPath.toString()).directory(project.projectDir).start().waitFor() + ProcessBuilder( + configuration.editor, + "--extensionDevelopmentPath", + "${project.projectDir}${File.separator}build${File.separator}vscode", + configuration.examplesPath.toString(), + ).directory(project.projectDir).start().waitFor() } private fun addCreateVscodeExtensionTask(project: Project) { project.tasks.create("createVscodeExtension").apply { group = "language server" description = "Create language server extension folder for vscode under build/vscode" - actions = listOf(Action { _ -> try { createVscodeExtension(project) } catch (exception: Exception) { System.err.println(exception.message) } }) + actions = + listOf( + Action { + _ -> + try { + createVscodeExtension(project) + } catch (exception: Exception) { + System.err.println(exception.message) + } + }, + ) dependsOn(project.tasks.getByName("shadowJar")) - inputs.files(configuration.entryPointPath, configuration.textmateGrammarPath, configuration.logoPath, configuration.fileIconPath, configuration.languageClientPath, configuration.packageDefinitionPath, configuration.licensePath).optional() + inputs.files( + configuration.entryPointPath, + configuration.textmateGrammarPath, + configuration.logoPath, + configuration.fileIconPath, + configuration.languageClientPath, + configuration.packageDefinitionPath, + configuration.licensePath, + ).optional() outputs.dirs(configuration.outputPath) } } @@ -102,6 +146,7 @@ class LanguageServerPlugin : Plugin { fun isWindows(): Boolean { return System.getProperty("os.name").toLowerCase().contains("win") } + private fun createVscodeExtension(project: Project) { val shadowJar = project.tasks.getByName("shadowJar") as ShadowJar val entryPoint = shadowJar.manifest.attributes["Main-Class"] as String @@ -112,17 +157,19 @@ class LanguageServerPlugin : Plugin { configuration.entryPointPath, """ package com.strumenta.${configuration.language}.languageserver - + import com.strumenta.${configuration.language}.parser.${configuration.language.capitalized()}KolasuParser import com.strumenta.kolasu.languageserver.KolasuServer - + fun main() { val parser = ${configuration.language.capitalized()}KolasuParser() - val server = KolasuServer(parser, "${configuration.language}", listOf(${configuration.fileExtensions.joinToString(",") { "\"$it\"" }})) + val server = KolasuServer(parser, "${configuration.language}", listOf(${configuration.fileExtensions.joinToString( + ",", + ) { "\"$it\"" }})) server.startCommunication() } - """.trimIndent() + """.trimIndent(), ) } } @@ -130,17 +177,22 @@ class LanguageServerPlugin : Plugin { Files.createDirectories(configuration.outputPath) if (Files.exists(configuration.packageDefinitionPath)) { - Files.copy(configuration.packageDefinitionPath, Paths.get(configuration.outputPath.toString(), "package.json"), StandardCopyOption.REPLACE_EXISTING) + Files.copy( + configuration.packageDefinitionPath, + Paths.get(configuration.outputPath.toString(), "package.json"), + StandardCopyOption.REPLACE_EXISTING, + ) } else { var grammars = "" if (Files.exists(configuration.textmateGrammarPath)) { - grammars = """ - , - "grammars": - [ - {"language": "${configuration.language}", "scopeName": "${configuration.textmateGrammarScope}", "path": "./grammar.tmLanguage"} - ] - """.trimIndent() + grammars = + """ + , + "grammars": + [ + {"language": "${configuration.language}", "scopeName": "${configuration.textmateGrammarScope}", "path": "./grammar.tmLanguage"} + ] + """.trimIndent() } var logo = "" @@ -165,7 +217,9 @@ class LanguageServerPlugin : Plugin { { "languages": [ - {"id": "${configuration.language}", "extensions": ["${configuration.fileExtensions.joinToString("\", \""){ ".$it" }}"]$fileIcon} + {"id": "${configuration.language}", "extensions": ["${configuration.fileExtensions.joinToString( + "\", \"", + ){ ".$it" }}"]$fileIcon} ], "configuration": { "title": "${configuration.language.capitalized()}", @@ -192,51 +246,81 @@ class LanguageServerPlugin : Plugin { "activationEvents": ["onLanguage:${configuration.language}"], "main": "client.js" } - """.trimIndent() + """.trimIndent(), ) } if (Files.exists(configuration.languageClientPath)) { - Files.copy(configuration.languageClientPath, Paths.get(configuration.outputPath.toString(), "client.js"), StandardCopyOption.REPLACE_EXISTING) + Files.copy( + configuration.languageClientPath, + Paths.get(configuration.outputPath.toString(), "client.js"), + StandardCopyOption.REPLACE_EXISTING, + ) } else { Files.writeString( Paths.get(configuration.outputPath.toString(), "client.js"), """ let {LanguageClient} = require("./node_modules/vscode-languageclient/node"); - + async function activate (context) { let productionServer = {run: {command: "java", args: ["-jar", context.asAbsolutePath("server.jar")]}}; - + let languageClient = new LanguageClient("${configuration.language}", "${configuration.language} language server", productionServer, {documentSelector: ["${configuration.language}"]}); await languageClient.start(); - + context.subscriptions.push(languageClient); } - + module.exports = {activate}; - """.trimIndent() + """.trimIndent(), ) } - Files.copy(configuration.serverJarPath, Paths.get(configuration.outputPath.toString(), "server.jar"), StandardCopyOption.REPLACE_EXISTING) + Files.copy( + configuration.serverJarPath, + Paths.get(configuration.outputPath.toString(), "server.jar"), + StandardCopyOption.REPLACE_EXISTING, + ) val npm = if (isWindows()) "npm.cmd" else "npm" val npx = if (isWindows()) "npx.cmd" else "npx" ProcessBuilder(npm, "install", "--prefix", "build/vscode/", "vscode-languageclient").directory(project.projectDir).start().waitFor() - ProcessBuilder(npx, "esbuild", "build/vscode/client.js", "--bundle", "--external:vscode", "--format=cjs", "--platform=node", "--outfile=build/vscode/client.js", "--allow-overwrite").directory(project.projectDir).start().waitFor() + ProcessBuilder( + npx, + "esbuild", + "build/vscode/client.js", + "--bundle", + "--external:vscode", + "--format=cjs", + "--platform=node", + "--outfile=build/vscode/client.js", + "--allow-overwrite", + ).directory(project.projectDir).start().waitFor() if (Files.exists(configuration.textmateGrammarPath)) { - Files.copy(configuration.textmateGrammarPath, Paths.get(configuration.outputPath.toString(), "grammar.tmLanguage"), StandardCopyOption.REPLACE_EXISTING) + Files.copy( + configuration.textmateGrammarPath, + Paths.get(configuration.outputPath.toString(), "grammar.tmLanguage"), + StandardCopyOption.REPLACE_EXISTING, + ) } if (Files.exists(configuration.logoPath)) { - Files.copy(configuration.logoPath, Paths.get(configuration.outputPath.toString(), "logo.png"), StandardCopyOption.REPLACE_EXISTING) + Files.copy( + configuration.logoPath, + Paths.get(configuration.outputPath.toString(), "logo.png"), + StandardCopyOption.REPLACE_EXISTING, + ) } if (Files.exists(configuration.fileIconPath)) { - Files.copy(configuration.fileIconPath, Paths.get(configuration.outputPath.toString(), "fileIcon.png"), StandardCopyOption.REPLACE_EXISTING) + Files.copy( + configuration.fileIconPath, + Paths.get(configuration.outputPath.toString(), "fileIcon.png"), + StandardCopyOption.REPLACE_EXISTING, + ) } if (Files.exists(configuration.licensePath)) { @@ -244,8 +328,18 @@ class LanguageServerPlugin : Plugin { } else { Files.writeString(Paths.get(configuration.outputPath.toString(), "LICENSE.md"), "Copyright Strumenta SRL") } - ProcessBuilder("curl", "https://repo1.maven.org/maven2/org/apache/lucene/lucene-core/9.8.0/lucene-core-9.8.0.jar", "-o", Paths.get(configuration.outputPath.toString(), "lucene-core-9.8.0.jar").toString()).start().waitFor() - ProcessBuilder("curl", "https://repo1.maven.org/maven2/org/apache/lucene/lucene-codecs/9.8.0/lucene-codecs-9.8.0.jar", "-o", Paths.get(configuration.outputPath.toString(), "lucene-codecs-9.8.0.jar").toString()).start().waitFor() + ProcessBuilder( + "curl", + "https://repo1.maven.org/maven2/org/apache/lucene/lucene-core/9.8.0/lucene-core-9.8.0.jar", + "-o", + Paths.get(configuration.outputPath.toString(), "lucene-core-9.8.0.jar").toString(), + ).start().waitFor() + ProcessBuilder( + "curl", + "https://repo1.maven.org/maven2/org/apache/lucene/lucene-codecs/9.8.0/lucene-codecs-9.8.0.jar", + "-o", + Paths.get(configuration.outputPath.toString(), "lucene-codecs-9.8.0.jar").toString(), + ).start().waitFor() ProcessBuilder(npx, "vsce@2.15", "package").directory(configuration.outputPath.toFile()).start().waitFor() } diff --git a/testing/build.gradle.kts b/testing/build.gradle.kts index ad7c8ff..6be752f 100644 --- a/testing/build.gradle.kts +++ b/testing/build.gradle.kts @@ -11,11 +11,15 @@ repositories { mavenCentral() } +val kolasuVersion: String by project +val lsp4jVersion: String by project +val junitVersion: String by project + dependencies { implementation(project(":kolasu-languageserver-library")) - implementation("com.strumenta.kolasu:kolasu-core:1.5.31") - implementation("org.eclipse.lsp4j:org.eclipse.lsp4j:0.21.1") - implementation("org.junit.jupiter:junit-jupiter-api:5.7.1") + implementation("com.strumenta.kolasu:kolasu-core:$kolasuVersion") + implementation("org.eclipse.lsp4j:org.eclipse.lsp4j:$lsp4jVersion") + implementation("org.junit.jupiter:junit-jupiter-api:$junitVersion") } java { @@ -78,3 +82,7 @@ publishing { signing { sign(publishing.publications.getByName("language-server-testing")) } + +ktlint { + version = "1.2.1" +} diff --git a/testing/src/main/kotlin/testing/DiagnosticListenerClient.kt b/testing/src/main/kotlin/testing/DiagnosticListenerClient.kt index da60c70..79840ae 100644 --- a/testing/src/main/kotlin/testing/DiagnosticListenerClient.kt +++ b/testing/src/main/kotlin/testing/DiagnosticListenerClient.kt @@ -11,7 +11,6 @@ import org.eclipse.lsp4j.services.LanguageClient import java.util.concurrent.CompletableFuture class DiagnosticListenerClient(private val onDiagnosticPublished: (PublishDiagnosticsParams) -> Unit) : LanguageClient { - override fun publishDiagnostics(diagnostics: PublishDiagnosticsParams?) { diagnostics?.let(onDiagnosticPublished) } @@ -19,15 +18,20 @@ class DiagnosticListenerClient(private val onDiagnosticPublished: (PublishDiagno override fun showMessageRequest(requestParams: ShowMessageRequestParams?): CompletableFuture { return CompletableFuture.completedFuture(null) } + override fun registerCapability(params: RegistrationParams?): CompletableFuture { return CompletableFuture.completedFuture(null) } + override fun createProgress(params: WorkDoneProgressCreateParams?): CompletableFuture { return CompletableFuture.completedFuture(null) } override fun notifyProgress(params: ProgressParams?) {} + override fun telemetryEvent(message: Any?) {} + override fun logMessage(message: MessageParams?) {} + override fun showMessage(message: MessageParams?) {} } diff --git a/testing/src/main/kotlin/testing/TestKolasuServer.kt b/testing/src/main/kotlin/testing/TestKolasuServer.kt index 409ede3..ec4cf24 100644 --- a/testing/src/main/kotlin/testing/TestKolasuServer.kt +++ b/testing/src/main/kotlin/testing/TestKolasuServer.kt @@ -37,9 +37,8 @@ open class TestKolasuServer( protected open var codeGenerator: CodeGenerator? = null, protected open var language: String = "languageserver", protected open var fileExtensions: List = listOf(), - protected open var workspacePath: Path = Paths.get("src", "test", "resources") + protected open var workspacePath: Path = Paths.get("src", "test", "resources"), ) { - protected open lateinit var server: KolasuServer @BeforeEach @@ -64,18 +63,24 @@ open class TestKolasuServer( server.connect( DiagnosticListenerClient { assertEquals(amount, it.diagnostics.size) - } + }, ) } - protected open fun open(uri: String, text: String) { + protected open fun open( + uri: String, + text: String, + ) { val textDocument = TextDocumentItem(uri, "", 0, text) val parameters = DidOpenTextDocumentParams(textDocument) server.didOpen(parameters) } - protected open fun change(uri: String, text: String) { + protected open fun change( + uri: String, + text: String, + ) { val document = VersionedTextDocumentIdentifier(uri, null) val changes = listOf(TextDocumentContentChangeEvent(text)) val parameters = DidChangeTextDocumentParams(document, changes) @@ -90,21 +95,31 @@ open class TestKolasuServer( return server.documentSymbol(parameters).get()?.first()?.right } - protected open fun definition(uri: String, position: Position): Location? { + protected open fun definition( + uri: String, + position: Position, + ): Location? { val document = TextDocumentIdentifier(uri) val parameters = DefinitionParams(document, position) return server.definition(parameters).get()?.left?.first() } - protected open fun references(uri: String, position: Position, includeDeclaration: Boolean = true): MutableList? { + protected open fun references( + uri: String, + position: Position, + includeDeclaration: Boolean = true, + ): MutableList? { val document = TextDocumentIdentifier(uri) val parameters = ReferenceParams(document, position, ReferenceContext(includeDeclaration)) return server.references(parameters).get() } - protected fun requestAtEachPositionInResourceFiles(name: String, request: (String, Position) -> Unit): List { + protected fun requestAtEachPositionInResourceFiles( + name: String, + request: (String, Position) -> Unit, + ): List { val timings = mutableListOf() for (file in Files.list(workspacePath)) { From d719d0315ec1fa772e1f6e4e5d934799c2a1419e Mon Sep 17 00:00:00 2001 From: Lorenzo Addazi Date: Mon, 11 Mar 2024 10:50:10 +0100 Subject: [PATCH 2/3] style: fixed ktlint violations ignoring build/generated folder Signed-off-by: Lorenzo Addazi --- plugin/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 0d039ac..ee7e787 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -50,6 +50,6 @@ buildConfig { ktlint { version = "1.2.1" filter { - exclude("**/generated/**") + exclude { it.file.path.contains(layout.buildDirectory.dir("generated").get().toString()) } } } From a22b78530dc0550bc68c253b4aeacadf03027356 Mon Sep 17 00:00:00 2001 From: Lorenzo Addazi Date: Mon, 11 Mar 2024 12:59:17 +0100 Subject: [PATCH 3/3] build: adds version catalogs to centralize versions (could be migrated to .toml in the future) Signed-off-by: Lorenzo Addazi --- build.gradle.kts | 5 +- library/build.gradle.kts | 24 ++----- .../kolasu/languageserver/KolasuServer.kt | 64 +++++++++---------- plugin/build.gradle.kts | 27 +++----- .../plugin/LanguageServerPlugin.kt | 38 +++++------ settings.gradle.kts | 33 ++++++++++ testing/build.gradle.kts | 22 ++----- .../main/kotlin/testing/TestKolasuServer.kt | 14 ++-- 8 files changed, 117 insertions(+), 110 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 89a9ee0..cccd800 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,16 +1,15 @@ plugins { - id("net.researchgate.release") version "3.0.2" + alias(libs.plugins.release) } allprojects { group = "com.strumenta.kolasu.languageserver" } - release { buildTasks.set(listOf(":kolasu-languageserver-library:publish", ":kolasu-languageserver-testing:publish", ":kolasu-languageserver-plugin:publishPlugins")) git { requireBranch.set("") pushToRemote.set("origin") } -} +} \ No newline at end of file diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 287708a..e3a60a4 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -1,26 +1,20 @@ import java.net.URI plugins { - id("org.jetbrains.kotlin.jvm") version "1.8.22" - id("org.jlleitschuh.gradle.ktlint") version "11.6.0" - id("maven-publish") - id("signing") + alias(libs.plugins.kotlin.jvm) + `maven-publish` + signing } repositories { mavenCentral() } -val kotlinVersion: String by project -val kolasuVersion: String by project -val lsp4jVersion: String by project -val luceneVersion: String by project - dependencies { - implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") - implementation("com.strumenta.kolasu:kolasu-core:$kolasuVersion") - implementation("org.eclipse.lsp4j:org.eclipse.lsp4j:$lsp4jVersion") - implementation("org.apache.lucene:lucene-core:$luceneVersion") + implementation(libs.kotlin.reflect) + implementation(libs.kolasu.core) + implementation(libs.lsp4j) + implementation(libs.lucene) } java { @@ -83,7 +77,3 @@ publishing { signing { sign(publishing.publications.getByName("language-server-library")) } - -ktlint { - version = "1.2.1" -} diff --git a/library/src/main/kotlin/com/strumenta/kolasu/languageserver/KolasuServer.kt b/library/src/main/kotlin/com/strumenta/kolasu/languageserver/KolasuServer.kt index 8ebce87..0d7e4cc 100644 --- a/library/src/main/kotlin/com/strumenta/kolasu/languageserver/KolasuServer.kt +++ b/library/src/main/kotlin/com/strumenta/kolasu/languageserver/KolasuServer.kt @@ -98,7 +98,7 @@ open class KolasuServer( protected open val extensions: List = listOf(), protected open val enableDefinitionCapability: Boolean = false, protected open val enableReferencesCapability: Boolean = false, - protected open val generator: CodeGenerator? = null, + protected open val generator: CodeGenerator? = null ) : LanguageServer, TextDocumentService, WorkspaceService, LanguageClientAware { protected open lateinit var client: LanguageClient protected open var configuration: JsonObject = JsonObject() @@ -116,7 +116,7 @@ open class KolasuServer( open fun startCommunication( inputStream: InputStream = System.`in`, - outputStream: OutputStream = System.out, + outputStream: OutputStream = System.out ) { val launcher = LSPLauncher.createServerLauncher(this, inputStream, outputStream) connect(launcher.remoteProxy) @@ -142,14 +142,14 @@ open class KolasuServer( WorkspaceFoldersOptions().apply { supported = true changeNotifications = Either.forLeft("didChangeWorkspaceFoldersRegistration") - }, + } ) capabilities.setTextDocumentSync( TextDocumentSyncOptions().apply { openClose = true change = TextDocumentSyncKind.Full - }, + } ) capabilities.setDocumentSymbolProvider(true) capabilities.setDefinitionProvider(this.enableDefinitionCapability) @@ -169,10 +169,10 @@ open class KolasuServer( Registration( "workspace/didChangeWatchedFiles", "workspace/didChangeWatchedFiles", - DidChangeWatchedFilesRegistrationOptions(watchers), - ), - ), - ), + DidChangeWatchedFilesRegistrationOptions(watchers) + ) + ) + ) ) client.registerCapability( @@ -183,10 +183,10 @@ open class KolasuServer( "workspace/didChangeConfiguration", object { val section = language - }, - ), - ), - ), + } + ) + ) + ) ) } @@ -204,7 +204,7 @@ open class KolasuServer( client.createProgress(WorkDoneProgressCreateParams(Either.forLeft("indexing"))) client.notifyProgress( - ProgressParams(Either.forLeft("indexing"), Either.forLeft(WorkDoneProgressBegin().apply { title = "indexing" })), + ProgressParams(Either.forLeft("indexing"), Either.forLeft(WorkDoneProgressBegin().apply { title = "indexing" })) ) for (folder in folders) { val projectFiles = File(URI(folder)).walk().filter { extensions.contains(it.extension) }.toList() @@ -220,9 +220,9 @@ open class KolasuServer( Either.forLeft( WorkDoneProgressReport().apply { this.percentage = percentage - }, - ), - ), + } + ) + ) ) } } @@ -257,7 +257,7 @@ open class KolasuServer( open fun parse( uri: String, - text: String, + text: String ) { if (!::indexWriter.isInitialized) return @@ -324,11 +324,11 @@ open class KolasuServer( Diagnostic( toLSPRange(node.position!!), "Leaf type: ${node.simpleNodeType} but findByPositionType: ${tree.findByPosition( - node.position!!, - )?.simpleNodeType}", + node.position!! + )?.simpleNodeType}" ).apply { severity = DiagnosticSeverity.Warning - }, + } ) } @@ -336,10 +336,10 @@ open class KolasuServer( diagnostics.add( Diagnostic( toLSPRange(node.position!!), - "Leaf position: ${node.position}, Source text: ${node.sourceText}", + "Leaf position: ${node.position}, Source text: ${node.sourceText}" ).apply { severity = DiagnosticSeverity.Information - }, + } ) } } @@ -369,7 +369,7 @@ open class KolasuServer( protected open fun appendNamedChildren( node: Node, - parent: DocumentSymbol, + parent: DocumentSymbol ) { var nextParent = parent if (node is PossiblyNamed && node.name != null) { @@ -392,7 +392,7 @@ open class KolasuServer( } override fun definition( - params: DefinitionParams?, + params: DefinitionParams? ): CompletableFuture, MutableList>> { val document = getDocument(params) ?: return CompletableFuture.completedFuture(null) @@ -400,7 +400,7 @@ open class KolasuServer( val result = indexSearcher.search( TermQuery(Term("uuid", symbolID)), - 1, + 1 ).scoreDocs.firstOrNull() ?: return CompletableFuture.completedFuture(null) val definition = indexSearcher.storedFields().document(result.doc) @@ -426,7 +426,7 @@ open class KolasuServer( val result = indexSearcher.search( TermQuery(Term("uuid", symbolID)), - 1, + 1 ).scoreDocs.firstOrNull() ?: return CompletableFuture.completedFuture(null) val definition = indexSearcher.storedFields().document(result.doc) @@ -469,7 +469,7 @@ open class KolasuServer( val range = Range( Position(document.get("startLine").toInt() - 1, document.get("startColumn").toInt()), - Position(document.get("endLine").toInt() - 1, document.get("endColumn").toInt()), + Position(document.get("endLine").toInt() - 1, document.get("endColumn").toInt()) ) return Location(uri, range) } @@ -532,14 +532,14 @@ open class KolasuServer( protected open fun log( text: String, - verboseExplanation: String? = null, + verboseExplanation: String? = null ) { client.logTrace(LogTraceParams(text, verboseExplanation)) } protected open fun showNotification( text: String, - messageType: MessageType = MessageType.Info, + messageType: MessageType = MessageType.Info ) { client.showMessage(MessageParams(messageType, text)) } @@ -547,7 +547,7 @@ open class KolasuServer( protected open fun askClient( messageText: String, options: List = listOf("Yes", "No"), - messageType: MessageType = MessageType.Info, + messageType: MessageType = MessageType.Info ): CompletableFuture { val future = CompletableFuture() @@ -572,13 +572,13 @@ open class KolasuServer( interface CodeGenerator { fun generate( tree: T, - uri: String, + uri: String ) } interface SymbolResolver { fun resolveSymbols( tree: Node?, - uri: String, + uri: String ) } diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index ee7e787..151c0cd 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -1,8 +1,8 @@ plugins { - id("org.jetbrains.kotlin.jvm") version "1.8.22" - id("org.jlleitschuh.gradle.ktlint") version "11.6.0" - id("maven-publish") - id("java-gradle-plugin") + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.ktlint) + `maven-publish` + `java-gradle-plugin` id("com.gradle.plugin-publish") version "1.2.1" id("com.github.gmazzo.buildconfig") version "5.3.5" } @@ -12,15 +12,9 @@ repositories { gradlePluginPortal() } -val kotlinVersion: String by project -val kolasuVersion: String by project -val luceneVersion: String by project -val lsp4jVersion: String by project -val junitVersion: String by project - dependencies { - implementation("com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:7.1.2") - implementation("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:$kotlinVersion") + implementation(libs.shadow) + implementation(libs.kotlin.jvm) } gradlePlugin { @@ -41,14 +35,13 @@ gradlePlugin { buildConfig { packageName = "com.strumenta.kolasu.languageserver.plugin" buildConfigField("KOLASU_LSP_VERSION", "${project.version}") - buildConfigField("KOLASU_VERSION", kolasuVersion) - buildConfigField("LUCENE_VERSION", luceneVersion) - buildConfigField("LSP4J_VERSION", lsp4jVersion) - buildConfigField("JUNIT_VERSION", junitVersion) + buildConfigField("KOLASU_VERSION", libs.versions.kolasu) + buildConfigField("LUCENE_VERSION", libs.versions.lucene) + buildConfigField("LSP4J_VERSION", libs.versions.lsp4j) + buildConfigField("JUNIT_VERSION", libs.versions.junit5) } ktlint { - version = "1.2.1" filter { exclude { it.file.path.contains(layout.buildDirectory.dir("generated").get().toString()) } } diff --git a/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt b/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt index c32ce17..8164d71 100644 --- a/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt +++ b/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt @@ -61,7 +61,7 @@ class LanguageServerPlugin : Plugin { "strumenta", language, "languageserver", - "Main.kt", + "Main.kt" ) configuration.textmateGrammarPath = Paths.get(projectPath, "src", "main", "resources", "grammar.tmLanguage") configuration.logoPath = Paths.get(projectPath, "src", "main", "resources", "logo.png") @@ -99,7 +99,7 @@ class LanguageServerPlugin : Plugin { } catch (exception: Exception) { System.err.println(exception.message) } - }, + } ) dependsOn(project.tasks.getByName("createVscodeExtension")) } @@ -110,7 +110,7 @@ class LanguageServerPlugin : Plugin { configuration.editor, "--extensionDevelopmentPath", "${project.projectDir}${File.separator}build${File.separator}vscode", - configuration.examplesPath.toString(), + configuration.examplesPath.toString() ).directory(project.projectDir).start().waitFor() } @@ -127,7 +127,7 @@ class LanguageServerPlugin : Plugin { } catch (exception: Exception) { System.err.println(exception.message) } - }, + } ) dependsOn(project.tasks.getByName("shadowJar")) inputs.files( @@ -137,7 +137,7 @@ class LanguageServerPlugin : Plugin { configuration.fileIconPath, configuration.languageClientPath, configuration.packageDefinitionPath, - configuration.licensePath, + configuration.licensePath ).optional() outputs.dirs(configuration.outputPath) } @@ -165,11 +165,11 @@ class LanguageServerPlugin : Plugin { val parser = ${configuration.language.capitalized()}KolasuParser() val server = KolasuServer(parser, "${configuration.language}", listOf(${configuration.fileExtensions.joinToString( - ",", + "," ) { "\"$it\"" }})) server.startCommunication() } - """.trimIndent(), + """.trimIndent() ) } } @@ -180,7 +180,7 @@ class LanguageServerPlugin : Plugin { Files.copy( configuration.packageDefinitionPath, Paths.get(configuration.outputPath.toString(), "package.json"), - StandardCopyOption.REPLACE_EXISTING, + StandardCopyOption.REPLACE_EXISTING ) } else { var grammars = "" @@ -218,7 +218,7 @@ class LanguageServerPlugin : Plugin { "languages": [ {"id": "${configuration.language}", "extensions": ["${configuration.fileExtensions.joinToString( - "\", \"", + "\", \"" ){ ".$it" }}"]$fileIcon} ], "configuration": { @@ -246,7 +246,7 @@ class LanguageServerPlugin : Plugin { "activationEvents": ["onLanguage:${configuration.language}"], "main": "client.js" } - """.trimIndent(), + """.trimIndent() ) } @@ -254,7 +254,7 @@ class LanguageServerPlugin : Plugin { Files.copy( configuration.languageClientPath, Paths.get(configuration.outputPath.toString(), "client.js"), - StandardCopyOption.REPLACE_EXISTING, + StandardCopyOption.REPLACE_EXISTING ) } else { Files.writeString( @@ -273,14 +273,14 @@ class LanguageServerPlugin : Plugin { } module.exports = {activate}; - """.trimIndent(), + """.trimIndent() ) } Files.copy( configuration.serverJarPath, Paths.get(configuration.outputPath.toString(), "server.jar"), - StandardCopyOption.REPLACE_EXISTING, + StandardCopyOption.REPLACE_EXISTING ) val npm = if (isWindows()) "npm.cmd" else "npm" @@ -296,14 +296,14 @@ class LanguageServerPlugin : Plugin { "--format=cjs", "--platform=node", "--outfile=build/vscode/client.js", - "--allow-overwrite", + "--allow-overwrite" ).directory(project.projectDir).start().waitFor() if (Files.exists(configuration.textmateGrammarPath)) { Files.copy( configuration.textmateGrammarPath, Paths.get(configuration.outputPath.toString(), "grammar.tmLanguage"), - StandardCopyOption.REPLACE_EXISTING, + StandardCopyOption.REPLACE_EXISTING ) } @@ -311,7 +311,7 @@ class LanguageServerPlugin : Plugin { Files.copy( configuration.logoPath, Paths.get(configuration.outputPath.toString(), "logo.png"), - StandardCopyOption.REPLACE_EXISTING, + StandardCopyOption.REPLACE_EXISTING ) } @@ -319,7 +319,7 @@ class LanguageServerPlugin : Plugin { Files.copy( configuration.fileIconPath, Paths.get(configuration.outputPath.toString(), "fileIcon.png"), - StandardCopyOption.REPLACE_EXISTING, + StandardCopyOption.REPLACE_EXISTING ) } @@ -332,13 +332,13 @@ class LanguageServerPlugin : Plugin { "curl", "https://repo1.maven.org/maven2/org/apache/lucene/lucene-core/9.8.0/lucene-core-9.8.0.jar", "-o", - Paths.get(configuration.outputPath.toString(), "lucene-core-9.8.0.jar").toString(), + Paths.get(configuration.outputPath.toString(), "lucene-core-9.8.0.jar").toString() ).start().waitFor() ProcessBuilder( "curl", "https://repo1.maven.org/maven2/org/apache/lucene/lucene-codecs/9.8.0/lucene-codecs-9.8.0.jar", "-o", - Paths.get(configuration.outputPath.toString(), "lucene-codecs-9.8.0.jar").toString(), + Paths.get(configuration.outputPath.toString(), "lucene-codecs-9.8.0.jar").toString() ).start().waitFor() ProcessBuilder(npx, "vsce@2.15", "package").directory(configuration.outputPath.toFile()).start().waitFor() diff --git a/settings.gradle.kts b/settings.gradle.kts index 9b37f14..f943103 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -6,3 +6,36 @@ rootProject.name="kolasu-languageserver" project(":library").name = "kolasu-languageserver-library" project(":testing").name = "kolasu-languageserver-testing" project(":plugin").name = "kolasu-languageserver-plugin" + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + // versions + val releasePluginVersion = version("release", "3.0.2") + val shadowPluginVersion = version("shadow", "7.1.2") + val ktlintPluginVersion = version("ktlint", "11.6.0") + val ktlintLibraryVersion = version("ktlint-library", "0.47.1") + val kotlinVersion = version("kotlin", "1.8.22") + val kolasuVersion = version("kolasu", "1.5.45") + val lsp4jVersion = version("lsp4j", "0.21.1") + val luceneVersion = version("lucene", "9.8.0") + val junit5Version = version("junit5", "5.7.1") + // plugins + plugin("kotlin-jvm", "org.jetbrains.kotlin.jvm").versionRef(kotlinVersion) + plugin("ktlint", "org.jlleitschuh.gradle.ktlint").versionRef(ktlintPluginVersion) + plugin("release", "net.researchgate.release").versionRef(releasePluginVersion) + plugin("shadow", "com.github.johnrengelman.shadow").versionRef(shadowPluginVersion) + // libraries + library("kotlin-reflect", "org.jetbrains.kotlin", "kotlin-reflect").versionRef(kotlinVersion) +// library("kotlin-stdlib-jdk8", "org.jetbrains.kotlin", "kotlin-stdlib-jdk8").versionRef(kotlinVersion) + library("kolasu-core", "com.strumenta.kolasu", "kolasu-core").versionRef(kolasuVersion) + library("lsp4j", "org.eclipse.lsp4j", "org.eclipse.lsp4j").versionRef(lsp4jVersion) + library("junit5", "org.junit.jupiter", "junit-jupiter-api").versionRef(junit5Version) + library("lucene", "org.apache.lucene", "lucene-core").versionRef(luceneVersion) + library("ktlint", "com.pinterest", "ktlint").versionRef(ktlintLibraryVersion) + // plugin - libraries + library("shadow", "com.github.johnrengelman.shadow", "com.github.johnrengelman.shadow.gradle.plugin").versionRef(shadowPluginVersion) + library("kotlin-jvm", "org.jetbrains.kotlin.jvm", "org.jetbrains.kotlin.jvm.gradle.plugin").versionRef(kotlinVersion) + } + } +} \ No newline at end of file diff --git a/testing/build.gradle.kts b/testing/build.gradle.kts index 6be752f..3b721f6 100644 --- a/testing/build.gradle.kts +++ b/testing/build.gradle.kts @@ -1,25 +1,21 @@ import java.net.URI plugins { - id("org.jetbrains.kotlin.jvm") version "1.8.22" - id("org.jlleitschuh.gradle.ktlint") version "11.6.0" - id("maven-publish") - id("signing") + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.ktlint) + `maven-publish` + signing } repositories { mavenCentral() } -val kolasuVersion: String by project -val lsp4jVersion: String by project -val junitVersion: String by project - dependencies { implementation(project(":kolasu-languageserver-library")) - implementation("com.strumenta.kolasu:kolasu-core:$kolasuVersion") - implementation("org.eclipse.lsp4j:org.eclipse.lsp4j:$lsp4jVersion") - implementation("org.junit.jupiter:junit-jupiter-api:$junitVersion") + implementation(libs.kolasu.core) + implementation(libs.lsp4j) + implementation(libs.junit5) } java { @@ -82,7 +78,3 @@ publishing { signing { sign(publishing.publications.getByName("language-server-testing")) } - -ktlint { - version = "1.2.1" -} diff --git a/testing/src/main/kotlin/testing/TestKolasuServer.kt b/testing/src/main/kotlin/testing/TestKolasuServer.kt index ec4cf24..01a80a7 100644 --- a/testing/src/main/kotlin/testing/TestKolasuServer.kt +++ b/testing/src/main/kotlin/testing/TestKolasuServer.kt @@ -37,7 +37,7 @@ open class TestKolasuServer( protected open var codeGenerator: CodeGenerator? = null, protected open var language: String = "languageserver", protected open var fileExtensions: List = listOf(), - protected open var workspacePath: Path = Paths.get("src", "test", "resources"), + protected open var workspacePath: Path = Paths.get("src", "test", "resources") ) { protected open lateinit var server: KolasuServer @@ -63,13 +63,13 @@ open class TestKolasuServer( server.connect( DiagnosticListenerClient { assertEquals(amount, it.diagnostics.size) - }, + } ) } protected open fun open( uri: String, - text: String, + text: String ) { val textDocument = TextDocumentItem(uri, "", 0, text) val parameters = DidOpenTextDocumentParams(textDocument) @@ -79,7 +79,7 @@ open class TestKolasuServer( protected open fun change( uri: String, - text: String, + text: String ) { val document = VersionedTextDocumentIdentifier(uri, null) val changes = listOf(TextDocumentContentChangeEvent(text)) @@ -97,7 +97,7 @@ open class TestKolasuServer( protected open fun definition( uri: String, - position: Position, + position: Position ): Location? { val document = TextDocumentIdentifier(uri) val parameters = DefinitionParams(document, position) @@ -108,7 +108,7 @@ open class TestKolasuServer( protected open fun references( uri: String, position: Position, - includeDeclaration: Boolean = true, + includeDeclaration: Boolean = true ): MutableList? { val document = TextDocumentIdentifier(uri) val parameters = ReferenceParams(document, position, ReferenceContext(includeDeclaration)) @@ -118,7 +118,7 @@ open class TestKolasuServer( protected fun requestAtEachPositionInResourceFiles( name: String, - request: (String, Position) -> Unit, + request: (String, Position) -> Unit ): List { val timings = mutableListOf()