From 12edb623ac3b931ce469d4c9c75bd66cfc01926d Mon Sep 17 00:00:00 2001 From: fwcd Date: Mon, 15 Jan 2024 01:58:55 +0000 Subject: [PATCH 1/4] Log more verbosely about exclusions --- .../kotlin/org/javacs/kt/KotlinTextDocumentService.kt | 5 ++++- server/src/main/kotlin/org/javacs/kt/SourceFiles.kt | 1 + shared/src/main/kotlin/org/javacs/kt/SourceExclusions.kt | 8 +++++--- 3 files changed, 10 insertions(+), 4 deletions(-) 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/SourceFiles.kt b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt index 68c0f66c8..b78ea8510 100644 --- a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt +++ b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt @@ -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) 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) } } From 91bd63da2cb3decb1cda1b4f0c8e1842f8d78205 Mon Sep 17 00:00:00 2001 From: fwcd Date: Mon, 15 Jan 2024 02:01:39 +0000 Subject: [PATCH 2/4] Update exclusions on config changes --- server/src/main/kotlin/org/javacs/kt/KotlinWorkspaceService.kt | 1 + server/src/main/kotlin/org/javacs/kt/SourceFiles.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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 b78ea8510..e409e97ec 100644 --- a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt +++ b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt @@ -188,7 +188,7 @@ class SourceFiles( .toSet() } - private fun updateExclusions() { + fun updateExclusions() { exclusions = SourceExclusions(workspaceRoots, scriptsConfig) } From 58efab4285636dc2d519ce6b87658c2b0b2308fa Mon Sep 17 00:00:00 2001 From: fwcd Date: Mon, 15 Jan 2024 02:03:18 +0000 Subject: [PATCH 3/4] Use isIncluded locally too --- server/src/main/kotlin/org/javacs/kt/SourceFiles.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt index e409e97ec..5558b86b2 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 From 84dc685960f697c5cc9d10378067b6552569e18c Mon Sep 17 00:00:00 2001 From: fwcd Date: Mon, 15 Jan 2024 02:04:48 +0000 Subject: [PATCH 4/4] Log updated exclusions --- server/src/main/kotlin/org/javacs/kt/SourceFiles.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt index 5558b86b2..d7bb84968 100644 --- a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt +++ b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt @@ -190,6 +190,7 @@ class SourceFiles( fun updateExclusions() { exclusions = SourceExclusions(workspaceRoots, scriptsConfig) + LOG.info("Updated exclusions: ${exclusions.excludedPatterns}") } fun isOpen(uri: URI): Boolean = (uri in open)