diff options
author | Norbert Preining <norbert@preining.info> | 2023-12-04 03:01:04 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2023-12-04 03:01:04 +0000 |
commit | db0fe20663f1bcb3fcf87c3fb05a727420edd203 (patch) | |
tree | e5abdee7535ece54123168f0fa9a21fa0a627464 /support/texlab/crates/diagnostics | |
parent | de2c50ca7889fda13da11c1ccf6bdbd199ba8c2b (diff) |
CTAN sync 202312040301
Diffstat (limited to 'support/texlab/crates/diagnostics')
-rw-r--r-- | support/texlab/crates/diagnostics/Cargo.toml | 7 | ||||
-rw-r--r-- | support/texlab/crates/diagnostics/src/build_log.rs | 22 | ||||
-rw-r--r-- | support/texlab/crates/diagnostics/src/citations.rs | 3 | ||||
-rw-r--r-- | support/texlab/crates/diagnostics/src/tests.rs | 4 |
4 files changed, 19 insertions, 17 deletions
diff --git a/support/texlab/crates/diagnostics/Cargo.toml b/support/texlab/crates/diagnostics/Cargo.toml index 3f87c8c879..490bee32f3 100644 --- a/support/texlab/crates/diagnostics/Cargo.toml +++ b/support/texlab/crates/diagnostics/Cargo.toml @@ -8,11 +8,12 @@ rust-version.workspace = true [dependencies] base-db = { path = "../base-db" } -itertools = "0.11.0" -rowan = "0.15.11" +itertools = "0.12.0" +line-index = { path = "../line-index" } +rowan = "0.15.13" rustc-hash = "1.1.0" syntax = { path = "../syntax" } -url = "=2.3.1" +url = "2.5.0" [dev-dependencies] test-utils = { path = "../test-utils" } diff --git a/support/texlab/crates/diagnostics/src/build_log.rs b/support/texlab/crates/diagnostics/src/build_log.rs index 525bd982ff..4c53a35ff8 100644 --- a/support/texlab/crates/diagnostics/src/build_log.rs +++ b/support/texlab/crates/diagnostics/src/build_log.rs @@ -1,6 +1,7 @@ use std::borrow::Cow; use base_db::{Document, Workspace}; +use line_index::LineCol; use rowan::{TextLen, TextRange, TextSize}; use rustc_hash::FxHashMap; use syntax::BuildError; @@ -43,15 +44,15 @@ impl DiagnosticSource for BuildErrors { let Ok(full_path_uri) = Url::from_file_path(&full_path) else { continue; }; + let tex_document = workspace.lookup(&full_path_uri).unwrap_or(root_document); let range = find_range_of_hint(tex_document, error).unwrap_or_else(|| { let line = error.line.unwrap_or(0); - let offset = *tex_document + let offset = tex_document .line_index - .newlines - .get(line as usize) - .unwrap_or(&TextSize::from(0)); + .offset(LineCol { line, col: 0 }) + .unwrap_or(TextSize::from(0)); TextRange::empty(offset) }); @@ -91,16 +92,17 @@ impl DiagnosticSource for BuildErrors { } fn find_range_of_hint(document: &Document, error: &BuildError) -> Option<TextRange> { - let line = error.line? as usize; + let line = error.line?; let hint = error.hint.as_deref()?; let line_index = &document.line_index; - let line_start = line_index.newlines.get(line).copied()?; + let line_start = line_index.offset(LineCol { line, col: 0 })?; let line_end = line_index - .newlines - .get(line + 1) - .copied() - .unwrap_or((&document.text).text_len()); + .offset(LineCol { + line: line + 1, + col: 0, + }) + .unwrap_or_else(|| document.text.text_len()); let line_text = &document.text[line_start.into()..line_end.into()]; let hint_start = line_start + TextSize::try_from(line_text.find(hint)?).unwrap(); diff --git a/support/texlab/crates/diagnostics/src/citations.rs b/support/texlab/crates/diagnostics/src/citations.rs index 1ab7b6db30..0b750aaadb 100644 --- a/support/texlab/crates/diagnostics/src/citations.rs +++ b/support/texlab/crates/diagnostics/src/citations.rs @@ -47,7 +47,8 @@ fn detect_undefined_citations<'db>( .collect(); for citation in &data.semantics.citations { - if !entries.contains(citation.name.text.as_str()) { + let name = citation.name_text(); + if name != "*" && !entries.contains(name) { let diagnostic = Diagnostic { range: citation.name.range, data: DiagnosticData::Tex(TexError::UndefinedCitation), diff --git a/support/texlab/crates/diagnostics/src/tests.rs b/support/texlab/crates/diagnostics/src/tests.rs index b9eafc0284..539e3ba765 100644 --- a/support/texlab/crates/diagnostics/src/tests.rs +++ b/support/texlab/crates/diagnostics/src/tests.rs @@ -1,14 +1,12 @@ use std::borrow::Cow; -use test_utils::fixture::Fixture; - use crate::{ types::{BibError, Diagnostic, DiagnosticData, TexError}, DiagnosticBuilder, DiagnosticManager, DiagnosticSource, }; fn check(input: &str, expected_data: &[DiagnosticData]) { - let fixture = Fixture::parse(input); + let fixture = test_utils::fixture::Fixture::parse(input); let mut manager = DiagnosticManager::default(); let mut expected = DiagnosticBuilder::default(); |