Skip to content

Commit 10c9199

Browse files
committed
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.
1 parent 6d9e61b commit 10c9199

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,12 @@ class KotlinTextDocumentService(
316316
val byFile = langServerDiagnostics.groupBy({ it.first }, { it.second })
317317

318318
for ((uri, diagnostics) in byFile) {
319-
if (sf.isOpen(uri)) {
319+
if (sf.isIncluded(uri)) {
320320
client.publishDiagnostics(PublishDiagnosticsParams(uri.toString(), diagnostics))
321321

322322
LOG.info("Reported {} diagnostics in {}", diagnostics.size, describeURI(uri))
323323
}
324-
else LOG.info("Ignore {} diagnostics in {} because it's not open", diagnostics.size, describeURI(uri))
324+
else LOG.info("Ignore {} diagnostics in {} because it's excluded", diagnostics.size, describeURI(uri))
325325
}
326326

327327
val noErrors = compiled - byFile.keys

server/src/main/kotlin/org/javacs/kt/SourceFiles.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class SourceFiles(
9999

100100
fun edit(uri: URI, newVersion: Int, contentChanges: List<TextDocumentContentChangeEvent>) {
101101
if (isIncluded(uri)) {
102+
if (!isOpen(uri)) {
103+
// There might be a case where the file is not have been opened yet if the configuration
104+
// is changed to include/exclude certain files. In that case, we read it from disk first.
105+
readFromDisk(uri, temporary = false)?.let {
106+
files[uri] = it
107+
} ?: LOG.warn("Could not read source file '{}'", uri.path)
108+
}
102109
val existing = files[uri]!!
103110
var newText = existing.content
104111

@@ -193,7 +200,7 @@ class SourceFiles(
193200
LOG.info("Updated exclusions: ${exclusions.excludedPatterns}")
194201
}
195202

196-
fun isOpen(uri: URI): Boolean = (uri in open)
203+
private fun isOpen(uri: URI): Boolean = (uri in open)
197204

198205
fun isIncluded(uri: URI): Boolean = exclusions.isURIIncluded(uri)
199206
}

0 commit comments

Comments
 (0)