summaryrefslogtreecommitdiff
path: root/support/texlab/src/link
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2021-05-23 03:00:39 +0000
committerNorbert Preining <norbert@preining.info>2021-05-23 03:00:39 +0000
commitf1261b349e875b842745b63258c3e338cb1fe3bf (patch)
treeb5d402b3e80818cde2c079a42249f3dcb9732247 /support/texlab/src/link
parent58aa1ac09b1d9e4769d0a0661cf12e2b2db41b14 (diff)
CTAN sync 202105230300
Diffstat (limited to 'support/texlab/src/link')
-rw-r--r--support/texlab/src/link/latex_import.rs99
-rw-r--r--support/texlab/src/link/latex_include.rs101
-rw-r--r--support/texlab/src/link/mod.rs40
3 files changed, 0 insertions, 240 deletions
diff --git a/support/texlab/src/link/latex_import.rs b/support/texlab/src/link/latex_import.rs
deleted file mode 100644
index 494a72b481..0000000000
--- a/support/texlab/src/link/latex_import.rs
+++ /dev/null
@@ -1,99 +0,0 @@
-use crate::{
- feature::{FeatureProvider, FeatureRequest},
- protocol::{DocumentLink, DocumentLinkParams},
- syntax::{latex, SyntaxNode},
- workspace::DocumentContent,
-};
-use async_trait::async_trait;
-
-#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
-pub struct LatexImportLinkProvider;
-
-#[async_trait]
-impl FeatureProvider for LatexImportLinkProvider {
- type Params = DocumentLinkParams;
- type Output = Vec<DocumentLink>;
-
- async fn execute<'a>(&'a self, req: &'a FeatureRequest<Self::Params>) -> Self::Output {
- if let DocumentContent::Latex(table) = &req.current().content {
- table
- .imports
- .iter()
- .flat_map(|import| Self::resolve(req, table, import))
- .collect()
- } else {
- Vec::new()
- }
- }
-}
-
-impl LatexImportLinkProvider {
- fn resolve(
- req: &FeatureRequest<DocumentLinkParams>,
- table: &latex::SymbolTable,
- import: &latex::Import,
- ) -> Vec<DocumentLink> {
- let mut links = Vec::new();
- let file = import.file(&table);
- for target in &import.targets {
- if let Some(link) = req.snapshot().find(target).map(|doc| DocumentLink {
- range: file.range(),
- target: doc.uri.clone().into(),
- tooltip: None,
- }) {
- links.push(link);
- break;
- }
- }
- links
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use crate::{
- feature::FeatureTester,
- protocol::{Range, RangeExt},
- };
-
- #[tokio::test]
- async fn empty_latex_document_command() {
- let actual_links = FeatureTester::new()
- .file("main.tex", "")
- .main("main.tex")
- .test_link(LatexImportLinkProvider)
- .await;
-
- assert!(actual_links.is_empty());
- }
-
- #[tokio::test]
- async fn empty_bibtex_document_command() {
- let actual_links = FeatureTester::new()
- .file("main.bib", "")
- .main("main.bib")
- .test_link(LatexImportLinkProvider)
- .await;
-
- assert!(actual_links.is_empty());
- }
-
- #[tokio::test]
- async fn has_links() {
- let actual_links = FeatureTester::new()
- .file("foo.tex", r#"\import{bar/}{baz}"#)
- .file("bar/baz.tex", r#""#)
- .main("foo.tex")
- .test_link(LatexImportLinkProvider)
- .await;
-
- let expected_links = vec![DocumentLink {
- range: Range::new_simple(0, 14, 0, 17),
- target: FeatureTester::uri("bar/baz.tex").into(),
- tooltip: None,
- }];
-
- assert_eq!(actual_links, expected_links);
- }
-}
diff --git a/support/texlab/src/link/latex_include.rs b/support/texlab/src/link/latex_include.rs
deleted file mode 100644
index 5f4f592f14..0000000000
--- a/support/texlab/src/link/latex_include.rs
+++ /dev/null
@@ -1,101 +0,0 @@
-use crate::{
- feature::{FeatureProvider, FeatureRequest},
- protocol::{DocumentLink, DocumentLinkParams},
- syntax::{latex, SyntaxNode},
- workspace::DocumentContent,
-};
-use async_trait::async_trait;
-
-#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
-pub struct LatexIncludeLinkProvider;
-
-#[async_trait]
-impl FeatureProvider for LatexIncludeLinkProvider {
- type Params = DocumentLinkParams;
- type Output = Vec<DocumentLink>;
-
- async fn execute<'a>(&'a self, req: &'a FeatureRequest<Self::Params>) -> Self::Output {
- if let DocumentContent::Latex(table) = &req.current().content {
- table
- .includes
- .iter()
- .flat_map(|include| Self::resolve(req, table, include))
- .collect()
- } else {
- Vec::new()
- }
- }
-}
-
-impl LatexIncludeLinkProvider {
- fn resolve(
- req: &FeatureRequest<DocumentLinkParams>,
- table: &latex::SymbolTable,
- include: &latex::Include,
- ) -> Vec<DocumentLink> {
- let mut links = Vec::new();
- let paths = include.paths(&table);
- for (i, targets) in include.all_targets.iter().enumerate() {
- for target in targets {
- if let Some(link) = req.snapshot().find(target).map(|doc| DocumentLink {
- range: paths[i].range(),
- target: doc.uri.clone().into(),
- tooltip: None,
- }) {
- links.push(link);
- break;
- }
- }
- }
- links
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use crate::{
- feature::FeatureTester,
- protocol::{Range, RangeExt},
- };
-
- #[tokio::test]
- async fn empty_latex_document_command() {
- let actual_links = FeatureTester::new()
- .file("main.tex", "")
- .main("main.tex")
- .test_link(LatexIncludeLinkProvider)
- .await;
-
- assert!(actual_links.is_empty());
- }
-
- #[tokio::test]
- async fn empty_bibtex_document_command() {
- let actual_links = FeatureTester::new()
- .file("main.bib", "")
- .main("main.bib")
- .test_link(LatexIncludeLinkProvider)
- .await;
-
- assert!(actual_links.is_empty());
- }
-
- #[tokio::test]
- async fn has_links() {
- let actual_links = FeatureTester::new()
- .file("foo.tex", r#"\input{bar.tex}"#)
- .file("bar.tex", r#""#)
- .main("foo.tex")
- .test_link(LatexIncludeLinkProvider)
- .await;
-
- let expected_links = vec![DocumentLink {
- range: Range::new_simple(0, 7, 0, 14),
- target: FeatureTester::uri("bar.tex").into(),
- tooltip: None,
- }];
-
- assert_eq!(actual_links, expected_links);
- }
-}
diff --git a/support/texlab/src/link/mod.rs b/support/texlab/src/link/mod.rs
deleted file mode 100644
index 934975f060..0000000000
--- a/support/texlab/src/link/mod.rs
+++ /dev/null
@@ -1,40 +0,0 @@
-mod latex_import;
-mod latex_include;
-
-use self::{latex_import::LatexImportLinkProvider, latex_include::LatexIncludeLinkProvider};
-use crate::{
- feature::{ConcatProvider, FeatureProvider, FeatureRequest},
- protocol::{DocumentLink, DocumentLinkParams},
-};
-use async_trait::async_trait;
-
-pub struct LinkProvider {
- provider: ConcatProvider<DocumentLinkParams, DocumentLink>,
-}
-
-impl LinkProvider {
- pub fn new() -> Self {
- Self {
- provider: ConcatProvider::new(vec![
- Box::new(LatexImportLinkProvider),
- Box::new(LatexIncludeLinkProvider),
- ]),
- }
- }
-}
-
-impl Default for LinkProvider {
- fn default() -> Self {
- Self::new()
- }
-}
-
-#[async_trait]
-impl FeatureProvider for LinkProvider {
- type Params = DocumentLinkParams;
- type Output = Vec<DocumentLink>;
-
- async fn execute<'a>(&'a self, req: &'a FeatureRequest<Self::Params>) -> Self::Output {
- self.provider.execute(req).await
- }
-}