@@ -35,6 +35,7 @@ import java.nio.file.Path
35
35
import java.time.Duration
36
36
import java.util.concurrent.CompletableFuture
37
37
import org.javacs.kt.implementation.findImplementation
38
+ import org.javacs.kt.codelens.findCodeLenses
38
39
39
40
class KotlinTextDocumentService (
40
41
private val sf : SourceFiles ,
@@ -145,8 +146,14 @@ class KotlinTextDocumentService(
145
146
))
146
147
}
147
148
148
- override fun codeLens (params : CodeLensParams ): CompletableFuture <List <CodeLens >> {
149
- TODO (" not implemented" )
149
+ override fun codeLens (params : CodeLensParams ): CompletableFuture <List <CodeLens >> = async.compute {
150
+ reportTime {
151
+ LOG .info(" Finding code lenses in {}" , describeURI(params.textDocument.uri))
152
+
153
+ val uri = parseURI(params.textDocument.uri)
154
+ val file = sp.currentVersion(uri)
155
+ return @compute findCodeLenses(file)
156
+ }
150
157
}
151
158
152
159
override fun rename (params : RenameParams ) = async.compute {
@@ -264,8 +271,66 @@ class KotlinTextDocumentService(
264
271
}
265
272
}
266
273
267
- override fun resolveCodeLens (unresolved : CodeLens ): CompletableFuture <CodeLens > {
268
- TODO (" not implemented" )
274
+ override fun resolveCodeLens (unresolved : CodeLens ): CompletableFuture <CodeLens > = async.compute {
275
+ reportTime {
276
+ LOG .info(" Resolving code lens {}" , unresolved.command?.command)
277
+
278
+ val command = unresolved.command
279
+ if (command == null ) {
280
+ return @compute unresolved
281
+ }
282
+
283
+ val args = command.arguments as List <* >
284
+ if (args.size != 3 ) {
285
+ return @compute unresolved
286
+ }
287
+
288
+ val uri = args[0 ] as String
289
+ val line = args[1 ] as Int
290
+ val character = args[2 ] as Int
291
+
292
+ val file = sp.currentVersion(parseURI(uri))
293
+ val content = sp.content(parseURI(uri))
294
+ val offset = offset(content, line, character)
295
+
296
+ when (command.command) {
297
+ " kotlin.showImplementations" -> {
298
+ val implementations = findImplementation(sp, sf, file, offset)
299
+ if (implementations.isNotEmpty()) {
300
+ unresolved.command = Command (
301
+ command.title,
302
+ command.command,
303
+ listOf (uri, line, character, implementations)
304
+ )
305
+ }
306
+ }
307
+ " kotlin.showSubclasses" -> {
308
+ val implementations = findImplementation(sp, sf, file, offset)
309
+ if (implementations.isNotEmpty()) {
310
+ unresolved.command = Command (
311
+ command.title,
312
+ command.command,
313
+ listOf (uri, line, character, implementations)
314
+ )
315
+ }
316
+ }
317
+ " kotlin.showReferences" -> {
318
+ val filePath = parseURI(uri).filePath
319
+ if (filePath != null ) {
320
+ val references = findReferences(filePath, offset, sp)
321
+ if (references.isNotEmpty()) {
322
+ unresolved.command = Command (
323
+ command.title,
324
+ command.command,
325
+ listOf (uri, line, character, references)
326
+ )
327
+ }
328
+ }
329
+ }
330
+ }
331
+
332
+ return @compute unresolved
333
+ }
269
334
}
270
335
271
336
override fun implementation (params : ImplementationParams ): CompletableFuture <Either <List <Location >, List<LocationLink>>> = async.compute {
0 commit comments