summaryrefslogtreecommitdiff
path: root/support/texlab/src/features/definition.rs
diff options
context:
space:
mode:
Diffstat (limited to 'support/texlab/src/features/definition.rs')
-rw-r--r--support/texlab/src/features/definition.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/support/texlab/src/features/definition.rs b/support/texlab/src/features/definition.rs
new file mode 100644
index 0000000000..c49f172399
--- /dev/null
+++ b/support/texlab/src/features/definition.rs
@@ -0,0 +1,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))
+}