@@ -74,12 +74,13 @@ class KotlinTextDocumentService(
74
74
ALWAYS , AFTER_DOT , NEVER
75
75
}
76
76
77
- private fun recover (position : TextDocumentPositionParams , recompile : Recompile ): Pair <CompiledFile , Int > {
77
+ private fun recover (position : TextDocumentPositionParams , recompile : Recompile ): Pair <CompiledFile , Int >? {
78
78
return recover(position.textDocument.uri, position.position, recompile)
79
79
}
80
80
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 >? {
82
82
val uri = parseURI(uriString)
83
+ if (! sf.isIncluded(uri)) return null
83
84
val content = sp.content(uri)
84
85
val offset = offset(content, position.line, position.character)
85
86
val shouldRecompile = when (recompile) {
@@ -92,26 +93,26 @@ class KotlinTextDocumentService(
92
93
}
93
94
94
95
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()
96
97
codeActions(file, sp.index, params.range, params.context)
97
98
}
98
99
99
100
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()
101
102
provideHints(file, config.inlayHints)
102
103
}
103
104
104
105
override fun hover (position : HoverParams ): CompletableFuture <Hover ?> = async.compute {
105
106
reportTime {
106
107
LOG .info(" Hovering at {}" , describePosition(position))
107
108
108
- val (file, cursor) = recover(position, Recompile .NEVER )
109
+ val (file, cursor) = recover(position, Recompile .NEVER ) ? : return @compute null
109
110
hoverAt(file, cursor) ? : noResult(" No hover found at ${describePosition(position)} " , null )
110
111
}
111
112
}
112
113
113
114
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()
115
116
documentHighlightsAt(file, cursor)
116
117
}
117
118
@@ -123,7 +124,7 @@ class KotlinTextDocumentService(
123
124
reportTime {
124
125
LOG .info(" Go-to-definition at {}" , describePosition(position))
125
126
126
- val (file, cursor) = recover(position, Recompile .NEVER )
127
+ val (file, cursor) = recover(position, Recompile .NEVER ) ? : return @compute Either .forLeft(emptyList())
127
128
goToDefinition(file, cursor, uriContentProvider.classContentProvider, tempDirectory, config.externalSources, cp)
128
129
?.let (::listOf)
129
130
?.let { Either .forLeft<List <Location >, List <LocationLink >>(it) }
@@ -144,19 +145,19 @@ class KotlinTextDocumentService(
144
145
}
145
146
146
147
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
148
149
renameSymbol(file, cursor, sp, params.newName)
149
150
}
150
151
151
- override fun completion (position : CompletionParams ) = async.compute {
152
+ override fun completion (position : CompletionParams ): CompletableFuture < Either < List < CompletionItem >, CompletionList>> = async.compute {
152
153
reportTime {
153
154
LOG .info(" Completing at {}" , describePosition(position))
154
155
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
156
157
val completions = completions(file, cursor, sp.index, config.completion)
157
158
LOG .info(" Found {} items" , completions.items.size)
158
159
159
- Either .forRight< List < CompletionItem >, CompletionList > (completions)
160
+ Either .forRight(completions)
160
161
}
161
162
}
162
163
@@ -195,7 +196,7 @@ class KotlinTextDocumentService(
195
196
reportTime {
196
197
LOG .info(" Signature help at {}" , describePosition(position))
197
198
198
- val (file, cursor) = recover(position, Recompile .NEVER )
199
+ val (file, cursor) = recover(position, Recompile .NEVER ) ? : return @compute null
199
200
fetchSignatureHelpAt(file, cursor) ? : noResult(" No function call around ${describePosition(position)} " , null )
200
201
}
201
202
}
0 commit comments