summaryrefslogtreecommitdiff
path: root/support/texlab/src/features/definition.rs
blob: c49f1723994648f6c16d4a86f1a03693c55936f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
mod command;
mod document;
mod entry;
mod label;
mod string;

use cancellation::CancellationToken;
use lsp_types::{GotoDefinitionParams, GotoDefinitionResponse};

use self::{
    command::goto_command_definition, document::goto_document_definition,
    entry::goto_entry_definition, label::goto_label_definition, string::goto_string_definition,
};

use super::{cursor::CursorContext, FeatureRequest};

pub fn goto_definition(
    request: FeatureRequest<GotoDefinitionParams>,
    cancellation_token: &CancellationToken,
) -> Option<GotoDefinitionResponse> {
    let context = CursorContext::new(request);
    log::debug!("[Definition] Cursor: {:?}", context.cursor);
    let links = goto_command_definition(&context, cancellation_token)
        .or_else(|| goto_document_definition(&context, cancellation_token))
        .or_else(|| goto_entry_definition(&context, cancellation_token))
        .or_else(|| goto_label_definition(&context, cancellation_token))
        .or_else(|| goto_string_definition(&context, cancellation_token))?;
    Some(GotoDefinitionResponse::Link(links))
}