summaryrefslogtreecommitdiff
path: root/support/texlab/tests/integration/lsp/text_document/document_link.rs
blob: 1a773fd47802a71d1327f5c01b0403f22a57bfdd (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use anyhow::Result;
use assert_unordered::assert_eq_unordered;
use lsp_types::{
    request::DocumentLinkRequest, ClientCapabilities, DocumentLink, DocumentLinkParams,
    TextDocumentIdentifier,
};

use crate::lsp::{client::Client, fixture};

fn check(fixture: &str) -> Result<()> {
    let mut client = Client::spawn()?;
    client.initialize(ClientCapabilities::default(), None)?;

    let fixture = fixture::parse(fixture);
    for file in fixture.files {
        client.open(file.name, file.lang, file.text)?;
    }

    let mut expected_links = Vec::new();
    for ranges in fixture.ranges.values() {
        expected_links.push(DocumentLink {
            range: ranges[&1].range,
            target: Some(client.uri(ranges[&2].name)?),
            tooltip: None,
            data: None,
        });
    }

    let actual_links = client
        .request::<DocumentLinkRequest>(DocumentLinkParams {
            text_document: TextDocumentIdentifier::new(client.uri(fixture.cursor.unwrap().name)?),
            work_done_progress_params: Default::default(),
            partial_result_params: Default::default(),
        })?
        .unwrap_or_default();

    client.shutdown()?;

    assert_eq_unordered!(actual_links, expected_links);
    Ok(())
}

#[test]
fn document_include() -> Result<()> {
    check(
        r#"
%TEX foo.tex
%SRC \input{bar.tex}
%1.1        ^^^^^^^
%CUR ^

%TEX bar.tex
%SRC 
%1.2 
"#,
    )
}

#[test]
fn document_import() -> Result<()> {
    check(
        r#"
%TEX foo.tex
%SRC \import{bar/}{baz}
%1.1               ^^^
%CUR ^

%TEX bar/baz.tex
%SRC 
%1.2 
"#,
    )
}