-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide completion for argument symbols
- Loading branch information
Showing
4 changed files
with
85 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use crate::completion::factory; | ||
use crate::completion::latex::combinators::LatexCombinators; | ||
use crate::data::symbols::DATABASE; | ||
use crate::feature::FeatureRequest; | ||
use lsp_types::{CompletionItem, CompletionParams}; | ||
|
||
pub struct LatexArgumentSymbolCompletionProvider; | ||
|
||
impl LatexArgumentSymbolCompletionProvider { | ||
pub async fn execute(request: &FeatureRequest<CompletionParams>) -> Vec<CompletionItem> { | ||
let mut items = Vec::new(); | ||
for group in &DATABASE.arguments { | ||
let command = format!("\\{}", group.command); | ||
let command_names = &[command.as_ref()]; | ||
items.append(&mut await!(LatexCombinators::argument( | ||
&request, | ||
command_names, | ||
group.index, | ||
async move |_| { | ||
let mut items = Vec::new(); | ||
for symbol in &group.arguments { | ||
items.push(factory::create_argument_symbol( | ||
&symbol.argument, | ||
&symbol.image, | ||
)); | ||
} | ||
items | ||
} | ||
))); | ||
} | ||
items | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::completion::latex::data::types::LatexComponentDatabase; | ||
use crate::feature::FeatureSpec; | ||
use crate::test_feature; | ||
use lsp_types::Position; | ||
|
||
#[test] | ||
fn test_inside_mathbb() { | ||
let items = test_feature!( | ||
LatexArgumentSymbolCompletionProvider, | ||
FeatureSpec { | ||
files: vec![FeatureSpec::file("foo.tex", "\\mathbb{}")], | ||
main_file: "foo.tex", | ||
position: Position::new(0, 8), | ||
new_name: "", | ||
component_database: LatexComponentDatabase::default(), | ||
} | ||
); | ||
assert_eq!(true, items.len() > 0); | ||
} | ||
|
||
#[test] | ||
fn test_outside_mathbb() { | ||
let items = test_feature!( | ||
LatexArgumentSymbolCompletionProvider, | ||
FeatureSpec { | ||
files: vec![FeatureSpec::file("foo.tex", "\\mathbb{}")], | ||
main_file: "foo.tex", | ||
position: Position::new(0, 9), | ||
new_name: "", | ||
component_database: LatexComponentDatabase::default(), | ||
} | ||
); | ||
assert_eq!(true, items.len() == 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod argument_symbol; | ||
pub mod begin_command; | ||
pub mod citation; | ||
pub mod color; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters