Skip to content

Commit f0be2db

Browse files
committed
Small stylistic improvements in doDocumentSymbols
1 parent dffcba7 commit f0be2db

File tree

1 file changed

+11
-12
lines changed
  • server/src/main/kotlin/org/javacs/kt/symbols

1 file changed

+11
-12
lines changed

server/src/main/kotlin/org/javacs/kt/symbols/Symbols.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@ import org.jetbrains.kotlin.psi.*
1515
import org.jetbrains.kotlin.psi.psiUtil.parents
1616

1717
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) }
1919

2020
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
3231
}
3332

3433
private const val MAX_SYMBOLS = 50

0 commit comments

Comments
 (0)