-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow user specified exclusion patterns #574
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ class KotlinLanguageServer( | |
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, config.scripts) | ||
val sourceFiles = SourceFiles(sourcePath, uriContentProvider, config.scripts, mutableListOf()) | ||
|
||
private val textDocuments = KotlinTextDocumentService(sourceFiles, sourcePath, config, tempDirectory, uriContentProvider, classPath) | ||
private val workspaces = KotlinWorkspaceService(sourceFiles, sourcePath, classPath, textDocuments, config) | ||
|
@@ -72,6 +72,14 @@ class KotlinLanguageServer( | |
fun getProtocolExtensionService(): KotlinProtocolExtensions = protocolExtensions | ||
|
||
override fun initialize(params: InitializeParams): CompletableFuture<InitializeResult> = async.compute { | ||
// Parse initialization options | ||
val options = getInitializationOptions(params) | ||
databaseService.setup(options?.storagePath) | ||
|
||
if(options?.additionalSourceExclusions != null) { | ||
sourceFiles.updateAdditionalExclusions(options.additionalSourceExclusions.toMutableList()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we refactor this to use immutable lists? Mutable structures make it harder to reason about where updates are happening and passing them around make it easier for things to get out-of-sync, therefore I usually prefer the functional style. |
||
} | ||
|
||
val serverCapabilities = ServerCapabilities() | ||
serverCapabilities.setTextDocumentSync(TextDocumentSyncKind.Incremental) | ||
serverCapabilities.workspace = WorkspaceServerCapabilities() | ||
|
@@ -94,8 +102,6 @@ class KotlinLanguageServer( | |
serverCapabilities.executeCommandProvider = ExecuteCommandOptions(ALL_COMMANDS) | ||
serverCapabilities.documentHighlightProvider = Either.forLeft(true) | ||
|
||
val storagePath = getStoragePath(params) | ||
databaseService.setup(storagePath) | ||
|
||
val clientCapabilities = params.capabilities | ||
config.completion.snippets.enabled = clientCapabilities?.textDocument?.completion?.completionItem?.snippetSupport ?: false | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -66,10 +66,15 @@ private class NotifySourcePath(private val sp: SourcePath) { | |||||||||||||||||||||
class SourceFiles( | ||||||||||||||||||||||
private val sp: SourcePath, | ||||||||||||||||||||||
private val contentProvider: URIContentProvider, | ||||||||||||||||||||||
private val scriptsConfig: ScriptsConfiguration | ||||||||||||||||||||||
private val scriptsConfig: ScriptsConfiguration, | ||||||||||||||||||||||
private val additionalSourceExclusions: MutableList<String>, | ||||||||||||||||||||||
) { | ||||||||||||||||||||||
private val workspaceRoots = mutableSetOf<Path>() | ||||||||||||||||||||||
private var exclusions = SourceExclusions(workspaceRoots, scriptsConfig) | ||||||||||||||||||||||
private var exclusions = SourceExclusions( | ||||||||||||||||||||||
workspaceRoots, | ||||||||||||||||||||||
scriptsConfig, | ||||||||||||||||||||||
additionalSourceExclusions | ||||||||||||||||||||||
) | ||||||||||||||||||||||
Comment on lines
+73
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style nit:
Suggested change
|
||||||||||||||||||||||
private val files = NotifySourcePath(sp) | ||||||||||||||||||||||
private val open = mutableSetOf<URI>() | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -181,18 +186,23 @@ class SourceFiles( | |||||||||||||||||||||
|
||||||||||||||||||||||
private fun findSourceFiles(root: Path): Set<URI> { | ||||||||||||||||||||||
val sourceMatcher = FileSystems.getDefault().getPathMatcher("glob:*.{kt,kts}") | ||||||||||||||||||||||
return SourceExclusions(listOf(root), scriptsConfig) | ||||||||||||||||||||||
return SourceExclusions(listOf(root), scriptsConfig, additionalSourceExclusions) | ||||||||||||||||||||||
.walkIncluded() | ||||||||||||||||||||||
.filter { sourceMatcher.matches(it.fileName) } | ||||||||||||||||||||||
.map(Path::toUri) | ||||||||||||||||||||||
.toSet() | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
fun updateExclusions() { | ||||||||||||||||||||||
exclusions = SourceExclusions(workspaceRoots, scriptsConfig) | ||||||||||||||||||||||
exclusions = SourceExclusions(workspaceRoots, scriptsConfig, additionalSourceExclusions) | ||||||||||||||||||||||
LOG.info("Updated exclusions: ${exclusions.excludedPatterns}") | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
fun updateAdditionalExclusions(exclusions: MutableList<String>) { | ||||||||||||||||||||||
additionalSourceExclusions.addAll(exclusions) | ||||||||||||||||||||||
updateExclusions() | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
fun isOpen(uri: URI): Boolean = (uri in open) | ||||||||||||||||||||||
|
||||||||||||||||||||||
fun isIncluded(uri: URI): Boolean = exclusions.isURIIncluded(uri) | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about whether we should put this into the initialization options. That makes it a bit more cumbersome on the VSCode side and I think it could be nice (in the future) if these options could be updated while the language server is running, even if we don't fully support "hot" configuration updates yet.