diff --git a/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt b/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt index ff988545d..cbacca589 100644 --- a/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt +++ b/server/src/main/kotlin/org/javacs/kt/KotlinTextDocumentService.kt @@ -80,7 +80,10 @@ class KotlinTextDocumentService( private fun recover(uriString: String, position: Position, recompile: Recompile): Pair? { val uri = parseURI(uriString) - if (!sf.isIncluded(uri)) return null + if (!sf.isIncluded(uri)) { + LOG.warn("URI is excluded, therefore cannot be recovered: $uri") + return null + } val content = sp.content(uri) val offset = offset(content, position.line, position.character) val shouldRecompile = when (recompile) { diff --git a/server/src/main/kotlin/org/javacs/kt/KotlinWorkspaceService.kt b/server/src/main/kotlin/org/javacs/kt/KotlinWorkspaceService.kt index 609a3b551..6b89473e4 100644 --- a/server/src/main/kotlin/org/javacs/kt/KotlinWorkspaceService.kt +++ b/server/src/main/kotlin/org/javacs/kt/KotlinWorkspaceService.kt @@ -140,6 +140,7 @@ class KotlinWorkspaceService( val scripts = config.scripts get("enabled")?.asBoolean?.let { scripts.enabled = it } get("buildScriptsEnabled")?.asBoolean?.let { scripts.buildScriptsEnabled = it } + sf.updateExclusions() } // Update code-completion options diff --git a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt index 68c0f66c8..d7bb84968 100644 --- a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt +++ b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt @@ -74,7 +74,7 @@ class SourceFiles( private val open = mutableSetOf() fun open(uri: URI, content: String, version: Int) { - if (exclusions.isURIIncluded(uri)) { + if (isIncluded(uri)) { files[uri] = SourceVersion(content, version, languageOf(uri), isTemporary = false) open.add(uri) } @@ -98,7 +98,7 @@ class SourceFiles( } fun edit(uri: URI, newVersion: Int, contentChanges: List) { - if (exclusions.isURIIncluded(uri)) { + if (isIncluded(uri)) { val existing = files[uri]!! var newText = existing.content @@ -143,7 +143,7 @@ class SourceFiles( null } - private fun isSource(uri: URI): Boolean = exclusions.isURIIncluded(uri) && languageOf(uri) != null + private fun isSource(uri: URI): Boolean = isIncluded(uri) && languageOf(uri) != null private fun languageOf(uri: URI): Language? { val fileName = uri.filePath?.fileName?.toString() ?: return null @@ -154,6 +154,7 @@ class SourceFiles( } fun addWorkspaceRoot(root: Path) { + LOG.info("Searching $root using exclusions: ${exclusions.excludedPatterns}") val addSources = findSourceFiles(root) logAdded(addSources, root) @@ -187,8 +188,9 @@ class SourceFiles( .toSet() } - private fun updateExclusions() { + fun updateExclusions() { exclusions = SourceExclusions(workspaceRoots, scriptsConfig) + LOG.info("Updated exclusions: ${exclusions.excludedPatterns}") } fun isOpen(uri: URI): Boolean = (uri in open) diff --git a/shared/src/main/kotlin/org/javacs/kt/SourceExclusions.kt b/shared/src/main/kotlin/org/javacs/kt/SourceExclusions.kt index 17f1d3e86..e86db62f6 100644 --- a/shared/src/main/kotlin/org/javacs/kt/SourceExclusions.kt +++ b/shared/src/main/kotlin/org/javacs/kt/SourceExclusions.kt @@ -13,13 +13,15 @@ class SourceExclusions( private val workspaceRoots: Collection, private val scriptsConfig: ScriptsConfiguration ) { - private val excludedPatterns = (listOf( + val excludedPatterns = (listOf( ".*", "bazel-*", "bin", "build", "node_modules", "target" ) + when { !scriptsConfig.enabled -> listOf("*.kts") !scriptsConfig.buildScriptsEnabled -> listOf("*.gradle.kts") else -> emptyList() }) + + private val exclusionMatchers = excludedPatterns .map { FileSystems.getDefault().getPathMatcher("glob:$it") } /** Finds all non-excluded files recursively. */ @@ -35,10 +37,10 @@ class SourceExclusions( /** Tests whether the given path is not excluded. */ fun isPathIncluded(file: Path): Boolean = workspaceRoots.any { file.startsWith(it) } - && excludedPatterns.none { pattern -> + && exclusionMatchers.none { matcher -> workspaceRoots .mapNotNull { if (file.startsWith(it)) it.relativize(file) else null } .flatMap { it } // Extract path segments - .any(pattern::matches) + .any(matcher::matches) } }