diff options
Diffstat (limited to 'support/texlab/src/features/definition/entry.rs')
-rw-r--r-- | support/texlab/src/features/definition/entry.rs | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/support/texlab/src/features/definition/entry.rs b/support/texlab/src/features/definition/entry.rs index 1dcd983af1..a945b18c41 100644 --- a/support/texlab/src/features/definition/entry.rs +++ b/support/texlab/src/features/definition/entry.rs @@ -1,24 +1,21 @@ -use std::sync::Arc; - -use lsp_types::GotoDefinitionParams; use rowan::ast::AstNode; use crate::{ - features::cursor::CursorContext, syntax::{ bibtex::{self, HasName}, latex, }, + util::cursor::CursorContext, }; use super::DefinitionResult; -pub(super) fn goto_entry_definition( - context: &CursorContext<GotoDefinitionParams>, -) -> Option<Vec<DefinitionResult>> { +pub(super) fn goto_definition(context: &CursorContext) -> Option<Vec<DefinitionResult>> { + let db = context.db; + let word = context .cursor - .as_latex() + .as_tex() .filter(|token| token.kind() == latex::WORD)?; let key = latex::Key::cast(word.parent()?)?; @@ -27,16 +24,13 @@ pub(super) fn goto_entry_definition( let origin_selection_range = latex::small_range(&key); - for document in context.request.workspace.documents_by_uri.values() { - if let Some(data) = document.data.as_bibtex() { - for entry in bibtex::SyntaxNode::new_root(data.green.clone()) - .children() - .filter_map(bibtex::Entry::cast) - { + for document in context.related() { + if let Some(data) = document.parse(db).as_bib() { + for entry in data.root(db).children().filter_map(bibtex::Entry::cast) { if let Some(key) = entry.name_token().filter(|k| k.text() == word.text()) { return Some(vec![DefinitionResult { origin_selection_range, - target_uri: Arc::clone(&document.uri), + target: document, target_selection_range: key.text_range(), target_range: entry.syntax().text_range(), }]); |