diff options
author | Norbert Preining <norbert@preining.info> | 2023-02-26 03:02:12 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2023-02-26 03:02:12 +0000 |
commit | e7ae872926eddb0de09ecfe1c578e0680033955a (patch) | |
tree | 01717465b5b26d3b2ccaea9889c720a840e0a16c /support/texlab/src/features | |
parent | 81a9d839224eef4c2bd9bf68410b4049c61cdb14 (diff) |
CTAN sync 202302260302
Diffstat (limited to 'support/texlab/src/features')
-rw-r--r-- | support/texlab/src/features/completion/builder.rs | 12 | ||||
-rw-r--r-- | support/texlab/src/features/completion/include.rs | 2 | ||||
-rw-r--r-- | support/texlab/src/features/folding.rs | 1 | ||||
-rw-r--r-- | support/texlab/src/features/forward_search.rs | 15 | ||||
-rw-r--r-- | support/texlab/src/features/symbol.rs | 7 | ||||
-rw-r--r-- | support/texlab/src/features/symbol/types.rs | 24 |
6 files changed, 45 insertions, 16 deletions
diff --git a/support/texlab/src/features/completion/builder.rs b/support/texlab/src/features/completion/builder.rs index f8ea4c5d15..686d39b62b 100644 --- a/support/texlab/src/features/completion/builder.rs +++ b/support/texlab/src/features/completion/builder.rs @@ -60,8 +60,7 @@ impl<'db> CompletionBuilder<'db> { .take_while(|word| word.text_range() != token.text_range()) .chain(std::iter::once(token.clone())) .filter(|word| word.text_range().start() < context.offset) - .join(" ") - .into(), + .join(" "), None => token.text().into(), } } @@ -180,14 +179,7 @@ impl<'db> CompletionBuilder<'db> { "{} {}", key, WHITESPACE_REGEX - .replace_all( - &code - .replace('{', " ") - .replace('}', " ") - .replace(',', " ") - .replace('=', " "), - " " - ) + .replace_all(&code.replace(['{', '}', ',', '='], " "), " ") .trim(), ); diff --git a/support/texlab/src/features/completion/include.rs b/support/texlab/src/features/completion/include.rs index bde7544570..5d7654a208 100644 --- a/support/texlab/src/features/completion/include.rs +++ b/support/texlab/src/features/completion/include.rs @@ -119,7 +119,7 @@ fn current_dir( path.push(graphics_path); } - path.push(&path_text); + path.push(path_text); if !path_text.ends_with('/') { path.pop(); } diff --git a/support/texlab/src/features/folding.rs b/support/texlab/src/features/folding.rs index 153b839f57..91c9571b61 100644 --- a/support/texlab/src/features/folding.rs +++ b/support/texlab/src/features/folding.rs @@ -57,6 +57,7 @@ fn create_range(range: Range) -> FoldingRange { start_character: Some(range.start.character), end_line: range.end.line, end_character: Some(range.end.character), + collapsed_text: None, kind: Some(FoldingRangeKind::Region), } } diff --git a/support/texlab/src/features/forward_search.rs b/support/texlab/src/features/forward_search.rs index 47be702659..8e5a2cc59c 100644 --- a/support/texlab/src/features/forward_search.rs +++ b/support/texlab/src/features/forward_search.rs @@ -15,6 +15,9 @@ pub enum Error { #[error("TeX document '{0}' not found")] TexNotFound(Url), + #[error("TeX document '{0}' is invalid")] + InvalidTexFile(Url), + #[error("PDF document '{0}' not found")] PdfNotFound(PathBuf), @@ -59,8 +62,16 @@ impl Command { .as_deref() .ok_or_else(|| Error::NoLocalFile(uri.clone()))?; - let pdf_name = format!("{}.pdf", parent.location(db).stem(db).unwrap()); - let pdf_path = output_dir.join(pdf_name); + let pdf_path = match parent.location(db).stem(db) { + Some(stem) => { + let pdf_name = format!("{}.pdf", stem); + output_dir.join(pdf_name) + } + None => { + return Err(Error::InvalidTexFile(uri.clone())); + } + }; + if !pdf_path.exists() { return Err(Error::PdfNotFound(pdf_path)); } diff --git a/support/texlab/src/features/symbol.rs b/support/texlab/src/features/symbol.rs index c16193efcb..58004b50ef 100644 --- a/support/texlab/src/features/symbol.rs +++ b/support/texlab/src/features/symbol.rs @@ -9,7 +9,7 @@ use lsp_types::{DocumentSymbolResponse, SymbolInformation, Url, WorkspaceSymbolP use crate::{db::Workspace, util::capabilities::ClientCapabilitiesExt, Db}; -use self::project_order::ProjectOrdering; +use self::{project_order::ProjectOrdering, types::InternalSymbol}; pub fn find_document_symbols(db: &dyn Db, uri: &Url) -> Option<DocumentSymbolResponse> { let workspace = Workspace::get(db); @@ -18,6 +18,11 @@ pub fn find_document_symbols(db: &dyn Db, uri: &Url) -> Option<DocumentSymbolRes let mut buf = Vec::new(); latex::find_symbols(db, document, &mut buf); bibtex::find_symbols(db, document, &mut buf); + + let options = &Workspace::get(db).options(db).symbols; + + InternalSymbol::filter(&mut buf, &options); + if workspace .client_capabilities(db) .has_hierarchical_document_symbol_support() diff --git a/support/texlab/src/features/symbol/types.rs b/support/texlab/src/features/symbol/types.rs index be0ffeceda..fb3bca217b 100644 --- a/support/texlab/src/features/symbol/types.rs +++ b/support/texlab/src/features/symbol/types.rs @@ -2,8 +2,8 @@ use lsp_types::{DocumentSymbol, Location, Range, SymbolInformation, SymbolKind, use crate::{ db::Word, - util::{lang_data::BibtexEntryTypeCategory, lsp_enums::Structure}, - Db, + util::{self, lang_data::BibtexEntryTypeCategory, lsp_enums::Structure}, + Db, SymbolOptions, }; #[derive(Debug, PartialEq, Eq, Clone, Copy)] @@ -80,6 +80,26 @@ impl InternalSymbol { buffer.push(self); } + pub fn filter(container: &mut Vec<InternalSymbol>, options: &SymbolOptions) { + let mut i = 0; + while i < container.len() { + let symbol = &mut container[i]; + + if util::regex_filter::filter( + &symbol.name, + &options.allowed_patterns, + &options.ignored_patterns, + ) { + Self::filter(&mut symbol.children, options); + i += 1; + } else { + drop(symbol); + let mut symbol = container.remove(i); + container.append(&mut symbol.children); + } + } + } + pub fn into_document_symbol(self, db: &dyn Db) -> DocumentSymbol { let children = self .children |