mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-12-23 09:19:21 +00:00
Implement definition request for BibTeX entries
This commit is contained in:
parent
40d3d3c45c
commit
f1ef002baf
3 changed files with 36 additions and 7 deletions
|
|
@ -10,10 +10,7 @@ import texlab.completion.latex.*
|
|||
import texlab.completion.latex.data.LatexComponentDatabase
|
||||
import texlab.completion.latex.data.LatexComponentDatabaseListener
|
||||
import texlab.completion.latex.data.LatexResolver
|
||||
import texlab.definition.AggregateDefinitionProvider
|
||||
import texlab.definition.DefinitionProvider
|
||||
import texlab.definition.DefinitionRequest
|
||||
import texlab.definition.LatexLabelDefinitionProvider
|
||||
import texlab.definition.*
|
||||
import texlab.folding.*
|
||||
import texlab.link.AggregateLinkProvider
|
||||
import texlab.link.LatexIncludeLinkProvider
|
||||
|
|
@ -92,7 +89,10 @@ class TextDocumentServiceImpl(private val workspace: Workspace) : TextDocumentSe
|
|||
|
||||
private val linkProvider: LinkProvider = AggregateLinkProvider(LatexIncludeLinkProvider)
|
||||
|
||||
private val definitionProvider: DefinitionProvider = AggregateDefinitionProvider(LatexLabelDefinitionProvider)
|
||||
private val definitionProvider: DefinitionProvider =
|
||||
AggregateDefinitionProvider(
|
||||
LatexLabelDefinitionProvider,
|
||||
BibtexEntryDefinitionProvider)
|
||||
|
||||
override fun didOpen(params: DidOpenTextDocumentParams) {
|
||||
params.textDocument.apply {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package texlab.definition
|
||||
|
||||
import org.eclipse.lsp4j.Location
|
||||
import texlab.BibtexDocument
|
||||
import texlab.LatexDocument
|
||||
import texlab.contains
|
||||
import texlab.syntax.bibtex.BibtexEntrySyntax
|
||||
|
||||
object BibtexEntryDefinitionProvider : DefinitionProvider {
|
||||
override fun find(request: DefinitionRequest): Location? {
|
||||
if (request.document !is LatexDocument) {
|
||||
return null
|
||||
}
|
||||
|
||||
val reference = request.document.tree.citations
|
||||
.firstOrNull { it.name.range.contains(request.position) } ?: return null
|
||||
|
||||
for (document in request.relatedDocuments.filterIsInstance<BibtexDocument>()) {
|
||||
val definition = document.tree.root.children
|
||||
.filterIsInstance<BibtexEntrySyntax>()
|
||||
.firstOrNull { it.name?.text == reference.name.text }
|
||||
if (definition?.name != null) {
|
||||
return Location(document.uri.toString(), definition.name.range)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
|
@ -40,8 +40,7 @@ object BibtexEntryRenamer : Renamer {
|
|||
}
|
||||
|
||||
private fun findEntry(document: BibtexDocument, position: Position): Token? {
|
||||
return document.tree.root
|
||||
.descendants()
|
||||
return document.tree.root.children
|
||||
.filterIsInstance<BibtexEntrySyntax>()
|
||||
.firstOrNull { it.name != null && it.name.range.contains(position) }?.name
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue