Skip to content

lint fix and remove deprecated function , tipically that one induced by exposed #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

# docs
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "weekly"
# We release on Tuesdays and open dependabot PRs will rebase after the
# version bump and thus consume unnecessary workers during release, thus
# let's open new ones on Wednesday
day: "wednesday"
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-patch"]
groups:
# Only update polars as a whole as there are many subcrates that need to
# be updated at once. We explicitly depend on some of them, so batch their
# updates to not take up dependabot PR slots with dysfunctional PRs
polars:
patterns:
- "polars"
- "polars-*"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "wednesday"
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
with:
cache-disabled: ${{ contains(matrix.os, 'windows') }}
- name: Build
run: ./gradlew :server:build :shared:build -PjavaVersion=${{ matrix.java }}
- name: Detekt
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
with:
cache-disabled: ${{ contains(matrix.os, 'windows') }}
- name: Get tag name
id: tag
run: |
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/typos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# yamllint disable rule:line-length
name: check_typos

on: # yamllint disable-line rule:truthy
push:
pull_request:
branches:
- '**'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: typos-action
uses: crate-ci/[email protected]
6 changes: 6 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[files]
extend-exclude = ["server/src/test/resources/completions/*.kt"]

[default.extend-words]
ba = "ba"
vertx = "vertx"
5 changes: 5 additions & 0 deletions detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ exceptions:
- NumberFormatException
- ParseException
- MissingPropertyException
TooGenericExceptionCaught:
active: false

naming:
excludes: *standardExcludes
Expand All @@ -38,6 +40,9 @@ style:
excludes: *standardExcludes
MaxLineLength:
active: false
ReturnCount:
active: true
max: 3 # Maximum allowed return statements in a function
WildcardImport:
excludeImports:
- java.util.*
Expand Down
2 changes: 1 addition & 1 deletion detekt_baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<ID>EmptyClassBlock:samefile.kt$MyImplClass${}</ID>
<ID>EmptyClassBlock:samefile.kt$NullClass${}</ID>
<ID>EmptyClassBlock:samefile.kt$PrintableClass${}</ID>
<ID>EmptyClassBlock:standardlib.kt$MyComperable${}</ID>
<ID>EmptyClassBlock:standardlib.kt$MyComparable${}</ID>
<ID>EmptyClassBlock:standardlib.kt$MyList${}</ID>
<ID>EmptyClassBlock:standardlib.kt$MyThread${}</ID>
<ID>EmptyDefaultConstructor:BigFile.kt$BigFile.A$()</ID>
Expand Down
20 changes: 13 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[versions]
kotlinVersion = "2.1.0"
lsp4jVersion = "0.21.2"
exposedVersion = "0.37.3"
lsp4jVersion = "0.23.1"
exposedVersion = "0.58.0"
jmhVersion = "1.20"
guavaVersion = "33.3.0-jre"
slf4j = "2.0.16"
guavaVersion = "33.4.0-jre"

[libraries]
org-jetbrains-kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlinVersion" }
Expand Down Expand Up @@ -41,12 +42,17 @@ com-beust-jcommander = { module = "com.beust:jcommander", version = "1.78" }
org-openjdk-jmh-generator-annprocess = { module = "org.openjdk.jmh:jmh-generator-annprocess", version.ref = "jmhVersion" }
org-openjdk-jmh-core = { module = "org.openjdk.jmh:jmh-core", version.ref = "jmhVersion" }

org-xerial-sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version = "3.41.2.1" }
org-xerial-sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version = "3.48.0.0" }

# buildSrc
org-jetbrains-kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin",version.ref = "kotlinVersion" }
org-jetbrains-kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinVersion" }

# this is used to remove the error info in console log
org-slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
org-slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" }


[plugins]
com-github-jk1-tcdeps = { id = "com.github.jk1.tcdeps", version = "1.2" }
com-jaredsburrows-license = { id = "com.jaredsburrows.license", version = "0.8.42" }
com-github-jk1-tcdeps = { id = "com.github.jk1.tcdeps", version = "1.6.2" }
com-jaredsburrows-license = { id = "com.jaredsburrows.license", version = "0.9.8" }
io-gitlab-arturbosch-detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.22.0" }
8 changes: 7 additions & 1 deletion server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ plugins {
id("kotlin-language-server.kotlin-conventions")
}

val serverDebugPort = 4000
val debugPort = 8000
val debugArgs = "-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n,quiet=y"
val debugArgs = "-agentlib:jdwp=transport=dt_socket,server=y,address=$debugPort,suspend=n,quiet=y"

val serverMainClassName = "org.javacs.kt.MainKt"
val applicationName = "kotlin-language-server"
Expand Down Expand Up @@ -43,6 +44,10 @@ dependencies {
implementation(libs.org.eclipse.lsp4j.lsp4j)
implementation(libs.org.eclipse.lsp4j.jsonrpc)

// used to clear the error during console log
implementation(libs.org.slf4j.api)
implementation(libs.org.slf4j.simple)

implementation(kotlin("compiler"))
implementation(kotlin("scripting-compiler"))
implementation(kotlin("scripting-jvm-host-unshaded"))
Expand Down Expand Up @@ -91,6 +96,7 @@ tasks.register<JavaExec>("debugRun") {
standardInput = System.`in`

jvmArgs(debugArgs)
args(listOf("--tcpServerPort", serverDebugPort, "--tcpDebug", "--tracingLog"))
doLast { println("Using debug port $debugPort") }
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/main/kotlin/org/javacs/kt/CompiledFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class CompiledFile(
surroundingContent = content.substring(recoveryRange.startOffset, content.length - (parse.text.length - recoveryRange.endOffset))
offset = recoveryRange.startOffset

if (asReference && !((parent as? KtParameter)?.hasValOrVar() ?: true)) {
if (asReference && (parent as? KtParameter)?.hasValOrVar() == false) {
// Prepend 'val' to (e.g. function) parameters
val prefix = "val "
surroundingContent = prefix + surroundingContent
Expand Down
6 changes: 3 additions & 3 deletions server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ class CompilerClassPath(
fun changedOnDisk(file: Path): Boolean {
val buildScript = isBuildScript(file)
val javaSource = isJavaSource(file)
if (buildScript || javaSource) {
return refresh(updateClassPath = buildScript, updateBuildScriptClassPath = false, updateJavaSourcePath = javaSource)
return if (buildScript || javaSource) {
refresh(updateClassPath = buildScript, updateBuildScriptClassPath = false, updateJavaSourcePath = javaSource)
} else {
return false
false
}
}

Expand Down
18 changes: 9 additions & 9 deletions server/src/main/kotlin/org/javacs/kt/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import java.nio.file.InvalidPathException
import java.nio.file.Path
import java.nio.file.Paths

public data class SnippetsConfiguration(
data class SnippetsConfiguration(
/** Whether code completion should return VSCode-style snippets. */
var enabled: Boolean = true
)

public data class CodegenConfiguration(
data class CodegenConfiguration(
/** Whether to enable code generation to a temporary build directory for Java interoperability. */
var enabled: Boolean = false
)

public data class CompletionConfiguration(
data class CompletionConfiguration(
val snippets: SnippetsConfiguration = SnippetsConfiguration()
)

public data class DiagnosticsConfiguration(
data class DiagnosticsConfiguration(
/** Whether diagnostics are enabled. */
var enabled: Boolean = true,
/** The minimum severity of enabled diagnostics. */
Expand All @@ -35,21 +35,21 @@ public data class DiagnosticsConfiguration(
var debounceTime: Long = 250L
)

public data class JVMConfiguration(
data class JVMConfiguration(
/** Which JVM target the Kotlin compiler uses. See Compiler.jvmTargetFrom for possible values. */
var target: String = "default"
)

public data class CompilerConfiguration(
data class CompilerConfiguration(
val jvm: JVMConfiguration = JVMConfiguration()
)

public data class IndexingConfiguration(
data class IndexingConfiguration(
/** Whether an index of global symbols should be built in the background. */
var enabled: Boolean = true
)

public data class ExternalSourcesConfiguration(
data class ExternalSourcesConfiguration(
/** Whether kls-URIs should be sent to the client to describe classes in JARs. */
var useKlsScheme: Boolean = false,
/** Whether external classes should be automatically converted to Kotlin. */
Expand Down Expand Up @@ -104,7 +104,7 @@ class GsonPathConverter : JsonDeserializer<Path?> {
}
}

public data class Configuration(
data class Configuration(
val codegen: CodegenConfiguration = CodegenConfiguration(),
val compiler: CompilerConfiguration = CompilerConfiguration(),
val completion: CompletionConfiguration = CompletionConfiguration(),
Expand Down
43 changes: 28 additions & 15 deletions server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,29 @@ import java.util.concurrent.CompletableFuture
import java.util.concurrent.CompletableFuture.completedFuture

class KotlinLanguageServer(
val config: Configuration = Configuration()
val config: Configuration = Configuration(),
private val tcpDebug: Boolean = false
) : LanguageServer, LanguageClientAware, Closeable {
val databaseService = DatabaseService()
private val databaseService = DatabaseService()
val classPath = CompilerClassPath(config.compiler, config.scripts, config.codegen, databaseService)

private val tempDirectory = TemporaryDirectory()
private val uriContentProvider = URIContentProvider(ClassContentProvider(config.externalSources, classPath, tempDirectory, CompositeSourceArchiveProvider(JdkSourceArchiveProvider(classPath), ClassPathSourceArchiveProvider(classPath))))
private val uriContentProvider = URIContentProvider(
ClassContentProvider(
config.externalSources,
classPath,
tempDirectory,
CompositeSourceArchiveProvider(
JdkSourceArchiveProvider(classPath),
ClassPathSourceArchiveProvider(classPath)
)
)
)
val sourcePath = SourcePath(classPath, uriContentProvider, config.indexing, databaseService)
val sourceFiles = SourceFiles(sourcePath, uriContentProvider, config.scripts)
private val sourceFiles = SourceFiles(sourcePath, uriContentProvider, config.scripts)

private val textDocuments = KotlinTextDocumentService(sourceFiles, sourcePath, config, tempDirectory, uriContentProvider, classPath)
private val textDocuments =
KotlinTextDocumentService(sourceFiles, sourcePath, config, tempDirectory, uriContentProvider, classPath)
private val workspaces = KotlinWorkspaceService(sourceFiles, sourcePath, classPath, textDocuments, config)
private val protocolExtensions = KotlinProtocolExtensionService(uriContentProvider, classPath, sourcePath)

Expand All @@ -56,7 +68,9 @@ class KotlinLanguageServer(

override fun connect(client: LanguageClient) {
this.client = client
connectLoggingBackend()
if (!tcpDebug) {
connectLoggingBackend()
}

workspaces.connect(client)
textDocuments.connect(client)
Expand Down Expand Up @@ -87,7 +101,8 @@ class KotlinLanguageServer(
serverCapabilities.documentSymbolProvider = Either.forLeft(true)
serverCapabilities.workspaceSymbolProvider = Either.forLeft(true)
serverCapabilities.referencesProvider = Either.forLeft(true)
serverCapabilities.semanticTokensProvider = SemanticTokensWithRegistrationOptions(semanticTokensLegend, true, true)
serverCapabilities.semanticTokensProvider =
SemanticTokensWithRegistrationOptions(semanticTokensLegend, true, true)
serverCapabilities.codeActionProvider = Either.forLeft(true)
serverCapabilities.documentFormattingProvider = Either.forLeft(true)
serverCapabilities.documentRangeFormattingProvider = Either.forLeft(true)
Expand All @@ -98,20 +113,18 @@ class KotlinLanguageServer(
databaseService.setup(storagePath)

val clientCapabilities = params.capabilities
config.completion.snippets.enabled = clientCapabilities?.textDocument?.completion?.completionItem?.snippetSupport ?: false
config.completion.snippets.enabled =
clientCapabilities?.textDocument?.completion?.completionItem?.snippetSupport ?: false

if (clientCapabilities?.window?.workDoneProgress ?: false) {
if (clientCapabilities?.window?.workDoneProgress == true) {
progressFactory = LanguageClientProgress.Factory(client)
}

if (clientCapabilities?.textDocument?.rename?.prepareSupport ?: false) {
if (clientCapabilities?.textDocument?.rename?.prepareSupport == true) {
serverCapabilities.renameProvider = Either.forRight(RenameOptions(false))
}

@Suppress("DEPRECATION")
val folders = params.workspaceFolders?.takeIf { it.isNotEmpty() }
?: params.rootUri?.let(::WorkspaceFolder)?.let(::listOf)
?: params.rootPath?.let(Paths::get)?.toUri()?.toString()?.let(::WorkspaceFolder)?.let(::listOf)
?: listOf()

val progress = params.workDoneToken?.let { LanguageClientProgress("Workspace folders", it, client) }
Expand Down Expand Up @@ -176,6 +189,6 @@ class KotlinLanguageServer(
// Fixed in https://github.com/eclipse/lsp4j/commit/04b0c6112f0a94140e22b8b15bb5a90d5a0ed851
// Causes issue in lsp 0.15
override fun getNotebookDocumentService(): NotebookDocumentService? {
return null;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ class KotlinTextDocumentService(
TODO("not implemented")
}

@Suppress("DEPRECATION")
override fun documentSymbol(params: DocumentSymbolParams): CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> = async.compute {
LOG.info("Find symbols in {}", describeURI(params.textDocument.uri))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ class KotlinWorkspaceService(
LOG.info("Updated configuration: {}", settings)
}

@Suppress("DEPRECATION")
override fun symbol(params: WorkspaceSymbolParams): CompletableFuture<Either<List<SymbolInformation>, List<WorkspaceSymbol>>> {
val result = workspaceSymbols(params.query, sp)

Expand Down
Loading
Loading