@@ -34,6 +34,7 @@ import java.io.Closeable
3434import java.nio.file.Path
3535import java.time.Duration
3636import java.util.concurrent.CompletableFuture
37+ import org.javacs.kt.codelens.findCodeLenses
3738
3839class KotlinTextDocumentService (
3940 private val sf : SourceFiles ,
@@ -144,8 +145,14 @@ class KotlinTextDocumentService(
144145 ))
145146 }
146147
147- override fun codeLens (params : CodeLensParams ): CompletableFuture <List <CodeLens >> {
148- TODO (" not implemented" )
148+ override fun codeLens (params : CodeLensParams ): CompletableFuture <List <CodeLens >> = async.compute {
149+ reportTime {
150+ LOG .info(" Finding code lenses in {}" , describeURI(params.textDocument.uri))
151+
152+ val uri = parseURI(params.textDocument.uri)
153+ val file = sp.currentVersion(uri)
154+ return @compute findCodeLenses(file)
155+ }
149156 }
150157
151158 override fun rename (params : RenameParams ) = async.compute {
@@ -263,8 +270,66 @@ class KotlinTextDocumentService(
263270 }
264271 }
265272
266- override fun resolveCodeLens (unresolved : CodeLens ): CompletableFuture <CodeLens > {
267- TODO (" not implemented" )
273+ override fun resolveCodeLens (unresolved : CodeLens ): CompletableFuture <CodeLens > = async.compute {
274+ reportTime {
275+ LOG .info(" Resolving code lens {}" , unresolved.command?.command)
276+
277+ val command = unresolved.command
278+ if (command == null ) {
279+ return @compute unresolved
280+ }
281+
282+ val args = command.arguments as List <* >
283+ if (args.size != 3 ) {
284+ return @compute unresolved
285+ }
286+
287+ val uri = args[0 ] as String
288+ val line = args[1 ] as Int
289+ val character = args[2 ] as Int
290+
291+ val file = sp.currentVersion(parseURI(uri))
292+ val content = sp.content(parseURI(uri))
293+ val offset = offset(content, line, character)
294+
295+ when (command.command) {
296+ " kotlin.showImplementations" -> {
297+ val implementations = findImplementation(sp, sf, file, offset)
298+ if (implementations.isNotEmpty()) {
299+ unresolved.command = Command (
300+ command.title,
301+ command.command,
302+ listOf (uri, line, character, implementations)
303+ )
304+ }
305+ }
306+ " kotlin.showSubclasses" -> {
307+ val implementations = findImplementation(sp, sf, file, offset)
308+ if (implementations.isNotEmpty()) {
309+ unresolved.command = Command (
310+ command.title,
311+ command.command,
312+ listOf (uri, line, character, implementations)
313+ )
314+ }
315+ }
316+ " kotlin.showReferences" -> {
317+ val filePath = parseURI(uri).filePath
318+ if (filePath != null ) {
319+ val references = findReferences(filePath, offset, sp)
320+ if (references.isNotEmpty()) {
321+ unresolved.command = Command (
322+ command.title,
323+ command.command,
324+ listOf (uri, line, character, references)
325+ )
326+ }
327+ }
328+ }
329+ }
330+
331+ return @compute unresolved
332+ }
268333 }
269334
270335 private fun describePosition (position : TextDocumentPositionParams ): String {
0 commit comments