summaryrefslogtreecommitdiff
path: root/support/texlab/crates/hover
diff options
context:
space:
mode:
Diffstat (limited to 'support/texlab/crates/hover')
-rw-r--r--support/texlab/crates/hover/Cargo.toml2
-rw-r--r--support/texlab/crates/hover/src/citation.rs12
-rw-r--r--support/texlab/crates/hover/src/entry_type.rs4
-rw-r--r--support/texlab/crates/hover/src/field_type.rs4
-rw-r--r--support/texlab/crates/hover/src/label.rs9
-rw-r--r--support/texlab/crates/hover/src/lib.rs34
-rw-r--r--support/texlab/crates/hover/src/package.rs4
-rw-r--r--support/texlab/crates/hover/src/string_ref.rs4
-rw-r--r--support/texlab/crates/hover/src/tests.rs9
9 files changed, 33 insertions, 49 deletions
diff --git a/support/texlab/crates/hover/Cargo.toml b/support/texlab/crates/hover/Cargo.toml
index 0db19b8189..af8f4f566b 100644
--- a/support/texlab/crates/hover/Cargo.toml
+++ b/support/texlab/crates/hover/Cargo.toml
@@ -11,7 +11,7 @@ base-db = { path = "../base-db" }
bibtex-utils = { path = "../bibtex-utils" }
citeproc = { path = "../citeproc" }
completion-data = { path = "../completion-data" }
-rowan = "0.15.11"
+rowan = "0.15.13"
syntax = { path = "../syntax" }
[dev-dependencies]
diff --git a/support/texlab/crates/hover/src/citation.rs b/support/texlab/crates/hover/src/citation.rs
index 49e5359bba..372668997e 100644
--- a/support/texlab/crates/hover/src/citation.rs
+++ b/support/texlab/crates/hover/src/citation.rs
@@ -4,14 +4,14 @@ use syntax::bibtex;
use crate::{Hover, HoverData, HoverParams};
-pub(super) fn find_hover<'db>(params: &HoverParams<'db>) -> Option<Hover<'db>> {
- let offset = params.offset;
+pub(super) fn find_hover<'a>(params: &HoverParams<'a>) -> Option<Hover<'a>> {
+ let HoverParams { feature, offset } = params;
- let (name, range) = match &params.document.data {
+ let (name, range) = match &feature.document.data {
DocumentData::Tex(data) => {
let result = queries::object_at_cursor(
&data.semantics.citations,
- offset,
+ *offset,
queries::SearchMode::Full,
)?;
(&result.object.name.text, result.range)
@@ -19,7 +19,7 @@ pub(super) fn find_hover<'db>(params: &HoverParams<'db>) -> Option<Hover<'db>> {
DocumentData::Bib(data) => {
let result = queries::object_at_cursor(
&data.semantics.entries,
- offset,
+ *offset,
queries::SearchMode::Name,
)?;
(&result.object.name.text, result.range)
@@ -27,7 +27,7 @@ pub(super) fn find_hover<'db>(params: &HoverParams<'db>) -> Option<Hover<'db>> {
_ => return None,
};
- let text = params.project.documents.iter().find_map(|document| {
+ let text = feature.project.documents.iter().find_map(|document| {
let data = document.data.as_bib()?;
let root = bibtex::Root::cast(data.root_node())?;
let entry = root.find_entry(name)?;
diff --git a/support/texlab/crates/hover/src/entry_type.rs b/support/texlab/crates/hover/src/entry_type.rs
index f4941b4ee0..f3417e960d 100644
--- a/support/texlab/crates/hover/src/entry_type.rs
+++ b/support/texlab/crates/hover/src/entry_type.rs
@@ -3,8 +3,8 @@ use syntax::bibtex;
use crate::{Hover, HoverData, HoverParams};
-pub(super) fn find_hover<'db>(params: &'db HoverParams) -> Option<Hover<'db>> {
- let data = params.document.data.as_bib()?;
+pub(super) fn find_hover<'a>(params: &HoverParams<'a>) -> Option<Hover<'a>> {
+ let data = params.feature.document.data.as_bib()?;
let root = data.root_node();
let name = root
.token_at_offset(params.offset)
diff --git a/support/texlab/crates/hover/src/field_type.rs b/support/texlab/crates/hover/src/field_type.rs
index 18ebe6b78f..ec9078410a 100644
--- a/support/texlab/crates/hover/src/field_type.rs
+++ b/support/texlab/crates/hover/src/field_type.rs
@@ -4,8 +4,8 @@ use syntax::bibtex;
use crate::{Hover, HoverData, HoverParams};
-pub(super) fn find_hover<'db>(params: &HoverParams<'db>) -> Option<Hover<'db>> {
- let data = params.document.data.as_bib()?;
+pub(super) fn find_hover<'a>(params: &HoverParams<'a>) -> Option<Hover<'a>> {
+ let data = params.feature.document.data.as_bib()?;
let root = data.root_node();
let name = root
.token_at_offset(params.offset)
diff --git a/support/texlab/crates/hover/src/label.rs b/support/texlab/crates/hover/src/label.rs
index fc9694fc6c..fc944aeaed 100644
--- a/support/texlab/crates/hover/src/label.rs
+++ b/support/texlab/crates/hover/src/label.rs
@@ -8,19 +8,20 @@ use base_db::{
use crate::{Hover, HoverData, HoverParams};
-pub(super) fn find_hover<'db>(params: &'db HoverParams<'db>) -> Option<Hover<'db>> {
- let data = params.document.data.as_tex()?;
+pub(super) fn find_hover<'a>(params: &HoverParams<'a>) -> Option<Hover<'a>> {
+ let feature = &params.feature;
+ let data = feature.document.data.as_tex()?;
let cursor = queries::object_at_cursor(
&data.semantics.labels,
params.offset,
queries::SearchMode::Full,
)?;
- let (_, definition) = tex::Label::find_all(&params.project)
+ let (_, definition) = tex::Label::find_all(&feature.project)
.filter(|(_, label)| label.kind == tex::LabelKind::Definition)
.find(|(_, label)| label.name_text() == cursor.object.name_text())?;
- let label = render_label(params.workspace, &params.project, definition)?;
+ let label = render_label(feature.workspace, &feature.project, definition)?;
Some(Hover {
range: cursor.range,
data: HoverData::Label(label),
diff --git a/support/texlab/crates/hover/src/lib.rs b/support/texlab/crates/hover/src/lib.rs
index 88be3b919a..bd16be3282 100644
--- a/support/texlab/crates/hover/src/lib.rs
+++ b/support/texlab/crates/hover/src/lib.rs
@@ -8,30 +8,16 @@ mod string_ref;
use base_db::{
data::{BibtexEntryType, BibtexFieldType},
util::RenderedLabel,
- Document, Project, Workspace,
+ FeatureParams,
};
use rowan::{TextRange, TextSize};
#[derive(Debug)]
-pub struct HoverParams<'db> {
- pub document: &'db Document,
- pub project: Project<'db>,
- pub workspace: &'db Workspace,
+pub struct HoverParams<'a> {
+ pub feature: FeatureParams<'a>,
pub offset: TextSize,
}
-impl<'db> HoverParams<'db> {
- pub fn new(workspace: &'db Workspace, document: &'db Document, offset: TextSize) -> Self {
- let project = workspace.project(document);
- Self {
- document,
- project,
- workspace,
- offset,
- }
- }
-}
-
#[derive(Debug, Clone)]
pub struct Hover<'db> {
pub range: TextRange,
@@ -48,13 +34,13 @@ pub enum HoverData<'db> {
StringRef(String),
}
-pub fn find<'db>(params: &'db HoverParams<'db>) -> Option<Hover<'db>> {
- citation::find_hover(params)
- .or_else(|| package::find_hover(params))
- .or_else(|| entry_type::find_hover(params))
- .or_else(|| field_type::find_hover(params))
- .or_else(|| label::find_hover(params))
- .or_else(|| string_ref::find_hover(params))
+pub fn find(params: HoverParams) -> Option<Hover> {
+ citation::find_hover(&params)
+ .or_else(|| package::find_hover(&params))
+ .or_else(|| entry_type::find_hover(&params))
+ .or_else(|| field_type::find_hover(&params))
+ .or_else(|| label::find_hover(&params))
+ .or_else(|| string_ref::find_hover(&params))
}
#[cfg(test)]
diff --git a/support/texlab/crates/hover/src/package.rs b/support/texlab/crates/hover/src/package.rs
index 1d6b328860..1dfc86573d 100644
--- a/support/texlab/crates/hover/src/package.rs
+++ b/support/texlab/crates/hover/src/package.rs
@@ -2,8 +2,8 @@ use base_db::semantics::tex::LinkKind;
use crate::{Hover, HoverData, HoverParams};
-pub(super) fn find_hover<'db>(params: &HoverParams<'db>) -> Option<Hover<'db>> {
- let data = params.document.data.as_tex()?;
+pub(super) fn find_hover<'a>(params: &HoverParams<'a>) -> Option<Hover<'a>> {
+ let data = params.feature.document.data.as_tex()?;
data.semantics
.links
.iter()
diff --git a/support/texlab/crates/hover/src/string_ref.rs b/support/texlab/crates/hover/src/string_ref.rs
index 7ea84113e0..6726041af2 100644
--- a/support/texlab/crates/hover/src/string_ref.rs
+++ b/support/texlab/crates/hover/src/string_ref.rs
@@ -4,8 +4,8 @@ use syntax::bibtex::{self, HasName, HasValue};
use crate::{Hover, HoverData, HoverParams};
-pub(super) fn find_hover<'db>(params: &HoverParams<'db>) -> Option<Hover<'db>> {
- let data = params.document.data.as_bib()?;
+pub(super) fn find_hover<'a>(params: &HoverParams<'a>) -> Option<Hover<'a>> {
+ let data = params.feature.document.data.as_bib()?;
let root = bibtex::Root::cast(data.root_node())?;
let name = root
.syntax()
diff --git a/support/texlab/crates/hover/src/tests.rs b/support/texlab/crates/hover/src/tests.rs
index 0db913d0b5..bbe33fa2db 100644
--- a/support/texlab/crates/hover/src/tests.rs
+++ b/support/texlab/crates/hover/src/tests.rs
@@ -4,12 +4,9 @@ use crate::HoverParams;
fn check(input: &str, expect: Expect) {
let fixture = test_utils::fixture::Fixture::parse(input);
- let workspace = &fixture.workspace;
- let document = workspace.lookup(&fixture.documents[0].uri).unwrap();
- let offset = fixture.documents[0].cursor.unwrap();
- let params = HoverParams::new(workspace, document, offset);
-
- let data = crate::find(&params).map(|hover| {
+ let (feature, offset) = fixture.make_params().unwrap();
+ let params = HoverParams { feature, offset };
+ let data = crate::find(params).map(|hover| {
assert_eq!(fixture.documents[0].ranges[0], hover.range);
hover.data
});