From 3bde12a1f3769b079b95d9609f751482df0fb0fe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Jan 2025 00:57:32 +0000 Subject: [PATCH 1/2] Bump com.jaredsburrows.license from 0.8.42 to 0.9.8 Bumps [com.jaredsburrows.license](https://github.com/jaredsburrows/gradle-license-plugin) from 0.8.42 to 0.9.8. - [Release notes](https://github.com/jaredsburrows/gradle-license-plugin/releases) - [Changelog](https://github.com/jaredsburrows/gradle-license-plugin/blob/master/CHANGELOG.md) - [Commits](https://github.com/jaredsburrows/gradle-license-plugin/commits/0.9.8) --- updated-dependencies: - dependency-name: com.jaredsburrows.license dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8208dc76..167e4e5e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -49,5 +49,5 @@ org-jetbrains-kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gra [plugins] com-github-jk1-tcdeps = { id = "com.github.jk1.tcdeps", version = "1.6.2" } -com-jaredsburrows-license = { id = "com.jaredsburrows.license", version = "0.8.42" } +com-jaredsburrows-license = { id = "com.jaredsburrows.license", version = "0.9.8" } io-gitlab-arturbosch-detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.22.0" } From a1f16b21a36bfb6dee0c97cda716c4322e6c7bf7 Mon Sep 17 00:00:00 2001 From: H4-MM-3R Date: Wed, 26 Mar 2025 23:11:47 +0530 Subject: [PATCH 2/2] implemented onTypeFormatting --- .../org/javacs/kt/KotlinLanguageServer.kt | 1 + .../javacs/kt/KotlinTextDocumentService.kt | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt b/server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt index e8da0ff9..d4a46f94 100644 --- a/server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt +++ b/server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt @@ -91,6 +91,7 @@ class KotlinLanguageServer( serverCapabilities.codeActionProvider = Either.forLeft(true) serverCapabilities.documentFormattingProvider = Either.forLeft(true) serverCapabilities.documentRangeFormattingProvider = Either.forLeft(true) + serverCapabilities.documentOnTypeFormattingProvider = DocumentOnTypeFormattingOptions("}", listOf(";", "\n")) serverCapabilities.executeCommandProvider = ExecuteCommandOptions(ALL_COMMANDS) serverCapabilities.documentHighlightProvider = Either.forLeft(true) diff --git a/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt b/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt index 2ec1e522..ffd9c79c 100644 --- a/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt +++ b/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt @@ -120,8 +120,27 @@ class KotlinTextDocumentService( documentHighlightsAt(file, cursor) } - override fun onTypeFormatting(params: DocumentOnTypeFormattingParams): CompletableFuture> { - TODO("not implemented") + override fun onTypeFormatting(params: DocumentOnTypeFormattingParams): CompletableFuture> = async.compute { + val code = params.textDocument.content + val position = params.position + val offset = offset(code, position.line, position.character) + + // Get the line up to the cursor position + val lineStart = code.lastIndexOf('\n', offset - 1) + 1 + val lineEnd = code.indexOf('\n', offset) + val line = if (lineEnd == -1) code.substring(lineStart) else code.substring(lineStart, lineEnd) + + // Format the line + val formattedLine = formattingService.formatKotlinCode(line, params.options) + + // Create a range for the line + val range = Range( + Position(position.line, 0), + Position(position.line, line.length) + ) + + // Return the edit + listOf(TextEdit(range, formattedLine)) } override fun definition(position: DefinitionParams): CompletableFuture, List>> = async.compute {