summaryrefslogtreecommitdiff
path: root/support/texlab/src/hover/latex_component.rs
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-12-03 03:01:24 +0000
committerNorbert Preining <norbert@preining.info>2019-12-03 03:01:24 +0000
commitb8d4bb76703bcb15578e2b23c5d256532180b894 (patch)
treebedd1df7a00521a2bd986b3c0289d6556a59e39b /support/texlab/src/hover/latex_component.rs
parent02e4625a78a5029e8b5dc2a4ec70193b232f497e (diff)
CTAN sync 201912030301
Diffstat (limited to 'support/texlab/src/hover/latex_component.rs')
-rw-r--r--support/texlab/src/hover/latex_component.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/support/texlab/src/hover/latex_component.rs b/support/texlab/src/hover/latex_component.rs
new file mode 100644
index 0000000000..4d262a6891
--- /dev/null
+++ b/support/texlab/src/hover/latex_component.rs
@@ -0,0 +1,39 @@
+use crate::completion::DATABASE;
+use crate::range::RangeExt;
+use crate::syntax::*;
+use crate::workspace::*;
+use futures_boxed::boxed;
+use lsp_types::{Hover, HoverContents, TextDocumentPositionParams};
+
+#[derive(Debug, PartialEq, Eq, Clone)]
+pub struct LatexComponentHoverProvider;
+
+impl FeatureProvider for LatexComponentHoverProvider {
+ type Params = TextDocumentPositionParams;
+ type Output = Option<Hover>;
+
+ #[boxed]
+ async fn execute<'a>(
+ &'a self,
+ request: &'a FeatureRequest<TextDocumentPositionParams>,
+ ) -> Option<Hover> {
+ if let SyntaxTree::Latex(tree) = &request.document().tree {
+ for include in &tree.includes {
+ if include.kind == LatexIncludeKind::Package
+ || include.kind == LatexIncludeKind::Class
+ {
+ for path in include.paths() {
+ if path.range().contains(request.params.position) {
+ let documentation = DATABASE.documentation(path.text())?;
+ return Some(Hover {
+ contents: HoverContents::Markup(documentation),
+ range: Some(path.range()),
+ });
+ }
+ }
+ }
+ }
+ }
+ None
+ }
+}