Skip to content

Commit b223561

Browse files
committed
Make kts support configurable and disable it by default
1 parent 42fd533 commit b223561

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public data class DiagnosticsConfiguration(
3030
var debounceTime: Long = 250L
3131
)
3232

33+
public data class ScriptsConfiguration(
34+
/** Whether .kts scripts are handled. */
35+
var enabled: Boolean = false,
36+
/** Whether .gradle.kts scripts are handled. Only considered if scripts are enabled in general. */
37+
var buildScriptsEnabled: Boolean = false
38+
)
39+
3340
public data class JVMConfiguration(
3441
/** Which JVM target the Kotlin compiler uses. See Compiler.jvmTargetFrom for possible values. */
3542
var target: String = "default"
@@ -91,6 +98,7 @@ public data class Configuration(
9198
val compiler: CompilerConfiguration = CompilerConfiguration(),
9299
val completion: CompletionConfiguration = CompletionConfiguration(),
93100
val diagnostics: DiagnosticsConfiguration = DiagnosticsConfiguration(),
101+
val scripts: ScriptsConfiguration = ScriptsConfiguration(),
94102
val indexing: IndexingConfiguration = IndexingConfiguration(),
95103
val externalSources: ExternalSourcesConfiguration = ExternalSourcesConfiguration(),
96104
val hints: InlayHintsConfiguration = InlayHintsConfiguration()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class KotlinLanguageServer : LanguageServer, LanguageClientAware, Closeable {
3030
private val tempDirectory = TemporaryDirectory()
3131
private val uriContentProvider = URIContentProvider(ClassContentProvider(config.externalSources, classPath, tempDirectory, CompositeSourceArchiveProvider(JdkSourceArchiveProvider(classPath), ClassPathSourceArchiveProvider(classPath))))
3232
val sourcePath = SourcePath(classPath, uriContentProvider, config.indexing, databaseService)
33-
val sourceFiles = SourceFiles(sourcePath, uriContentProvider)
33+
val sourceFiles = SourceFiles(sourcePath, uriContentProvider, config.scripts)
3434

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

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ private class NotifySourcePath(private val sp: SourcePath) {
6565
*/
6666
class SourceFiles(
6767
private val sp: SourcePath,
68-
private val contentProvider: URIContentProvider
68+
private val contentProvider: URIContentProvider,
69+
private val scriptsConfig: ScriptsConfiguration
6970
) {
7071
private val workspaceRoots = mutableSetOf<Path>()
7172
private var exclusions = SourceExclusions(workspaceRoots)
@@ -175,6 +176,19 @@ class SourceFiles(
175176
updateExclusions()
176177
}
177178

179+
private fun findSourceFiles(root: Path): Set<URI> {
180+
val glob = if (scriptsConfig.enabled) "*.{kt,kts}" else "*.kt"
181+
val sourceMatcher = FileSystems.getDefault().getPathMatcher("glob:$glob")
182+
return SourceExclusions(root)
183+
.walkIncluded()
184+
.filter {
185+
sourceMatcher.matches(it.fileName)
186+
&& (scriptsConfig.buildScriptsEnabled || !it.endsWith(".gradle.kts"))
187+
}
188+
.map(Path::toUri)
189+
.toSet()
190+
}
191+
178192
private fun updateExclusions() {
179193
exclusions = SourceExclusions(workspaceRoots)
180194
}
@@ -222,15 +236,6 @@ private fun patch(sourceText: String, change: TextDocumentContentChangeEvent): S
222236
}
223237
}
224238

225-
private fun findSourceFiles(root: Path): Set<URI> {
226-
val sourceMatcher = FileSystems.getDefault().getPathMatcher("glob:*.{kt,kts}")
227-
return SourceExclusions(root)
228-
.walkIncluded()
229-
.filter { sourceMatcher.matches(it.fileName) }
230-
.map(Path::toUri)
231-
.toSet()
232-
}
233-
234239
private fun logAdded(sources: Collection<URI>, rootPath: Path?) {
235240
LOG.info("Adding {} under {} to source path", describeURIs(sources), rootPath)
236241
}

0 commit comments

Comments
 (0)