Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ec4e302

Browse files
author
Lorenz Bateman
committed
Fallback to declaration text range
Not all named declarations have a name identifier. In those cases fallback to using the range that encloses the whole named declaration rather than returning nothing.
1 parent 4056a8b commit ec4e302

File tree

1 file changed

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

1 file changed

+14
-12
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import org.eclipse.lsp4j.WorkspaceSymbolLocation
1212
import org.eclipse.lsp4j.jsonrpc.messages.Either
1313
import org.javacs.kt.SourcePath
1414
import org.javacs.kt.position.range
15+
import org.javacs.kt.position.toURIString
1516
import org.javacs.kt.util.containsCharactersInOrder
1617
import org.javacs.kt.util.preOrderTraversal
17-
import org.javacs.kt.util.toPath
1818
import org.jetbrains.kotlin.psi.*
1919
import org.jetbrains.kotlin.psi.psiUtil.parents
2020

@@ -82,20 +82,22 @@ private fun symbolKind(d: KtNamedDeclaration): SymbolKind =
8282
else -> throw IllegalArgumentException("Unexpected symbol $d")
8383
}
8484

85-
private fun location(d: KtNamedDeclaration): Location? {
86-
val uri = d.containingFile.toPath().toUri().toString()
87-
val (content, textRange) = try { d.containingFile?.text to d.nameIdentifier?.textRange } catch (e: Exception) { null to null }
88-
return if (content != null && textRange != null) {
89-
Location(uri, range(content, textRange))
90-
} else {
85+
private fun location(d: KtNamedDeclaration): Location? =
86+
try {
87+
val content = d.containingFile?.text
88+
val locationInContent = (d.nameIdentifier?.textRange ?: d.textRange)
89+
if (content != null && locationInContent != null) {
90+
Location(d.containingFile.toURIString(), range(content, locationInContent))
91+
} else {
92+
null
93+
}
94+
} catch (e: Exception) {
9195
null
9296
}
93-
}
9497

95-
private fun workspaceSymbolLocation(d: KtNamedDeclaration): WorkspaceSymbolLocation {
96-
val uri = d.containingFile.toPath().toUri().toString()
97-
return WorkspaceSymbolLocation(uri)
98-
}
98+
99+
private fun workspaceSymbolLocation(d: KtNamedDeclaration): WorkspaceSymbolLocation =
100+
WorkspaceSymbolLocation(d.containingFile.toURIString())
99101

100102
private fun symbolContainer(d: KtNamedDeclaration): String? =
101103
d.parents

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /