Skip to content
Merged
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
4 changes: 2 additions & 2 deletions detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ config:
warningsAsErrors: false

comments:
excludes: ["**/src/test/resources/**"]
excludes: ["**/src/test/**"]

complexity:
excludes: ["**/src/test/resources/**"]
excludes: ["**/src/test/**"]

empty-blocks:
excludes: ["**/src/test/**"]
Expand Down
22 changes: 19 additions & 3 deletions server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import java.nio.file.Path
* Manages the class path (compiled JARs, etc), the Java source path
* and the compiler. Note that Kotlin sources are stored in SourcePath.
*/
class CompilerClassPath(private val config: CompilerConfiguration, private val databaseService: DatabaseService) : Closeable {
class CompilerClassPath(
private val config: CompilerConfiguration,
private val scriptsConfig: ScriptsConfiguration,
private val databaseService: DatabaseService
) : Closeable {
val workspaceRoots = mutableSetOf<Path>()

private val javaSourcePath = mutableSetOf<Path>()
Expand All @@ -24,7 +28,13 @@ class CompilerClassPath(private val config: CompilerConfiguration, private val d
val outputDirectory: File = Files.createTempDirectory("klsBuildOutput").toFile()
val javaHome: String? = System.getProperty("java.home", null)

var compiler = Compiler(javaSourcePath, classPath.map { it.compiledJar }.toSet(), buildScriptClassPath, outputDirectory)
var compiler = Compiler(
javaSourcePath,
classPath.map { it.compiledJar }.toSet(),
buildScriptClassPath,
scriptsConfig,
outputDirectory
)
private set

private val async = AsyncExecutor()
Expand Down Expand Up @@ -72,7 +82,13 @@ class CompilerClassPath(private val config: CompilerConfiguration, private val d
if (refreshCompiler) {
LOG.info("Reinstantiating compiler")
compiler.close()
compiler = Compiler(javaSourcePath, classPath.map { it.compiledJar }.toSet(), buildScriptClassPath, outputDirectory)
compiler = Compiler(
javaSourcePath,
classPath.map { it.compiledJar }.toSet(),
buildScriptClassPath,
scriptsConfig,
outputDirectory
)
updateCompilerConfiguration()
}

Expand Down
10 changes: 9 additions & 1 deletion server/src/main/kotlin/org/javacs/kt/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public data class DiagnosticsConfiguration(
var debounceTime: Long = 250L
)

public data class ScriptsConfiguration(
/** Whether .kts scripts are handled. */
var enabled: Boolean = false,
/** Whether .gradle.kts scripts are handled. Only considered if scripts are enabled in general. */
var buildScriptsEnabled: Boolean = false
)

public data class JVMConfiguration(
/** Which JVM target the Kotlin compiler uses. See Compiler.jvmTargetFrom for possible values. */
var target: String = "default"
Expand Down Expand Up @@ -91,7 +98,8 @@ public data class Configuration(
val compiler: CompilerConfiguration = CompilerConfiguration(),
val completion: CompletionConfiguration = CompletionConfiguration(),
val diagnostics: DiagnosticsConfiguration = DiagnosticsConfiguration(),
var indexing: IndexingConfiguration = IndexingConfiguration(),
val scripts: ScriptsConfiguration = ScriptsConfiguration(),
val indexing: IndexingConfiguration = IndexingConfiguration(),
val externalSources: ExternalSourcesConfiguration = ExternalSourcesConfiguration(),
val hints: InlayHintsConfiguration = InlayHintsConfiguration()
)
9 changes: 5 additions & 4 deletions server/src/main/kotlin/org/javacs/kt/KotlinLanguageServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import java.nio.file.Paths
import java.util.concurrent.CompletableFuture
import java.util.concurrent.CompletableFuture.completedFuture

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

private val tempDirectory = TemporaryDirectory()
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)
val sourceFiles = SourceFiles(sourcePath, uriContentProvider, config.scripts)

private val textDocuments = KotlinTextDocumentService(sourceFiles, sourcePath, config, tempDirectory, uriContentProvider, classPath)
private val workspaces = KotlinWorkspaceService(sourceFiles, sourcePath, classPath, textDocuments, config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ class KotlinWorkspaceService(
}
}

// Update scripts options
get("scripts")?.asJsonObject?.apply {
val scripts = config.scripts
get("enabled")?.asBoolean?.let { scripts.enabled = it }
get("buildScriptsEnabled")?.asBoolean?.let { scripts.buildScriptsEnabled = it }
}

// Update code-completion options
get("completion")?.asJsonObject?.apply {
val completion = config.completion
Expand Down
25 changes: 15 additions & 10 deletions server/src/main/kotlin/org/javacs/kt/SourceFiles.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ private class NotifySourcePath(private val sp: SourcePath) {
*/
class SourceFiles(
private val sp: SourcePath,
private val contentProvider: URIContentProvider
private val contentProvider: URIContentProvider,
private val scriptsConfig: ScriptsConfiguration
) {
private val workspaceRoots = mutableSetOf<Path>()
private var exclusions = SourceExclusions(workspaceRoots)
Expand Down Expand Up @@ -175,6 +176,19 @@ class SourceFiles(
updateExclusions()
}

private fun findSourceFiles(root: Path): Set<URI> {
val glob = if (scriptsConfig.enabled) "*.{kt,kts}" else "*.kt"
val sourceMatcher = FileSystems.getDefault().getPathMatcher("glob:$glob")
return SourceExclusions(root)
.walkIncluded()
.filter {
sourceMatcher.matches(it.fileName)
&& (scriptsConfig.buildScriptsEnabled || !it.endsWith(".gradle.kts"))
}
.map(Path::toUri)
.toSet()
}

private fun updateExclusions() {
exclusions = SourceExclusions(workspaceRoots)
}
Expand Down Expand Up @@ -222,15 +236,6 @@ private fun patch(sourceText: String, change: TextDocumentContentChangeEvent): S
}
}

private fun findSourceFiles(root: Path): Set<URI> {
val sourceMatcher = FileSystems.getDefault().getPathMatcher("glob:*.{kt,kts}")
return SourceExclusions(root)
.walkIncluded()
.filter { sourceMatcher.matches(it.fileName) }
.map(Path::toUri)
.toSet()
}

private fun logAdded(sources: Collection<URI>, rootPath: Path?) {
LOG.info("Adding {} under {} to source path", describeURIs(sources), rootPath)
}
Expand Down
Loading