mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-08-04 10:49:55 +00:00
Refactor symbol request tests
This commit is contained in:
parent
4cc0b20a56
commit
7fb38fa877
44 changed files with 1290 additions and 1678 deletions
14
Cargo.lock
generated
14
Cargo.lock
generated
|
@ -1488,9 +1488,12 @@ version = "0.0.0"
|
|||
dependencies = [
|
||||
"base-db",
|
||||
"distro",
|
||||
"insta",
|
||||
"itertools",
|
||||
"regex",
|
||||
"rowan",
|
||||
"syntax",
|
||||
"test-utils",
|
||||
"titlecase",
|
||||
"url",
|
||||
]
|
||||
|
@ -1538,6 +1541,17 @@ dependencies = [
|
|||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "test-utils"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"base-db",
|
||||
"distro",
|
||||
"rowan",
|
||||
"syntax",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "texlab"
|
||||
version = "5.5.0"
|
||||
|
|
|
@ -18,7 +18,7 @@ pub enum Owner {
|
|||
Server,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct Document {
|
||||
pub uri: Url,
|
||||
pub dir: Url,
|
||||
|
@ -100,6 +100,12 @@ impl Document {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Document {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_tuple("Document").field(&self.uri.as_str()).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::borrow::Borrow<Url> for Document {
|
||||
fn borrow(&self) -> &Url {
|
||||
&self.uri
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
pub mod auxiliary;
|
||||
pub mod tex;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
|
||||
#[derive(PartialEq, Eq, Clone, Hash)]
|
||||
pub struct Span {
|
||||
pub text: String,
|
||||
pub range: rowan::TextRange,
|
||||
}
|
||||
impl std::fmt::Debug for Span {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_tuple("Span")
|
||||
.field(&self.text)
|
||||
.field(&self.range)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&syntax::latex::Key> for Span {
|
||||
fn from(key: &syntax::latex::Key) -> Self {
|
||||
|
|
|
@ -6,14 +6,19 @@ authors.workspace = true
|
|||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
base-db = { path = "../base-db" }
|
||||
distro = { path = "../distro" }
|
||||
itertools = "0.10.5"
|
||||
rowan = "0.15.11"
|
||||
syntax = { path = "../syntax" }
|
||||
url = "2.3.1"
|
||||
titlecase = "2.2.1"
|
||||
url = "2.3.1"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
[dev-dependencies]
|
||||
insta = "1.29.0"
|
||||
regex = "1.7.3"
|
||||
test-utils = { path = "../test-utils" }
|
||||
|
|
|
@ -46,3 +46,6 @@ fn filter_symbols(container: &mut Vec<Symbol>, config: &SymbolConfig) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
source: crates/symbols/src/document/tests.rs
|
||||
expression: "document_symbols(&fixture.workspace, document)"
|
||||
---
|
||||
[
|
||||
Symbol {
|
||||
name: "Enumerate",
|
||||
kind: Enumeration,
|
||||
label: None,
|
||||
full_range: 98..159,
|
||||
selection_range: 98..159,
|
||||
children: [
|
||||
Symbol {
|
||||
name: "Item",
|
||||
kind: EnumerationItem,
|
||||
label: None,
|
||||
full_range: 120..129,
|
||||
selection_range: 120..129,
|
||||
children: [],
|
||||
},
|
||||
Symbol {
|
||||
name: "Item",
|
||||
kind: EnumerationItem,
|
||||
label: None,
|
||||
full_range: 134..143,
|
||||
selection_range: 134..143,
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
|
@ -0,0 +1,62 @@
|
|||
---
|
||||
source: crates/symbols/src/document/tests.rs
|
||||
expression: "document_symbols(&fixture.workspace, document)"
|
||||
---
|
||||
[
|
||||
Symbol {
|
||||
name: "Enumerate",
|
||||
kind: Enumeration,
|
||||
label: None,
|
||||
full_range: 43..184,
|
||||
selection_range: 43..184,
|
||||
children: [
|
||||
Symbol {
|
||||
name: "1",
|
||||
kind: EnumerationItem,
|
||||
label: Some(
|
||||
Span(
|
||||
"it:foo",
|
||||
70..84,
|
||||
),
|
||||
),
|
||||
full_range: 65..88,
|
||||
selection_range: 70..84,
|
||||
children: [],
|
||||
},
|
||||
Symbol {
|
||||
name: "Item",
|
||||
kind: EnumerationItem,
|
||||
label: Some(
|
||||
Span(
|
||||
"it:bar",
|
||||
98..112,
|
||||
),
|
||||
),
|
||||
full_range: 93..116,
|
||||
selection_range: 98..112,
|
||||
children: [],
|
||||
},
|
||||
Symbol {
|
||||
name: "Baz",
|
||||
kind: EnumerationItem,
|
||||
label: None,
|
||||
full_range: 121..135,
|
||||
selection_range: 121..135,
|
||||
children: [],
|
||||
},
|
||||
Symbol {
|
||||
name: "2",
|
||||
kind: EnumerationItem,
|
||||
label: Some(
|
||||
Span(
|
||||
"it:qux",
|
||||
150..164,
|
||||
),
|
||||
),
|
||||
full_range: 140..168,
|
||||
selection_range: 150..164,
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
source: crates/symbols/src/document/tests.rs
|
||||
expression: "document_symbols(&fixture.workspace, document)"
|
||||
---
|
||||
[
|
||||
Symbol {
|
||||
name: "Equation (1)",
|
||||
kind: Equation,
|
||||
label: Some(
|
||||
Span(
|
||||
"eq:foo",
|
||||
59..73,
|
||||
),
|
||||
),
|
||||
full_range: 43..96,
|
||||
selection_range: 59..73,
|
||||
children: [],
|
||||
},
|
||||
Symbol {
|
||||
name: "Equation",
|
||||
kind: Equation,
|
||||
label: Some(
|
||||
Span(
|
||||
"eq:bar",
|
||||
114..128,
|
||||
),
|
||||
),
|
||||
full_range: 98..151,
|
||||
selection_range: 114..128,
|
||||
children: [],
|
||||
},
|
||||
Symbol {
|
||||
name: "Equation",
|
||||
kind: Equation,
|
||||
label: None,
|
||||
full_range: 153..192,
|
||||
selection_range: 153..192,
|
||||
children: [],
|
||||
},
|
||||
]
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
source: crates/symbols/src/document/tests.rs
|
||||
expression: "document_symbols(&fixture.workspace, document)"
|
||||
---
|
||||
[
|
||||
Symbol {
|
||||
name: "Figure 1: Foo",
|
||||
kind: Figure,
|
||||
label: Some(
|
||||
Span(
|
||||
"fig:foo",
|
||||
83..98,
|
||||
),
|
||||
),
|
||||
full_range: 43..111,
|
||||
selection_range: 83..98,
|
||||
children: [],
|
||||
},
|
||||
Symbol {
|
||||
name: "Figure: Bar",
|
||||
kind: Figure,
|
||||
label: Some(
|
||||
Span(
|
||||
"fig:bar",
|
||||
153..168,
|
||||
),
|
||||
),
|
||||
full_range: 113..181,
|
||||
selection_range: 153..168,
|
||||
children: [],
|
||||
},
|
||||
Symbol {
|
||||
name: "Figure: Baz",
|
||||
kind: Figure,
|
||||
label: None,
|
||||
full_range: 183..236,
|
||||
selection_range: 183..236,
|
||||
children: [],
|
||||
},
|
||||
]
|
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
source: crates/symbols/src/document/tests.rs
|
||||
expression: "document_symbols(&fixture.workspace, document)"
|
||||
---
|
||||
[
|
||||
Symbol {
|
||||
name: "Equation",
|
||||
kind: Equation,
|
||||
label: Some(
|
||||
Span(
|
||||
"eq:foo",
|
||||
59..73,
|
||||
),
|
||||
),
|
||||
full_range: 43..96,
|
||||
selection_range: 59..73,
|
||||
children: [],
|
||||
},
|
||||
]
|
|
@ -0,0 +1,41 @@
|
|||
---
|
||||
source: crates/symbols/src/document/tests.rs
|
||||
expression: "document_symbols(&fixture.workspace, document)"
|
||||
---
|
||||
[
|
||||
Symbol {
|
||||
name: "Foo",
|
||||
kind: Section,
|
||||
label: None,
|
||||
full_range: 43..56,
|
||||
selection_range: 43..56,
|
||||
children: [],
|
||||
},
|
||||
Symbol {
|
||||
name: "2 Bar",
|
||||
kind: Section,
|
||||
label: Some(
|
||||
Span(
|
||||
"sec:bar",
|
||||
71..86,
|
||||
),
|
||||
),
|
||||
full_range: 58..119,
|
||||
selection_range: 71..86,
|
||||
children: [
|
||||
Symbol {
|
||||
name: "Baz",
|
||||
kind: Section,
|
||||
label: Some(
|
||||
Span(
|
||||
"sec:baz",
|
||||
104..119,
|
||||
),
|
||||
),
|
||||
full_range: 88..119,
|
||||
selection_range: 104..119,
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
|
@ -0,0 +1,53 @@
|
|||
---
|
||||
source: crates/symbols/src/document/tests.rs
|
||||
expression: "document_symbols(&fixture.workspace, document)"
|
||||
---
|
||||
[
|
||||
Symbol {
|
||||
name: "Lemma 1 (Foo)",
|
||||
kind: Theorem,
|
||||
label: Some(
|
||||
Span(
|
||||
"thm:foo",
|
||||
107..122,
|
||||
),
|
||||
),
|
||||
full_range: 89..142,
|
||||
selection_range: 107..122,
|
||||
children: [],
|
||||
},
|
||||
Symbol {
|
||||
name: "Lemma 2",
|
||||
kind: Theorem,
|
||||
label: Some(
|
||||
Span(
|
||||
"thm:bar",
|
||||
157..172,
|
||||
),
|
||||
),
|
||||
full_range: 144..192,
|
||||
selection_range: 157..172,
|
||||
children: [],
|
||||
},
|
||||
Symbol {
|
||||
name: "Lemma",
|
||||
kind: Theorem,
|
||||
label: Some(
|
||||
Span(
|
||||
"thm:baz",
|
||||
207..222,
|
||||
),
|
||||
),
|
||||
full_range: 194..242,
|
||||
selection_range: 207..222,
|
||||
children: [],
|
||||
},
|
||||
Symbol {
|
||||
name: "Lemma (Qux)",
|
||||
kind: Theorem,
|
||||
label: None,
|
||||
full_range: 244..282,
|
||||
selection_range: 244..282,
|
||||
children: [],
|
||||
},
|
||||
]
|
250
crates/symbols/src/document/tests.rs
Normal file
250
crates/symbols/src/document/tests.rs
Normal file
|
@ -0,0 +1,250 @@
|
|||
use base_db::{Config, SymbolConfig};
|
||||
use insta::assert_debug_snapshot;
|
||||
use regex::Regex;
|
||||
use test_utils::fixture::Fixture;
|
||||
|
||||
use crate::document_symbols;
|
||||
|
||||
#[test]
|
||||
fn test_enumerate() {
|
||||
let fixture = Fixture::parse(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{enumerate}
|
||||
\item\label{it:foo} Foo
|
||||
\item\label{it:bar} Bar
|
||||
\item[Baz] Baz
|
||||
\item[Qux]\label{it:qux} Qux
|
||||
\end{enumerate}
|
||||
|
||||
\end{document}
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\newlabel{it:foo}{{1}{1}}
|
||||
\newlabel{it:qux}{{2}{1}}"#,
|
||||
);
|
||||
|
||||
let document = fixture.workspace.lookup(&fixture.documents[0].uri).unwrap();
|
||||
assert_debug_snapshot!(document_symbols(&fixture.workspace, document));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_equation() {
|
||||
let fixture = Fixture::parse(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{equation}\label{eq:foo}
|
||||
Foo
|
||||
\end{equation}
|
||||
|
||||
\begin{equation}\label{eq:bar}
|
||||
Bar
|
||||
\end{equation}
|
||||
|
||||
\begin{equation}
|
||||
Baz
|
||||
\end{equation}
|
||||
|
||||
\end{document}
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\newlabel{eq:foo}{{1}{1}}"#,
|
||||
);
|
||||
|
||||
let document = fixture.workspace.lookup(&fixture.documents[0].uri).unwrap();
|
||||
assert_debug_snapshot!(document_symbols(&fixture.workspace, document));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_float() {
|
||||
let fixture = Fixture::parse(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{figure}
|
||||
Foo
|
||||
\caption{Foo}\label{fig:foo}
|
||||
\end{figure}
|
||||
|
||||
\begin{figure}
|
||||
Bar
|
||||
\caption{Bar}\label{fig:bar}
|
||||
\end{figure}
|
||||
|
||||
\begin{figure}
|
||||
Baz
|
||||
\caption{Baz}
|
||||
\end{figure}
|
||||
|
||||
\begin{figure}
|
||||
Qux
|
||||
\end{figure}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces Foo}}{1}\protected@file@percent }
|
||||
\newlabel{fig:foo}{{1}{1}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {2}{\ignorespaces Bar}}{1}\protected@file@percent }
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {3}{\ignorespaces Baz}}{1}\protected@file@percent }"#,
|
||||
);
|
||||
|
||||
let document = fixture.workspace.lookup(&fixture.documents[0].uri).unwrap();
|
||||
assert_debug_snapshot!(document_symbols(&fixture.workspace, document));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_section() {
|
||||
let fixture = Fixture::parse(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\section{Foo}
|
||||
|
||||
\section{Bar}\label{sec:bar}
|
||||
|
||||
\subsection{Baz}\label{sec:baz}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {1}Foo}{1}\protected@file@percent }
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {2}Bar}{1}\protected@file@percent }
|
||||
\newlabel{sec:bar}{{2}{1}}"#,
|
||||
);
|
||||
|
||||
let document = fixture.workspace.lookup(&fixture.documents[0].uri).unwrap();
|
||||
assert_debug_snapshot!(document_symbols(&fixture.workspace, document));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_theorem() {
|
||||
let fixture = Fixture::parse(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
\usepackage{amsthm}
|
||||
\newtheorem{lemma}{Lemma}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{lemma}[Foo]\label{thm:foo}
|
||||
Foo
|
||||
\end{lemma}
|
||||
|
||||
\begin{lemma}\label{thm:bar}
|
||||
Bar
|
||||
\end{lemma}
|
||||
|
||||
\begin{lemma}\label{thm:baz}
|
||||
Baz
|
||||
\end{lemma}
|
||||
|
||||
\begin{lemma}[Qux]
|
||||
Qux
|
||||
\end{lemma}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\newlabel{thm:foo}{{1}{1}}
|
||||
\newlabel{thm:bar}{{2}{1}}"#,
|
||||
);
|
||||
|
||||
let document = fixture.workspace.lookup(&fixture.documents[0].uri).unwrap();
|
||||
assert_debug_snapshot!(document_symbols(&fixture.workspace, document));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_allowed_patterns() {
|
||||
let mut fixture = Fixture::parse(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{equation}\label{eq:foo}
|
||||
Foo
|
||||
\end{equation}
|
||||
|
||||
\begin{enumerate}
|
||||
\item Foo
|
||||
\item Bar
|
||||
\end{enumerate}
|
||||
|
||||
\end{document}"#,
|
||||
);
|
||||
|
||||
fixture.workspace.set_config(Config {
|
||||
symbols: SymbolConfig {
|
||||
allowed_patterns: vec![
|
||||
Regex::new("Item").unwrap(),
|
||||
Regex::new("Enumerate").unwrap(),
|
||||
],
|
||||
ignored_patterns: Vec::new(),
|
||||
},
|
||||
..Config::default()
|
||||
});
|
||||
|
||||
let document = fixture.workspace.lookup(&fixture.documents[0].uri).unwrap();
|
||||
assert_debug_snapshot!(document_symbols(&fixture.workspace, document));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ignored_patterns() {
|
||||
let mut fixture = Fixture::parse(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{equation}\label{eq:foo}
|
||||
Foo
|
||||
\end{equation}
|
||||
|
||||
\begin{enumerate}
|
||||
\item Foo
|
||||
\item Bar
|
||||
\end{enumerate}
|
||||
|
||||
\end{document}"#,
|
||||
);
|
||||
|
||||
fixture.workspace.set_config(Config {
|
||||
symbols: SymbolConfig {
|
||||
ignored_patterns: vec![
|
||||
Regex::new("Item").unwrap(),
|
||||
Regex::new("Enumerate").unwrap(),
|
||||
],
|
||||
allowed_patterns: Vec::new(),
|
||||
},
|
||||
..Config::default()
|
||||
});
|
||||
|
||||
let document = fixture.workspace.lookup(&fixture.documents[0].uri).unwrap();
|
||||
assert_debug_snapshot!(document_symbols(&fixture.workspace, document));
|
||||
}
|
|
@ -24,9 +24,9 @@ pub fn workspace_symbols<'a>(workspace: &'a Workspace, query: &str) -> Vec<Symbo
|
|||
.filter(|symbol| symbol.kind != SymbolKind::Field)
|
||||
{
|
||||
let keywords = symbol.keywords();
|
||||
|
||||
if itertools::iproduct!(keywords.iter(), query.iter())
|
||||
.any(|(keyword, query)| keyword.eq_ignore_ascii_case(query))
|
||||
if query.is_empty()
|
||||
|| itertools::iproduct!(keywords.iter(), query.iter())
|
||||
.any(|(keyword, query)| keyword.eq_ignore_ascii_case(query))
|
||||
{
|
||||
results.push(SymbolLocation { document, symbol });
|
||||
}
|
||||
|
@ -42,3 +42,6 @@ pub fn workspace_symbols<'a>(workspace: &'a Workspace, query: &str) -> Vec<Symbo
|
|||
|
||||
results
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
source: crates/symbols/src/workspace/tests.rs
|
||||
expression: "workspace_symbols(&fixture.workspace, \"bibtex\")"
|
||||
---
|
||||
[
|
||||
SymbolLocation {
|
||||
document: Document(
|
||||
"file:///texlab/main.bib",
|
||||
),
|
||||
symbol: Symbol {
|
||||
name: "foo",
|
||||
kind: Entry(
|
||||
Article,
|
||||
),
|
||||
label: None,
|
||||
full_range: 0..14,
|
||||
selection_range: 9..12,
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
SymbolLocation {
|
||||
document: Document(
|
||||
"file:///texlab/main.bib",
|
||||
),
|
||||
symbol: Symbol {
|
||||
name: "bar",
|
||||
kind: Entry(
|
||||
String,
|
||||
),
|
||||
label: None,
|
||||
full_range: 16..36,
|
||||
selection_range: 24..27,
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
]
|
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
source: crates/symbols/src/workspace/tests.rs
|
||||
expression: "workspace_symbols(&fixture.workspace, \"figure\")"
|
||||
---
|
||||
[
|
||||
SymbolLocation {
|
||||
document: Document(
|
||||
"file:///texlab/main.tex",
|
||||
),
|
||||
symbol: Symbol {
|
||||
name: "Figure 1: Bar",
|
||||
kind: Figure,
|
||||
label: Some(
|
||||
Span(
|
||||
"fig:bar",
|
||||
265..280,
|
||||
),
|
||||
),
|
||||
full_range: 220..293,
|
||||
selection_range: 265..280,
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
]
|
|
@ -0,0 +1,60 @@
|
|||
---
|
||||
source: crates/symbols/src/workspace/tests.rs
|
||||
expression: "workspace_symbols(&fixture.workspace, \"item\")"
|
||||
---
|
||||
[
|
||||
SymbolLocation {
|
||||
document: Document(
|
||||
"file:///texlab/main.tex",
|
||||
),
|
||||
symbol: Symbol {
|
||||
name: "1",
|
||||
kind: EnumerationItem,
|
||||
label: Some(
|
||||
Span(
|
||||
"itm:foo",
|
||||
352..367,
|
||||
),
|
||||
),
|
||||
full_range: 347..371,
|
||||
selection_range: 352..367,
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
SymbolLocation {
|
||||
document: Document(
|
||||
"file:///texlab/main.tex",
|
||||
),
|
||||
symbol: Symbol {
|
||||
name: "2",
|
||||
kind: EnumerationItem,
|
||||
label: Some(
|
||||
Span(
|
||||
"itm:bar",
|
||||
381..396,
|
||||
),
|
||||
),
|
||||
full_range: 376..400,
|
||||
selection_range: 381..396,
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
SymbolLocation {
|
||||
document: Document(
|
||||
"file:///texlab/main.tex",
|
||||
),
|
||||
symbol: Symbol {
|
||||
name: "3",
|
||||
kind: EnumerationItem,
|
||||
label: Some(
|
||||
Span(
|
||||
"itm:baz",
|
||||
410..425,
|
||||
),
|
||||
),
|
||||
full_range: 405..429,
|
||||
selection_range: 410..425,
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
]
|
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
source: crates/symbols/src/workspace/tests.rs
|
||||
expression: "workspace_symbols(&fixture.workspace, \"math\")"
|
||||
---
|
||||
[
|
||||
SymbolLocation {
|
||||
document: Document(
|
||||
"file:///texlab/main.tex",
|
||||
),
|
||||
symbol: Symbol {
|
||||
name: "Equation (1)",
|
||||
kind: Equation,
|
||||
label: Some(
|
||||
Span(
|
||||
"eq:foo",
|
||||
151..165,
|
||||
),
|
||||
),
|
||||
full_range: 135..188,
|
||||
selection_range: 151..165,
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
SymbolLocation {
|
||||
document: Document(
|
||||
"file:///texlab/main.tex",
|
||||
),
|
||||
symbol: Symbol {
|
||||
name: "Lemma 1 (Qux)",
|
||||
kind: Theorem,
|
||||
label: Some(
|
||||
Span(
|
||||
"thm:qux",
|
||||
522..537,
|
||||
),
|
||||
),
|
||||
full_range: 504..557,
|
||||
selection_range: 522..537,
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
]
|
|
@ -0,0 +1,78 @@
|
|||
---
|
||||
source: crates/symbols/src/workspace/tests.rs
|
||||
expression: "workspace_symbols(&fixture.workspace, \"section\")"
|
||||
---
|
||||
[
|
||||
SymbolLocation {
|
||||
document: Document(
|
||||
"file:///texlab/main.tex",
|
||||
),
|
||||
symbol: Symbol {
|
||||
name: "1 Foo",
|
||||
kind: Section,
|
||||
label: Some(
|
||||
Span(
|
||||
"sec:foo",
|
||||
118..133,
|
||||
),
|
||||
),
|
||||
full_range: 105..188,
|
||||
selection_range: 118..133,
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
SymbolLocation {
|
||||
document: Document(
|
||||
"file:///texlab/main.tex",
|
||||
),
|
||||
symbol: Symbol {
|
||||
name: "2 Bar",
|
||||
kind: Section,
|
||||
label: Some(
|
||||
Span(
|
||||
"sec:bar",
|
||||
203..218,
|
||||
),
|
||||
),
|
||||
full_range: 190..293,
|
||||
selection_range: 203..218,
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
SymbolLocation {
|
||||
document: Document(
|
||||
"file:///texlab/main.tex",
|
||||
),
|
||||
symbol: Symbol {
|
||||
name: "3 Baz",
|
||||
kind: Section,
|
||||
label: Some(
|
||||
Span(
|
||||
"sec:baz",
|
||||
308..323,
|
||||
),
|
||||
),
|
||||
full_range: 295..445,
|
||||
selection_range: 308..323,
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
SymbolLocation {
|
||||
document: Document(
|
||||
"file:///texlab/main.tex",
|
||||
),
|
||||
symbol: Symbol {
|
||||
name: "4 Qux",
|
||||
kind: Section,
|
||||
label: Some(
|
||||
Span(
|
||||
"sec:qux",
|
||||
460..475,
|
||||
),
|
||||
),
|
||||
full_range: 447..557,
|
||||
selection_range: 460..475,
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
]
|
99
crates/symbols/src/workspace/tests.rs
Normal file
99
crates/symbols/src/workspace/tests.rs
Normal file
|
@ -0,0 +1,99 @@
|
|||
use insta::assert_debug_snapshot;
|
||||
use test_utils::fixture::Fixture;
|
||||
|
||||
use crate::workspace_symbols;
|
||||
|
||||
static FIXTURE: &str = r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
\usepackage{caption}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amsthm}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\section{Foo}\label{sec:foo}
|
||||
|
||||
\begin{equation}\label{eq:foo}
|
||||
Foo
|
||||
\end{equation}
|
||||
|
||||
\section{Bar}\label{sec:bar}
|
||||
|
||||
\begin{figure}
|
||||
Bar
|
||||
\caption{Bar}
|
||||
\label{fig:bar}
|
||||
\end{figure}
|
||||
|
||||
\section{Baz}\label{sec:baz}
|
||||
|
||||
\begin{enumerate}
|
||||
\item\label{itm:foo} Foo
|
||||
\item\label{itm:bar} Bar
|
||||
\item\label{itm:baz} Baz
|
||||
\end{enumerate}
|
||||
|
||||
\section{Qux}\label{sec:qux}
|
||||
|
||||
\newtheorem{lemma}{Lemma}
|
||||
|
||||
\begin{lemma}[Qux]\label{thm:qux}
|
||||
Qux
|
||||
\end{lemma}
|
||||
|
||||
\end{document}
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces Bar\relax }}{1}\protected@file@percent }
|
||||
\providecommand*\caption@xref[2]{\@setref\relax\@undefined{#1}}
|
||||
\newlabel{fig:bar}{{1}{1}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {1}Foo}{1}\protected@file@percent }
|
||||
\newlabel{sec:foo}{{1}{1}}
|
||||
\newlabel{eq:foo}{{1}{1}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {2}Bar}{1}\protected@file@percent }
|
||||
\newlabel{sec:bar}{{2}{1}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {3}Baz}{1}\protected@file@percent }
|
||||
\newlabel{sec:baz}{{3}{1}}
|
||||
\newlabel{itm:foo}{{1}{1}}
|
||||
\newlabel{itm:bar}{{2}{1}}
|
||||
\newlabel{itm:baz}{{3}{1}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {4}Qux}{1}\protected@file@percent }
|
||||
\newlabel{sec:qux}{{4}{1}}
|
||||
\newlabel{thm:qux}{{1}{1}}
|
||||
|
||||
%! main.bib
|
||||
@article{foo,}
|
||||
|
||||
@string{bar = "bar"}"#;
|
||||
|
||||
#[test]
|
||||
fn filter_type_section() {
|
||||
let fixture = Fixture::parse(FIXTURE);
|
||||
assert_debug_snapshot!(workspace_symbols(&fixture.workspace, "section"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_type_figure() {
|
||||
let fixture = Fixture::parse(FIXTURE);
|
||||
assert_debug_snapshot!(workspace_symbols(&fixture.workspace, "figure"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_type_item() {
|
||||
let fixture = Fixture::parse(FIXTURE);
|
||||
assert_debug_snapshot!(workspace_symbols(&fixture.workspace, "item"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_type_math() {
|
||||
let fixture = Fixture::parse(FIXTURE);
|
||||
assert_debug_snapshot!(workspace_symbols(&fixture.workspace, "math"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_bibtex() {
|
||||
let fixture = Fixture::parse(FIXTURE);
|
||||
assert_debug_snapshot!(workspace_symbols(&fixture.workspace, "bibtex"));
|
||||
}
|
17
crates/test-utils/Cargo.toml
Normal file
17
crates/test-utils/Cargo.toml
Normal file
|
@ -0,0 +1,17 @@
|
|||
[package]
|
||||
name = "test-utils"
|
||||
version = "0.0.0"
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
base-db = { path = "../base-db" }
|
||||
distro = { path = "../distro" }
|
||||
rowan = "0.15.11"
|
||||
syntax = { path = "../syntax" }
|
||||
url = "2.3.1"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
105
crates/test-utils/src/fixture.rs
Normal file
105
crates/test-utils/src/fixture.rs
Normal file
|
@ -0,0 +1,105 @@
|
|||
use base_db::{Owner, Workspace};
|
||||
use rowan::{TextRange, TextSize};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Fixture {
|
||||
pub workspace: Workspace,
|
||||
pub documents: Vec<DocumentSpec>,
|
||||
}
|
||||
|
||||
impl Fixture {
|
||||
pub fn parse(input: &str) -> Fixture {
|
||||
let mut documents = Vec::new();
|
||||
|
||||
let mut start = 0;
|
||||
for end in input
|
||||
.match_indices("%!")
|
||||
.skip(1)
|
||||
.map(|(i, _)| i)
|
||||
.chain(std::iter::once(input.len()))
|
||||
{
|
||||
documents.push(DocumentSpec::parse(&input[start..end]));
|
||||
start = end;
|
||||
}
|
||||
|
||||
let mut workspace = Workspace::default();
|
||||
for document in &documents {
|
||||
let language = document
|
||||
.uri
|
||||
.to_file_path()
|
||||
.ok()
|
||||
.and_then(|path| distro::Language::from_path(&path))
|
||||
.unwrap_or(distro::Language::Tex);
|
||||
|
||||
workspace.open(
|
||||
document.uri.clone(),
|
||||
document.text.clone(),
|
||||
language,
|
||||
Owner::Client,
|
||||
TextSize::from(0),
|
||||
);
|
||||
}
|
||||
|
||||
Self {
|
||||
workspace,
|
||||
documents,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DocumentSpec {
|
||||
pub uri: Url,
|
||||
pub text: String,
|
||||
pub cursor: Option<TextSize>,
|
||||
pub ranges: Vec<TextRange>,
|
||||
}
|
||||
|
||||
impl DocumentSpec {
|
||||
pub fn parse(input: &str) -> Self {
|
||||
let (uri_str, input) = input
|
||||
.trim()
|
||||
.strip_prefix("%! ")
|
||||
.map(|input| input.split_once('\n').unwrap_or((input, "")))
|
||||
.unwrap();
|
||||
|
||||
let uri = Url::parse(&format!("file:///texlab/{uri_str}")).unwrap();
|
||||
|
||||
let mut ranges = Vec::new();
|
||||
let mut cursor = None;
|
||||
|
||||
let mut text = String::new();
|
||||
for line in input.lines().map(|line| line.trim_end()) {
|
||||
if line.chars().all(|c| matches!(c, ' ' | '^' | '|' | '!')) && !line.is_empty() {
|
||||
cursor = cursor.or_else(|| {
|
||||
let offset = line.find('|')?;
|
||||
Some(TextSize::from((text.len() + offset) as u32))
|
||||
});
|
||||
|
||||
if let Some(start) = line.find('!') {
|
||||
let position = TextSize::from((text.len() + start) as u32);
|
||||
ranges.push(TextRange::new(position, position));
|
||||
}
|
||||
|
||||
if let Some(start) = line.find('^') {
|
||||
let end = line.rfind('^').unwrap() + 1;
|
||||
ranges.push(TextRange::new(
|
||||
TextSize::from((text.len() + start) as u32),
|
||||
TextSize::from((text.len() + end) as u32),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
text.push_str(line);
|
||||
text.push('\n');
|
||||
}
|
||||
}
|
||||
|
||||
Self {
|
||||
uri,
|
||||
text,
|
||||
cursor,
|
||||
ranges,
|
||||
}
|
||||
}
|
||||
}
|
1
crates/test-utils/src/lib.rs
Normal file
1
crates/test-utils/src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod fixture;
|
|
@ -26,14 +26,16 @@ impl Fixture {
|
|||
let mut documents = Vec::new();
|
||||
|
||||
let mut start = 0;
|
||||
for end in input
|
||||
.match_indices("%!")
|
||||
.skip(1)
|
||||
.map(|(i, _)| i)
|
||||
.chain(std::iter::once(input.len()))
|
||||
{
|
||||
documents.push(Document::parse(&input[start..end]));
|
||||
start = end;
|
||||
if !input.is_empty() {
|
||||
for end in input
|
||||
.match_indices("%!")
|
||||
.skip(1)
|
||||
.map(|(i, _)| i)
|
||||
.chain(std::iter::once(input.len()))
|
||||
{
|
||||
documents.push(Document::parse(&input[start..end]));
|
||||
start = end;
|
||||
}
|
||||
}
|
||||
|
||||
Self { documents }
|
||||
|
|
|
@ -1,441 +1,45 @@
|
|||
use insta::assert_json_snapshot;
|
||||
use lsp_types::{
|
||||
notification::DidChangeConfiguration, request::DocumentSymbolRequest,
|
||||
DidChangeConfigurationParams, DocumentSymbolParams, DocumentSymbolResponse,
|
||||
};
|
||||
use insta::assert_debug_snapshot;
|
||||
use lsp_types::{notification::DidOpenTextDocument, request::DocumentSymbolRequest, *};
|
||||
|
||||
use crate::fixture::TestBed;
|
||||
|
||||
fn find_symbols(
|
||||
fixture: &str,
|
||||
capabilities: serde_json::Value,
|
||||
settings: serde_json::Value,
|
||||
) -> DocumentSymbolResponse {
|
||||
let test_bed = TestBed::new(fixture).unwrap();
|
||||
|
||||
#[test]
|
||||
fn test_smoke() {
|
||||
let test_bed = TestBed::new("").unwrap();
|
||||
test_bed
|
||||
.initialize(serde_json::from_value(capabilities).unwrap())
|
||||
.initialize(ClientCapabilities {
|
||||
text_document: Some(TextDocumentClientCapabilities {
|
||||
document_symbol: Some(DocumentSymbolClientCapabilities {
|
||||
hierarchical_document_symbol_support: Some(true),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let uri = Url::parse("file:///texlab/main.tex").unwrap();
|
||||
test_bed
|
||||
.client()
|
||||
.send_notification::<DidChangeConfiguration>(DidChangeConfigurationParams { settings })
|
||||
.send_notification::<DidOpenTextDocument>(DidOpenTextDocumentParams {
|
||||
text_document: TextDocumentItem::new(
|
||||
uri.clone(),
|
||||
"latex".into(),
|
||||
0,
|
||||
r#"\section{Foo} \subsection{Bar} \section{Baz}"#.into(),
|
||||
),
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let text_document = test_bed.cursor().unwrap().text_document;
|
||||
|
||||
let mut response = test_bed
|
||||
let Some(DocumentSymbolResponse::Nested(symbols)) = test_bed
|
||||
.client()
|
||||
.send_request::<DocumentSymbolRequest>(DocumentSymbolParams {
|
||||
text_document,
|
||||
work_done_progress_params: Default::default(),
|
||||
text_document: TextDocumentIdentifier { uri },
|
||||
partial_result_params: Default::default(),
|
||||
work_done_progress_params: Default::default(),
|
||||
})
|
||||
.unwrap()
|
||||
.unwrap_or_else(|| DocumentSymbolResponse::Flat(vec![]));
|
||||
.unwrap() else { unreachable!() };
|
||||
|
||||
if let DocumentSymbolResponse::Flat(symbols) = &mut response {
|
||||
for symbol in symbols {
|
||||
symbol.location.uri = test_bed.redact(&symbol.location.uri);
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enumerate_nested() {
|
||||
assert_json_snapshot!(find_symbols(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{enumerate}
|
||||
\item\label{it:foo} Foo
|
||||
\item\label{it:bar} Bar
|
||||
\item[Baz] Baz
|
||||
\item[Qux]\label{it:qux} Qux
|
||||
\end{enumerate}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\newlabel{it:foo}{{1}{1}}
|
||||
\newlabel{it:qux}{{2}{1}}"#,
|
||||
serde_json::json!({
|
||||
"textDocument": {
|
||||
"documentSymbol": {
|
||||
"hierarchicalDocumentSymbolSupport": true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
serde_json::Value::Null,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enumerate_flat() {
|
||||
assert_json_snapshot!(find_symbols(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{enumerate}
|
||||
\item\label{it:foo} Foo
|
||||
\item\label{it:bar} Bar
|
||||
\item[Baz] Baz
|
||||
\item[Qux]\label{it:qux} Qux
|
||||
\end{enumerate}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\newlabel{it:foo}{{1}{1}}
|
||||
\newlabel{it:qux}{{2}{1}}"#,
|
||||
serde_json::json!({}),
|
||||
serde_json::Value::Null,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn equation_nested() {
|
||||
assert_json_snapshot!(find_symbols(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{equation}\label{eq:foo}
|
||||
Foo
|
||||
\end{equation}
|
||||
|
||||
\begin{equation}\label{eq:bar}
|
||||
Bar
|
||||
\end{equation}
|
||||
|
||||
\begin{equation}
|
||||
Baz
|
||||
\end{equation}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\newlabel{eq:foo}{{1}{1}}"#,
|
||||
serde_json::json!({
|
||||
"textDocument": {
|
||||
"documentSymbol": {
|
||||
"hierarchicalDocumentSymbolSupport": true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
serde_json::Value::Null,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn equation_flat() {
|
||||
assert_json_snapshot!(find_symbols(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{equation}\label{eq:foo}
|
||||
Foo
|
||||
\end{equation}
|
||||
|
||||
\begin{equation}\label{eq:bar}
|
||||
Bar
|
||||
\end{equation}
|
||||
|
||||
\begin{equation}
|
||||
Baz
|
||||
\end{equation}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\newlabel{eq:foo}{{1}{1}}"#,
|
||||
serde_json::json!({}),
|
||||
serde_json::Value::Null,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_nested() {
|
||||
assert_json_snapshot!(find_symbols(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{figure}
|
||||
Foo
|
||||
\caption{Foo}\label{fig:foo}
|
||||
\end{figure}
|
||||
|
||||
\begin{figure}
|
||||
Bar
|
||||
\caption{Bar}\label{fig:bar}
|
||||
\end{figure}
|
||||
|
||||
\begin{figure}
|
||||
Baz
|
||||
\caption{Baz}
|
||||
\end{figure}
|
||||
|
||||
\begin{figure}
|
||||
Qux
|
||||
\end{figure}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces Foo}}{1}\protected@file@percent }
|
||||
\newlabel{fig:foo}{{1}{1}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {2}{\ignorespaces Bar}}{1}\protected@file@percent }
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {3}{\ignorespaces Baz}}{1}\protected@file@percent }"#,
|
||||
serde_json::json!({
|
||||
"textDocument": {
|
||||
"documentSymbol": {
|
||||
"hierarchicalDocumentSymbolSupport": true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
serde_json::Value::Null,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_flat() {
|
||||
assert_json_snapshot!(find_symbols(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{figure}
|
||||
Foo
|
||||
\caption{Foo}\label{fig:foo}
|
||||
\end{figure}
|
||||
|
||||
\begin{figure}
|
||||
Bar
|
||||
\caption{Bar}\label{fig:bar}
|
||||
\end{figure}
|
||||
|
||||
\begin{figure}
|
||||
Baz
|
||||
\caption{Baz}
|
||||
\end{figure}
|
||||
|
||||
\begin{figure}
|
||||
Qux
|
||||
\end{figure}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces Foo}}{1}\protected@file@percent }
|
||||
\newlabel{fig:foo}{{1}{1}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {2}{\ignorespaces Bar}}{1}\protected@file@percent }
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {3}{\ignorespaces Baz}}{1}\protected@file@percent }"#,
|
||||
serde_json::json!({}),
|
||||
serde_json::Value::Null,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn section_nested() {
|
||||
assert_json_snapshot!(find_symbols(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\section{Foo}
|
||||
|
||||
\section{Bar}\label{sec:bar}
|
||||
|
||||
\subsection{Baz}\label{sec:baz}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {1}Foo}{1}\protected@file@percent }
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {2}Bar}{1}\protected@file@percent }
|
||||
\newlabel{sec:bar}{{2}{1}}"#,
|
||||
serde_json::json!({
|
||||
"textDocument": {
|
||||
"documentSymbol": {
|
||||
"hierarchicalDocumentSymbolSupport": true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
serde_json::Value::Null,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn section_flat() {
|
||||
assert_json_snapshot!(find_symbols(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\section{Foo}
|
||||
|
||||
\section{Bar}\label{sec:bar}
|
||||
|
||||
\subsection{Baz}\label{sec:baz}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {1}Foo}{1}\protected@file@percent }
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {2}Bar}{1}\protected@file@percent }
|
||||
\newlabel{sec:bar}{{2}{1}}"#,
|
||||
serde_json::json!({}),
|
||||
serde_json::Value::Null,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn theorem_nested() {
|
||||
assert_json_snapshot!(find_symbols(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
\usepackage{amsthm}
|
||||
\newtheorem{lemma}{Lemma}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{lemma}[Foo]\label{thm:foo}
|
||||
Foo
|
||||
\end{lemma}
|
||||
|
||||
\begin{lemma}\label{thm:bar}
|
||||
Bar
|
||||
\end{lemma}
|
||||
|
||||
\begin{lemma}\label{thm:baz}
|
||||
Baz
|
||||
\end{lemma}
|
||||
|
||||
\begin{lemma}[Qux]
|
||||
Qux
|
||||
\end{lemma}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\newlabel{thm:foo}{{1}{1}}
|
||||
\newlabel{thm:bar}{{2}{1}}"#,
|
||||
serde_json::json!({
|
||||
"textDocument": {
|
||||
"documentSymbol": {
|
||||
"hierarchicalDocumentSymbolSupport": true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
serde_json::Value::Null,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn theorem_flat() {
|
||||
assert_json_snapshot!(find_symbols(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
\usepackage{amsthm}
|
||||
\newtheorem{lemma}{Lemma}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{lemma}[Foo]\label{thm:foo}
|
||||
Foo
|
||||
\end{lemma}
|
||||
|
||||
\begin{lemma}\label{thm:bar}
|
||||
Bar
|
||||
\end{lemma}
|
||||
|
||||
\begin{lemma}\label{thm:baz}
|
||||
Baz
|
||||
\end{lemma}
|
||||
|
||||
\begin{lemma}[Qux]
|
||||
Qux
|
||||
\end{lemma}
|
||||
|
||||
\end{document}
|
||||
|
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\newlabel{thm:foo}{{1}{1}}
|
||||
\newlabel{thm:bar}{{2}{1}}"#,
|
||||
serde_json::json!({}),
|
||||
serde_json::Value::Null,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignored_patterns() {
|
||||
assert_json_snapshot!(find_symbols(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{equation}\label{eq:foo}
|
||||
Foo
|
||||
\end{equation}
|
||||
|
||||
\begin{enumerate}
|
||||
\item Foo
|
||||
\item Bar
|
||||
\end{enumerate}
|
||||
|
||||
\end{document}
|
||||
|"#,
|
||||
serde_json::json!({}),
|
||||
serde_json::json!({
|
||||
"symbols": {
|
||||
"ignoredPatterns": ["Item", "Enumerate"]
|
||||
}
|
||||
}),
|
||||
));
|
||||
assert_debug_snapshot!(symbols);
|
||||
}
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/text_document/document_symbol.rs
|
||||
expression: "find_symbols(r#\"\n%! main.tex\n\\documentclass{article}\n\n\\begin{document}\n\n\\begin{enumerate}\n \\item\\label{it:foo} Foo\n \\item\\label{it:bar} Bar\n \\item[Baz] Baz\n \\item[Qux]\\label{it:qux} Qux\n\\end{enumerate}\n\n\\end{document}\n|\n\n%! main.aux\n\\relax\n\\newlabel{it:foo}{{1}{1}}\n\\newlabel{it:qux}{{2}{1}}\"#,\n serde_json::json!({}), serde_json::Value::Null)"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Enumerate",
|
||||
"kind": 10,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"character": 15
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "1",
|
||||
"kind": 22,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 5,
|
||||
"character": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"character": 27
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Item",
|
||||
"kind": 22,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"character": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"character": 27
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Baz",
|
||||
"kind": 22,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"character": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"character": 18
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "2",
|
||||
"kind": 22,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"character": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"character": 32
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,140 +0,0 @@
|
|||
---
|
||||
source: tests/lsp/text_document/document_symbol.rs
|
||||
expression: "find_symbols(r#\"\n%! main.tex\n\\documentclass{article}\n\n\\begin{document}\n\n\\begin{enumerate}\n \\item\\label{it:foo} Foo\n \\item\\label{it:bar} Bar\n \\item[Baz] Baz\n \\item[Qux]\\label{it:qux} Qux\n\\end{enumerate}\n\n\\end{document}\n|\n\n%! main.aux\n\\relax\n\\newlabel{it:foo}{{1}{1}}\n\\newlabel{it:qux}{{2}{1}}\"#,\n serde_json::json!({\n \"textDocument\" :\n {\n \"documentSymbol\" :\n { \"hierarchicalDocumentSymbolSupport\" : true, },\n },\n }), serde_json::Value::Null)"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Enumerate",
|
||||
"kind": 10,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"character": 15
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"character": 15
|
||||
}
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"name": "1",
|
||||
"detail": "it:foo",
|
||||
"kind": 22,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 5,
|
||||
"character": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"character": 27
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 5,
|
||||
"character": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"character": 23
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "Item",
|
||||
"detail": "it:bar",
|
||||
"kind": 22,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"character": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"character": 27
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"character": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"character": 23
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "Baz",
|
||||
"kind": 22,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"character": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"character": 18
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"character": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"character": 18
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "2",
|
||||
"detail": "it:qux",
|
||||
"kind": 22,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"character": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"character": 32
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"character": 14
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"character": 28
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1,60 +0,0 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/text_document/document_symbol.rs
|
||||
expression: "find_symbols(r#\"\n%! main.tex\n\\documentclass{article}\n\n\\begin{document}\n\n\\begin{equation}\\label{eq:foo}\n Foo\n\\end{equation}\n\n\\begin{equation}\\label{eq:bar}\n Bar\n\\end{equation}\n\n\\begin{equation}\n Baz\n\\end{equation}\n\n\\end{document}\n|\n\n%! main.aux\n\\relax\n\\newlabel{eq:foo}{{1}{1}}\"#,\n serde_json::json!({}), serde_json::Value::Null)"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Equation (1)",
|
||||
"kind": 14,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"character": 14
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Equation",
|
||||
"kind": 14,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 10,
|
||||
"character": 14
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Equation",
|
||||
"kind": 14,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 12,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 14,
|
||||
"character": 14
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,86 +0,0 @@
|
|||
---
|
||||
source: tests/lsp/text_document/document_symbol.rs
|
||||
expression: "find_symbols(r#\"\n%! main.tex\n\\documentclass{article}\n\n\\begin{document}\n\n\\begin{equation}\\label{eq:foo}\n Foo\n\\end{equation}\n\n\\begin{equation}\\label{eq:bar}\n Bar\n\\end{equation}\n\n\\begin{equation}\n Baz\n\\end{equation}\n\n\\end{document}\n|\n\n%! main.aux\n\\relax\n\\newlabel{eq:foo}{{1}{1}}\"#,\n serde_json::json!({\n \"textDocument\" :\n {\n \"documentSymbol\" :\n { \"hierarchicalDocumentSymbolSupport\" : true, },\n },\n }), serde_json::Value::Null)"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Equation (1)",
|
||||
"detail": "eq:foo",
|
||||
"kind": 14,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"character": 14
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"character": 30
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "Equation",
|
||||
"detail": "eq:bar",
|
||||
"kind": 14,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 10,
|
||||
"character": 14
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"character": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"character": 30
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "Equation",
|
||||
"kind": 14,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 12,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 14,
|
||||
"character": 14
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 12,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 14,
|
||||
"character": 14
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
}
|
||||
]
|
|
@ -1,60 +0,0 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/text_document/document_symbol.rs
|
||||
expression: "find_symbols(r#\"\n%! main.tex\n\\documentclass{article}\n\n\\begin{document}\n\n\\begin{figure}\n Foo\n \\caption{Foo}\\label{fig:foo}\n\\end{figure}\n\n\\begin{figure}\n Bar\n \\caption{Bar}\\label{fig:bar}\n\\end{figure}\n\n\\begin{figure}\n Baz\n \\caption{Baz}\n\\end{figure}\n\n\\begin{figure}\n Qux\n\\end{figure}\n\n\\end{document}\n|\n\n%! main.aux\n\\relax\n\\@writefile{lof}{\\contentsline {figure}{\\numberline {1}{\\ignorespaces Foo}}{1}\\protected@file@percent }\n\\newlabel{fig:foo}{{1}{1}}\n\\@writefile{lof}{\\contentsline {figure}{\\numberline {2}{\\ignorespaces Bar}}{1}\\protected@file@percent }\n\\@writefile{lof}{\\contentsline {figure}{\\numberline {3}{\\ignorespaces Baz}}{1}\\protected@file@percent }\"#,\n serde_json::json!({}), serde_json::Value::Null)"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Figure 1: Foo",
|
||||
"kind": 6,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"character": 12
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Figure: Bar",
|
||||
"kind": 6,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 9,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 12,
|
||||
"character": 12
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Figure: Baz",
|
||||
"kind": 6,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 14,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 17,
|
||||
"character": 12
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,86 +0,0 @@
|
|||
---
|
||||
source: tests/lsp/text_document/document_symbol.rs
|
||||
expression: "find_symbols(r#\"\n%! main.tex\n\\documentclass{article}\n\n\\begin{document}\n\n\\begin{figure}\n Foo\n \\caption{Foo}\\label{fig:foo}\n\\end{figure}\n\n\\begin{figure}\n Bar\n \\caption{Bar}\\label{fig:bar}\n\\end{figure}\n\n\\begin{figure}\n Baz\n \\caption{Baz}\n\\end{figure}\n\n\\begin{figure}\n Qux\n\\end{figure}\n\n\\end{document}\n|\n\n%! main.aux\n\\relax\n\\@writefile{lof}{\\contentsline {figure}{\\numberline {1}{\\ignorespaces Foo}}{1}\\protected@file@percent }\n\\newlabel{fig:foo}{{1}{1}}\n\\@writefile{lof}{\\contentsline {figure}{\\numberline {2}{\\ignorespaces Bar}}{1}\\protected@file@percent }\n\\@writefile{lof}{\\contentsline {figure}{\\numberline {3}{\\ignorespaces Baz}}{1}\\protected@file@percent }\"#,\n serde_json::json!({\n \"textDocument\" :\n {\n \"documentSymbol\" :\n { \"hierarchicalDocumentSymbolSupport\" : true, },\n },\n }), serde_json::Value::Null)"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Figure 1: Foo",
|
||||
"detail": "fig:foo",
|
||||
"kind": 6,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"character": 12
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"character": 17
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"character": 32
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "Figure: Bar",
|
||||
"detail": "fig:bar",
|
||||
"kind": 6,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 9,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 12,
|
||||
"character": 12
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 11,
|
||||
"character": 17
|
||||
},
|
||||
"end": {
|
||||
"line": 11,
|
||||
"character": 32
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "Figure: Baz",
|
||||
"kind": 6,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 14,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 17,
|
||||
"character": 12
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 14,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 17,
|
||||
"character": 12
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
}
|
||||
]
|
|
@ -1,24 +0,0 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/text_document/document_symbol.rs
|
||||
expression: "find_symbols(r#\"\n%! main.tex\n\\documentclass{article}\n\n\\begin{document}\n\n\\begin{equation}\\label{eq:foo}\n Foo\n\\end{equation}\n \n\\begin{enumerate}\n \\item Foo\n \\item Bar\n\\end{enumerate}\n\n\\end{document}\n|\"#,\n serde_json::json!({}),\n serde_json::json!({\n \"symbols\" : { \"ignoredPatterns\" : [\"Item\", \"Enumerate\"] }\n }))"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Equation",
|
||||
"kind": 14,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"character": 14
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,60 +0,0 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/text_document/document_symbol.rs
|
||||
expression: "find_symbols(r#\"\n%! main.tex\n\\documentclass{article}\n\n\\begin{document}\n\n\\section{Foo}\n\n\\section{Bar}\\label{sec:bar}\n\n\\subsection{Baz}\\label{sec:baz}\n\n\\end{document}\n|\n\n%! main.aux\n\\relax\n\\@writefile{toc}{\\contentsline {section}{\\numberline {1}Foo}{1}\\protected@file@percent }\n\\@writefile{toc}{\\contentsline {section}{\\numberline {2}Bar}{1}\\protected@file@percent }\n\\newlabel{sec:bar}{{2}{1}}\"#,\n serde_json::json!({}), serde_json::Value::Null)"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Foo",
|
||||
"kind": 2,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"character": 13
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "2 Bar",
|
||||
"kind": 2,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"character": 31
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Baz",
|
||||
"kind": 2,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"character": 31
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,87 +0,0 @@
|
|||
---
|
||||
source: tests/lsp/text_document/document_symbol.rs
|
||||
expression: "find_symbols(r#\"\n%! main.tex\n\\documentclass{article}\n\n\\begin{document}\n\n\\section{Foo}\n\n\\section{Bar}\\label{sec:bar}\n\n\\subsection{Baz}\\label{sec:baz}\n\n\\end{document}\n|\n\n%! main.aux\n\\relax\n\\@writefile{toc}{\\contentsline {section}{\\numberline {1}Foo}{1}\\protected@file@percent }\n\\@writefile{toc}{\\contentsline {section}{\\numberline {2}Bar}{1}\\protected@file@percent }\n\\newlabel{sec:bar}{{2}{1}}\"#,\n serde_json::json!({\n \"textDocument\" :\n {\n \"documentSymbol\" :\n { \"hierarchicalDocumentSymbolSupport\" : true, },\n },\n }), serde_json::Value::Null)"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Foo",
|
||||
"kind": 2,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"character": 13
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 4,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"character": 13
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "2 Bar",
|
||||
"detail": "sec:bar",
|
||||
"kind": 2,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"character": 31
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"character": 13
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"character": 28
|
||||
}
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"name": "Baz",
|
||||
"detail": "sec:baz",
|
||||
"kind": 2,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"character": 31
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 8,
|
||||
"character": 16
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"character": 31
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -0,0 +1,103 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/text_document/document_symbol.rs
|
||||
expression: symbols
|
||||
---
|
||||
[
|
||||
DocumentSymbol {
|
||||
name: "Foo",
|
||||
detail: None,
|
||||
kind: Module,
|
||||
tags: None,
|
||||
deprecated: Some(
|
||||
false,
|
||||
),
|
||||
range: Range {
|
||||
start: Position {
|
||||
line: 0,
|
||||
character: 0,
|
||||
},
|
||||
end: Position {
|
||||
line: 0,
|
||||
character: 30,
|
||||
},
|
||||
},
|
||||
selection_range: Range {
|
||||
start: Position {
|
||||
line: 0,
|
||||
character: 0,
|
||||
},
|
||||
end: Position {
|
||||
line: 0,
|
||||
character: 30,
|
||||
},
|
||||
},
|
||||
children: Some(
|
||||
[
|
||||
DocumentSymbol {
|
||||
name: "Bar",
|
||||
detail: None,
|
||||
kind: Module,
|
||||
tags: None,
|
||||
deprecated: Some(
|
||||
false,
|
||||
),
|
||||
range: Range {
|
||||
start: Position {
|
||||
line: 0,
|
||||
character: 14,
|
||||
},
|
||||
end: Position {
|
||||
line: 0,
|
||||
character: 30,
|
||||
},
|
||||
},
|
||||
selection_range: Range {
|
||||
start: Position {
|
||||
line: 0,
|
||||
character: 14,
|
||||
},
|
||||
end: Position {
|
||||
line: 0,
|
||||
character: 30,
|
||||
},
|
||||
},
|
||||
children: Some(
|
||||
[],
|
||||
),
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
DocumentSymbol {
|
||||
name: "Baz",
|
||||
detail: None,
|
||||
kind: Module,
|
||||
tags: None,
|
||||
deprecated: Some(
|
||||
false,
|
||||
),
|
||||
range: Range {
|
||||
start: Position {
|
||||
line: 0,
|
||||
character: 31,
|
||||
},
|
||||
end: Position {
|
||||
line: 0,
|
||||
character: 44,
|
||||
},
|
||||
},
|
||||
selection_range: Range {
|
||||
start: Position {
|
||||
line: 0,
|
||||
character: 31,
|
||||
},
|
||||
end: Position {
|
||||
line: 0,
|
||||
character: 44,
|
||||
},
|
||||
},
|
||||
children: Some(
|
||||
[],
|
||||
),
|
||||
},
|
||||
]
|
|
@ -1,78 +0,0 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/text_document/document_symbol.rs
|
||||
expression: "find_symbols(r#\"\n%! main.tex\n\\documentclass{article}\n\\usepackage{amsthm}\n\\newtheorem{lemma}{Lemma}\n\n\\begin{document}\n\n\\begin{lemma}[Foo]\\label{thm:foo}\n Foo\n\\end{lemma}\n\n\\begin{lemma}\\label{thm:bar}\n Bar\n\\end{lemma}\n\n\\begin{lemma}\\label{thm:baz}\n Baz\n\\end{lemma}\n\n\\begin{lemma}[Qux]\n Qux\n\\end{lemma}\n\n\\end{document}\n|\n\n%! main.aux\n\\relax\n\\newlabel{thm:foo}{{1}{1}}\n\\newlabel{thm:bar}{{2}{1}}\"#,\n serde_json::json!({}), serde_json::Value::Null)"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Lemma 1 (Foo)",
|
||||
"kind": 13,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"character": 11
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Lemma 2",
|
||||
"kind": 13,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 10,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 12,
|
||||
"character": 11
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Lemma",
|
||||
"kind": 13,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 14,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 16,
|
||||
"character": 11
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Lemma (Qux)",
|
||||
"kind": 13,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 18,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 20,
|
||||
"character": 11
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,113 +0,0 @@
|
|||
---
|
||||
source: tests/lsp/text_document/document_symbol.rs
|
||||
expression: "find_symbols(r#\"\n%! main.tex\n\\documentclass{article}\n\\usepackage{amsthm}\n\\newtheorem{lemma}{Lemma}\n\n\\begin{document}\n\n\\begin{lemma}[Foo]\\label{thm:foo}\n Foo\n\\end{lemma}\n\n\\begin{lemma}\\label{thm:bar}\n Bar\n\\end{lemma}\n\n\\begin{lemma}\\label{thm:baz}\n Baz\n\\end{lemma}\n\n\\begin{lemma}[Qux]\n Qux\n\\end{lemma}\n\n\\end{document}\n|\n\n%! main.aux\n\\relax\n\\newlabel{thm:foo}{{1}{1}}\n\\newlabel{thm:bar}{{2}{1}}\"#,\n serde_json::json!({\n \"textDocument\" :\n {\n \"documentSymbol\" :\n { \"hierarchicalDocumentSymbolSupport\" : true, },\n },\n }), serde_json::Value::Null)"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Lemma 1 (Foo)",
|
||||
"detail": "thm:foo",
|
||||
"kind": 13,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"character": 11
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 6,
|
||||
"character": 18
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"character": 33
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "Lemma 2",
|
||||
"detail": "thm:bar",
|
||||
"kind": 13,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 10,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 12,
|
||||
"character": 11
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 10,
|
||||
"character": 13
|
||||
},
|
||||
"end": {
|
||||
"line": 10,
|
||||
"character": 28
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "Lemma",
|
||||
"detail": "thm:baz",
|
||||
"kind": 13,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 14,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 16,
|
||||
"character": 11
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 14,
|
||||
"character": 13
|
||||
},
|
||||
"end": {
|
||||
"line": 14,
|
||||
"character": 28
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "Lemma (Qux)",
|
||||
"kind": 13,
|
||||
"deprecated": false,
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 18,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 20,
|
||||
"character": 11
|
||||
}
|
||||
},
|
||||
"selectionRange": {
|
||||
"start": {
|
||||
"line": 18,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 20,
|
||||
"character": 11
|
||||
}
|
||||
},
|
||||
"children": []
|
||||
}
|
||||
]
|
|
@ -1,42 +0,0 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/workspace/symbol.rs
|
||||
expression: "find_symbols(FIXTURE, \"bibtex\")"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "foo",
|
||||
"kind": 24,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.bib",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 0,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 0,
|
||||
"character": 14
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "bar",
|
||||
"kind": 15,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.bib",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"character": 20
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,24 +0,0 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/workspace/symbol.rs
|
||||
expression: "find_symbols(FIXTURE, \"figure\")"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Figure 1: Bar",
|
||||
"kind": 6,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 15,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 19,
|
||||
"character": 12
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,60 +0,0 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/workspace/symbol.rs
|
||||
expression: "find_symbols(FIXTURE, \"item\")"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "1",
|
||||
"kind": 22,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 24,
|
||||
"character": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 24,
|
||||
"character": 28
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "2",
|
||||
"kind": 22,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 25,
|
||||
"character": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 25,
|
||||
"character": 28
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "3",
|
||||
"kind": 22,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 26,
|
||||
"character": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 26,
|
||||
"character": 28
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,42 +0,0 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/workspace/symbol.rs
|
||||
expression: "find_symbols(FIXTURE, \"math\")"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "Equation (1)",
|
||||
"kind": 14,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 9,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 11,
|
||||
"character": 14
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Lemma 1 (Qux)",
|
||||
"kind": 13,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 33,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 35,
|
||||
"character": 11
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
|
@ -1,78 +0,0 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/workspace/symbol.rs
|
||||
expression: "find_symbols(FIXTURE, \"section\")"
|
||||
---
|
||||
[
|
||||
{
|
||||
"name": "1 Foo",
|
||||
"kind": 2,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 7,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 11,
|
||||
"character": 14
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "2 Bar",
|
||||
"kind": 2,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 13,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 19,
|
||||
"character": 12
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "3 Baz",
|
||||
"kind": 2,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 21,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 27,
|
||||
"character": 15
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "4 Qux",
|
||||
"kind": 2,
|
||||
"deprecated": false,
|
||||
"location": {
|
||||
"uri": "redacted://main.tex",
|
||||
"range": {
|
||||
"start": {
|
||||
"line": 29,
|
||||
"character": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 35,
|
||||
"character": 11
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
|
@ -0,0 +1,78 @@
|
|||
---
|
||||
source: crates/texlab/tests/lsp/workspace/symbol.rs
|
||||
expression: symbols
|
||||
---
|
||||
[
|
||||
SymbolInformation {
|
||||
name: "Foo",
|
||||
kind: Module,
|
||||
tags: None,
|
||||
deprecated: Some(
|
||||
false,
|
||||
),
|
||||
location: Location {
|
||||
uri: Url {
|
||||
scheme: "redacted",
|
||||
cannot_be_a_base: false,
|
||||
username: "",
|
||||
password: None,
|
||||
host: Some(
|
||||
Domain(
|
||||
"main.tex",
|
||||
),
|
||||
),
|
||||
port: None,
|
||||
path: "",
|
||||
query: None,
|
||||
fragment: None,
|
||||
},
|
||||
range: Range {
|
||||
start: Position {
|
||||
line: 7,
|
||||
character: 0,
|
||||
},
|
||||
end: Position {
|
||||
line: 8,
|
||||
character: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
container_name: None,
|
||||
},
|
||||
SymbolInformation {
|
||||
name: "Bar",
|
||||
kind: Module,
|
||||
tags: None,
|
||||
deprecated: Some(
|
||||
false,
|
||||
),
|
||||
location: Location {
|
||||
uri: Url {
|
||||
scheme: "redacted",
|
||||
cannot_be_a_base: false,
|
||||
username: "",
|
||||
password: None,
|
||||
host: Some(
|
||||
Domain(
|
||||
"main.tex",
|
||||
),
|
||||
),
|
||||
port: None,
|
||||
path: "",
|
||||
query: None,
|
||||
fragment: None,
|
||||
},
|
||||
range: Range {
|
||||
start: Position {
|
||||
line: 10,
|
||||
character: 0,
|
||||
},
|
||||
end: Position {
|
||||
line: 11,
|
||||
character: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
container_name: None,
|
||||
},
|
||||
]
|
|
@ -1,38 +1,15 @@
|
|||
use insta::assert_json_snapshot;
|
||||
use insta::assert_debug_snapshot;
|
||||
use lsp_types::{
|
||||
request::WorkspaceSymbolRequest, ClientCapabilities, SymbolInformation, WorkspaceSymbolParams,
|
||||
request::WorkspaceSymbolRequest, ClientCapabilities, WorkspaceSymbolParams,
|
||||
WorkspaceSymbolResponse,
|
||||
};
|
||||
|
||||
use crate::fixture::TestBed;
|
||||
|
||||
fn find_symbols(fixture: &str, query: &str) -> Vec<SymbolInformation> {
|
||||
let test_bed = TestBed::new(fixture).unwrap();
|
||||
|
||||
test_bed.initialize(ClientCapabilities::default()).unwrap();
|
||||
|
||||
let mut symbols = match test_bed
|
||||
.client()
|
||||
.send_request::<WorkspaceSymbolRequest>(WorkspaceSymbolParams {
|
||||
query: query.to_string(),
|
||||
work_done_progress_params: Default::default(),
|
||||
partial_result_params: Default::default(),
|
||||
})
|
||||
.unwrap()
|
||||
{
|
||||
Some(WorkspaceSymbolResponse::Flat(symbols)) => symbols,
|
||||
Some(WorkspaceSymbolResponse::Nested(_)) => unreachable!(),
|
||||
None => Vec::new(),
|
||||
};
|
||||
|
||||
for symbol in &mut symbols {
|
||||
symbol.location.uri = test_bed.redact(&symbol.location.uri);
|
||||
}
|
||||
|
||||
symbols
|
||||
}
|
||||
|
||||
const FIXTURE: &str = r#"
|
||||
#[test]
|
||||
fn test_smoke() {
|
||||
let test_bed = TestBed::new(
|
||||
r#"
|
||||
%! main.tex
|
||||
\documentclass{article}
|
||||
\usepackage{caption}
|
||||
|
@ -42,83 +19,30 @@ const FIXTURE: &str = r#"
|
|||
\begin{document}
|
||||
|
||||
\section{Foo}\label{sec:foo}
|
||||
Foo
|
||||
|
||||
\begin{equation}\label{eq:foo}
|
||||
Foo
|
||||
\end{equation}
|
||||
|
||||
\section{Bar}\label{sec:bar}
|
||||
|
||||
\begin{figure}
|
||||
Bar
|
||||
\caption{Bar}
|
||||
\label{fig:bar}
|
||||
\end{figure}
|
||||
|
||||
\section{Baz}\label{sec:baz}
|
||||
|
||||
\begin{enumerate}
|
||||
\item\label{itm:foo} Foo
|
||||
\item\label{itm:bar} Bar
|
||||
\item\label{itm:baz} Baz
|
||||
\end{enumerate}
|
||||
|
||||
\section{Qux}\label{sec:qux}
|
||||
|
||||
\newtheorem{lemma}{Lemma}
|
||||
|
||||
\begin{lemma}[Qux]\label{thm:qux}
|
||||
Qux
|
||||
\end{lemma}
|
||||
\section{Bar}
|
||||
Bar
|
||||
|
||||
\end{document}
|
||||
|
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
%! main.aux
|
||||
\relax
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces Bar\relax }}{1}\protected@file@percent }
|
||||
\providecommand*\caption@xref[2]{\@setref\relax\@undefined{#1}}
|
||||
\newlabel{fig:bar}{{1}{1}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {1}Foo}{1}\protected@file@percent }
|
||||
\newlabel{sec:foo}{{1}{1}}
|
||||
\newlabel{eq:foo}{{1}{1}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {2}Bar}{1}\protected@file@percent }
|
||||
\newlabel{sec:bar}{{2}{1}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {3}Baz}{1}\protected@file@percent }
|
||||
\newlabel{sec:baz}{{3}{1}}
|
||||
\newlabel{itm:foo}{{1}{1}}
|
||||
\newlabel{itm:bar}{{2}{1}}
|
||||
\newlabel{itm:baz}{{3}{1}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {4}Qux}{1}\protected@file@percent }
|
||||
\newlabel{sec:qux}{{4}{1}}
|
||||
\newlabel{thm:qux}{{1}{1}}
|
||||
test_bed.initialize(ClientCapabilities::default()).unwrap();
|
||||
|
||||
%! main.bib
|
||||
@article{foo,}
|
||||
let Some(WorkspaceSymbolResponse::Flat(mut symbols)) = test_bed
|
||||
.client()
|
||||
.send_request::<WorkspaceSymbolRequest>(WorkspaceSymbolParams {
|
||||
query: String::new(),
|
||||
work_done_progress_params: Default::default(),
|
||||
partial_result_params: Default::default(),
|
||||
})
|
||||
.unwrap() else { unreachable!() };
|
||||
|
||||
@string{bar = "bar"}"#;
|
||||
for symbol in &mut symbols {
|
||||
symbol.location.uri = test_bed.redact(&symbol.location.uri);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_type_section() {
|
||||
assert_json_snapshot!(find_symbols(FIXTURE, "section"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_type_figure() {
|
||||
assert_json_snapshot!(find_symbols(FIXTURE, "figure"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_type_item() {
|
||||
assert_json_snapshot!(find_symbols(FIXTURE, "item"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_type_math() {
|
||||
assert_json_snapshot!(find_symbols(FIXTURE, "math"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_bibtex() {
|
||||
assert_json_snapshot!(find_symbols(FIXTURE, "bibtex"));
|
||||
assert_debug_snapshot!(symbols);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue