From 10c919915d244841d21f01c1d0df7fe6a8b66dae Mon Sep 17 00:00:00 2001 From: kuna Date: Tue, 25 Nov 2025 16:40:19 +0900 Subject: [PATCH] Fix lint being ignored for kts script The lint has been ignored for kts script because the linting filtering is done based on the files enumerated when the workspace is opened. Setting for enabling script file is ignored as that workspace load happens before configuration is loaded. Easy workaround for the issue is, firstly filter the file for linting based on the matcher, then open the files dynamically if it's not been loaded at the workspace init time. --- .../kotlin/org/javacs/kt/KotlinTextDocumentService.kt | 4 ++-- server/src/main/kotlin/org/javacs/kt/SourceFiles.kt | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt b/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt index 2ec1e5227..0a268b050 100644 --- a/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt +++ b/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt @@ -316,12 +316,12 @@ class KotlinTextDocumentService( val byFile = langServerDiagnostics.groupBy({ it.first }, { it.second }) for ((uri, diagnostics) in byFile) { - if (sf.isOpen(uri)) { + if (sf.isIncluded(uri)) { client.publishDiagnostics(PublishDiagnosticsParams(uri.toString(), diagnostics)) LOG.info("Reported {} diagnostics in {}", diagnostics.size, describeURI(uri)) } - else LOG.info("Ignore {} diagnostics in {} because it's not open", diagnostics.size, describeURI(uri)) + else LOG.info("Ignore {} diagnostics in {} because it's excluded", diagnostics.size, describeURI(uri)) } val noErrors = compiled - byFile.keys diff --git a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt index d7bb84968..3e4648a20 100644 --- a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt +++ b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt @@ -99,6 +99,13 @@ class SourceFiles( fun edit(uri: URI, newVersion: Int, contentChanges: List) { if (isIncluded(uri)) { + if (!isOpen(uri)) { + // There might be a case where the file is not have been opened yet if the configuration + // is changed to include/exclude certain files. In that case, we read it from disk first. + readFromDisk(uri, temporary = false)?.let { + files[uri] = it + } ?: LOG.warn("Could not read source file '{}'", uri.path) + } val existing = files[uri]!! var newText = existing.content @@ -193,7 +200,7 @@ class SourceFiles( LOG.info("Updated exclusions: ${exclusions.excludedPatterns}") } - fun isOpen(uri: URI): Boolean = (uri in open) + private fun isOpen(uri: URI): Boolean = (uri in open) fun isIncluded(uri: URI): Boolean = exclusions.isURIIncluded(uri) }