@@ -15,20 +15,19 @@ import org.jetbrains.kotlin.psi.*
15
15
import org.jetbrains.kotlin.psi.psiUtil.parents
16
16
17
17
fun documentSymbols (file : KtFile ): List <Either <SymbolInformation , DocumentSymbol >> =
18
- doDocumentSymbols(file).toList(). map { Either .forRight<SymbolInformation , DocumentSymbol >(it) }
18
+ doDocumentSymbols(file).map { Either .forRight<SymbolInformation , DocumentSymbol >(it) }
19
19
20
20
private fun doDocumentSymbols (element : PsiElement ): List <DocumentSymbol > {
21
- val children = element.children.flatMap(::doDocumentSymbols);
22
- val currentDecl = pickImportantElements(element, true );
23
- if (currentDecl != null ) {
24
- val file = element.containingFile
25
- val span = range(file.text, currentDecl.textRange)
26
- val nameIdentifier = currentDecl.nameIdentifier
27
- val nameSpan = if (nameIdentifier != null ) range(file.text, nameIdentifier.textRange) else span
28
- return listOf (DocumentSymbol (currentDecl.name? : " <anonymous>" , symbolKind(currentDecl), span, nameSpan, null , children));
29
- } else {
30
- return children;
31
- }
21
+ val children = element.children.flatMap(::doDocumentSymbols)
22
+
23
+ return pickImportantElements(element, true )?.let { currentDecl ->
24
+ val file = element.containingFile
25
+ val span = range(file.text, currentDecl.textRange)
26
+ val nameIdentifier = currentDecl.nameIdentifier
27
+ val nameSpan = nameIdentifier?.let { range(file.text, it.textRange) } ? : span
28
+ val symbol = DocumentSymbol (currentDecl.name ? : " <anonymous>" , symbolKind(currentDecl), span, nameSpan, null , children)
29
+ listOf (symbol)
30
+ } ? : children
32
31
}
33
32
34
33
private const val MAX_SYMBOLS = 50
0 commit comments