Skip to content

Commit 9592c11

Browse files
committed
Only recover and provide language features for non-excluded files
1 parent 24b57b5 commit 9592c11

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@ class KotlinTextDocumentService(
7474
ALWAYS, AFTER_DOT, NEVER
7575
}
7676

77-
private fun recover(position: TextDocumentPositionParams, recompile: Recompile): Pair<CompiledFile, Int> {
77+
private fun recover(position: TextDocumentPositionParams, recompile: Recompile): Pair<CompiledFile, Int>? {
7878
return recover(position.textDocument.uri, position.position, recompile)
7979
}
8080

81-
private fun recover(uriString: String, position: Position, recompile: Recompile): Pair<CompiledFile, Int> {
81+
private fun recover(uriString: String, position: Position, recompile: Recompile): Pair<CompiledFile, Int>? {
8282
val uri = parseURI(uriString)
83+
if (!sf.isIncluded(uri)) return null
8384
val content = sp.content(uri)
8485
val offset = offset(content, position.line, position.character)
8586
val shouldRecompile = when (recompile) {
@@ -92,26 +93,26 @@ class KotlinTextDocumentService(
9293
}
9394

9495
override fun codeAction(params: CodeActionParams): CompletableFuture<List<Either<Command, CodeAction>>> = async.compute {
95-
val (file, _) = recover(params.textDocument.uri, params.range.start, Recompile.NEVER)
96+
val (file, _) = recover(params.textDocument.uri, params.range.start, Recompile.NEVER) ?: return@compute emptyList()
9697
codeActions(file, sp.index, params.range, params.context)
9798
}
9899

99100
override fun inlayHint(params: InlayHintParams): CompletableFuture<List<InlayHint>> = async.compute {
100-
val (file, _) = recover(params.textDocument.uri, params.range.start, Recompile.ALWAYS)
101+
val (file, _) = recover(params.textDocument.uri, params.range.start, Recompile.ALWAYS) ?: return@compute emptyList()
101102
provideHints(file, config.inlayHints)
102103
}
103104

104105
override fun hover(position: HoverParams): CompletableFuture<Hover?> = async.compute {
105106
reportTime {
106107
LOG.info("Hovering at {}", describePosition(position))
107108

108-
val (file, cursor) = recover(position, Recompile.NEVER)
109+
val (file, cursor) = recover(position, Recompile.NEVER) ?: return@compute null
109110
hoverAt(file, cursor) ?: noResult("No hover found at ${describePosition(position)}", null)
110111
}
111112
}
112113

113114
override fun documentHighlight(position: DocumentHighlightParams): CompletableFuture<List<DocumentHighlight>> = async.compute {
114-
val (file, cursor) = recover(position.textDocument.uri, position.position, Recompile.NEVER)
115+
val (file, cursor) = recover(position.textDocument.uri, position.position, Recompile.NEVER) ?: return@compute emptyList()
115116
documentHighlightsAt(file, cursor)
116117
}
117118

@@ -123,7 +124,7 @@ class KotlinTextDocumentService(
123124
reportTime {
124125
LOG.info("Go-to-definition at {}", describePosition(position))
125126

126-
val (file, cursor) = recover(position, Recompile.NEVER)
127+
val (file, cursor) = recover(position, Recompile.NEVER) ?: return@compute Either.forLeft(emptyList())
127128
goToDefinition(file, cursor, uriContentProvider.classContentProvider, tempDirectory, config.externalSources, cp)
128129
?.let(::listOf)
129130
?.let { Either.forLeft<List<Location>, List<LocationLink>>(it) }
@@ -144,19 +145,19 @@ class KotlinTextDocumentService(
144145
}
145146

146147
override fun rename(params: RenameParams) = async.compute {
147-
val (file, cursor) = recover(params, Recompile.NEVER)
148+
val (file, cursor) = recover(params, Recompile.NEVER) ?: return@compute null
148149
renameSymbol(file, cursor, sp, params.newName)
149150
}
150151

151-
override fun completion(position: CompletionParams) = async.compute {
152+
override fun completion(position: CompletionParams): CompletableFuture<Either<List<CompletionItem>, CompletionList>> = async.compute {
152153
reportTime {
153154
LOG.info("Completing at {}", describePosition(position))
154155

155-
val (file, cursor) = recover(position, Recompile.NEVER) // TODO: Investigate when to recompile
156+
val (file, cursor) = recover(position, Recompile.NEVER) ?: return@compute Either.forRight(CompletionList()) // TODO: Investigate when to recompile
156157
val completions = completions(file, cursor, sp.index, config.completion)
157158
LOG.info("Found {} items", completions.items.size)
158159

159-
Either.forRight<List<CompletionItem>, CompletionList>(completions)
160+
Either.forRight(completions)
160161
}
161162
}
162163

@@ -195,7 +196,7 @@ class KotlinTextDocumentService(
195196
reportTime {
196197
LOG.info("Signature help at {}", describePosition(position))
197198

198-
val (file, cursor) = recover(position, Recompile.NEVER)
199+
val (file, cursor) = recover(position, Recompile.NEVER) ?: return@compute null
199200
fetchSignatureHelpAt(file, cursor) ?: noResult("No function call around ${describePosition(position)}", null)
200201
}
201202
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ class SourceFiles(
192192
}
193193

194194
fun isOpen(uri: URI): Boolean = (uri in open)
195+
196+
fun isIncluded(uri: URI): Boolean = exclusions.isURIIncluded(uri)
195197
}
196198

197199
private fun patch(sourceText: String, change: TextDocumentContentChangeEvent): String {

0 commit comments

Comments
 (0)