Skip to content

Commit 439aa63

Browse files
feat(deps): Absolve kdl-rs of syn (#125)
This completes the removal of `syn` from `kdl-rs`s dependency tree!
1 parent c1680e8 commit 439aa63

File tree

8 files changed

+160
-40
lines changed

8 files changed

+160
-40
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
runs-on: ${{ matrix.os }}
2929
strategy:
3030
matrix:
31-
rust: [1.71.1, stable]
31+
rust: [1.81, stable]
3232
os: [ubuntu-latest, macOS-latest, windows-latest]
3333

3434
steps:

.github/workflows/release.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ on:
4747
jobs:
4848
# Run 'dist plan' (or host) to determine what tasks we need to do
4949
plan:
50-
runs-on: "ubuntu-20.04"
50+
runs-on: "ubuntu-22.04"
5151
outputs:
5252
val: ${{ steps.plan.outputs.manifest }}
5353
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
@@ -168,7 +168,7 @@ jobs:
168168
needs:
169169
- plan
170170
- build-local-artifacts
171-
runs-on: "ubuntu-20.04"
171+
runs-on: "ubuntu-22.04"
172172
env:
173173
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
174174
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
@@ -218,7 +218,7 @@ jobs:
218218
if: ${{ always() && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.build-local-artifacts.result == 'skipped' || needs.build-local-artifacts.result == 'success') }}
219219
env:
220220
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
221-
runs-on: "ubuntu-20.04"
221+
runs-on: "ubuntu-22.04"
222222
outputs:
223223
val: ${{ steps.host.outputs.manifest }}
224224
steps:
@@ -278,7 +278,7 @@ jobs:
278278
needs:
279279
- plan
280280
- host
281-
runs-on: "ubuntu-20.04"
281+
runs-on: "ubuntu-22.04"
282282
env:
283283
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
284284
PLAN: ${{ needs.plan.outputs.val }}
@@ -311,7 +311,7 @@ jobs:
311311
# still allowing individual publish jobs to skip themselves (for prereleases).
312312
# "host" however must run to completion, no skipping allowed!
313313
if: ${{ always() && needs.host.result == 'success' && (needs.publish-npm.result == 'skipped' || needs.publish-npm.result == 'success') }}
314-
runs-on: "ubuntu-20.04"
314+
runs-on: "ubuntu-22.04"
315315
env:
316316
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
317317
steps:

Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ readme = "README.md"
88
homepage = "https://kdl.dev"
99
repository = "https://github.com/kdl-org/kdl-rs"
1010
keywords = ["kdl", "document", "serialization", "config"]
11-
rust-version = "1.71.1"
11+
rust-version = "1.81"
1212
edition = "2021"
1313

1414
[features]
@@ -22,17 +22,16 @@ members = ["tools/*"]
2222

2323
[dependencies]
2424
miette.workspace = true
25-
thiserror.workspace = true
2625
num = "0.4.2"
2726
winnow = { version = "=0.6.24", features = ["alloc", "unstable-recover"] }
2827
kdlv1 = { package = "kdl", version = "4.7.0", optional = true }
2928

3029
[workspace.dependencies]
31-
miette = "7.2.0"
32-
thiserror = "1.0.40"
30+
miette = { version = "7.6.0", default-features = false }
3331

3432
[dev-dependencies]
35-
miette = { workspace = true, features = ["fancy"] }
33+
miette = { workspace = true, features = ["derive", "fancy"] }
34+
thiserror = "2.0.12"
3635
pretty_assertions = "1.3.0"
3736

3837
# The profile that 'dist' will build with

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ Error:
109109

110110
* `span` (default) - Includes spans in the various document-related structs.
111111
* `v1` - Adds support for v1 parsing. This will pull in the entire previous
112-
version of `kdl-rs`, and so may be fairly heavy.
112+
version of `kdl-rs`, and so may be fairly heavy.
113113
* `v1-fallback` - Implies `v1`. Makes it so the various `*::parse()` and
114-
`FromStr` implementations try to parse their inputs as `v2`, and, if that
115-
fails, try again with `v1`. For `KdlDocument`, a heuristic will be applied
116-
if both `v1` and `v2` parsers fail, to pick which error(s) to return. For
117-
other types, only the `v2` parser's errors will be returned.
114+
`FromStr` implementations try to parse their inputs as `v2`, and, if that
115+
fails, try again with `v1`. For `KdlDocument`, a heuristic will be applied
116+
if both `v1` and `v2` parsers fail, to pick which error(s) to return. For
117+
other types, only the `v2` parser's errors will be returned.
118118

119119
### Quirks
120120

@@ -140,9 +140,9 @@ means a few things:
140140
representation will be thrown away and the actual value will be used when
141141
serializing.
142142

143-
### Minimum Supported Rust Version
143+
### Minimum Supported Rust Version (MSRV)
144144

145-
You must be at least `1.71.1` tall to get on this ride.
145+
You must be at least `1.81` tall to get on this ride.
146146

147147
### License
148148

dist-workspace.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ install-path = "CARGO_HOME"
1717
install-updater = false
1818
# Publish jobs to run in CI
1919
publish-jobs = ["npm"]
20+
21+
[dist.github-custom-runners]
22+
global = "ubuntu-22.04"

src/error.rs

Lines changed: 133 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::sync::Arc;
1+
use std::{error::Error, fmt::Display, iter, sync::Arc};
22

3-
use miette::{Diagnostic, SourceSpan};
4-
use thiserror::Error;
3+
use miette::{Diagnostic, LabeledSpan, Severity, SourceSpan};
54

65
#[cfg(doc)]
76
use {
@@ -34,30 +33,43 @@ use {
3433
/// ╰────
3534
/// help: Floating point numbers must be base 10, and have numbers after the decimal point.
3635
/// ```
37-
#[derive(Debug, Diagnostic, Clone, Eq, PartialEq, Error)]
38-
#[error("Failed to parse KDL document")]
36+
#[derive(Debug, Clone, Eq, PartialEq)]
3937
pub struct KdlError {
4038
/// Original input that this failure came from.
41-
#[source_code]
4239
pub input: Arc<String>,
4340

4441
/// Sub-diagnostics for this failure.
45-
#[related]
4642
pub diagnostics: Vec<KdlDiagnostic>,
4743
}
4844

45+
impl Display for KdlError {
46+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47+
write!(f, "Failed to parse KDL document")
48+
}
49+
}
50+
impl Error for KdlError {}
51+
52+
impl Diagnostic for KdlError {
53+
fn source_code(&self) -> Option<&dyn miette::SourceCode> {
54+
Some(&self.input)
55+
}
56+
57+
fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
58+
Some(Box::new(
59+
self.diagnostics.iter().map(|d| d as &dyn Diagnostic),
60+
))
61+
}
62+
}
63+
4964
/// An individual diagnostic message for a KDL parsing issue.
5065
///
5166
/// While generally signifying errors, they can also be treated as warnings.
52-
#[derive(Debug, Diagnostic, Clone, Eq, PartialEq, Error)]
53-
#[error("{}", message.clone().unwrap_or_else(|| "Unexpected error".into()))]
67+
#[derive(Debug, Clone, Eq, PartialEq)]
5468
pub struct KdlDiagnostic {
5569
/// Shared source for the diagnostic.
56-
#[source_code]
5770
pub input: Arc<String>,
5871

5972
/// Offset in chars of the error.
60-
#[label("{}", label.clone().unwrap_or_else(|| "here".into()))]
6173
pub span: SourceSpan,
6274

6375
/// Message for the error itself.
@@ -67,12 +79,42 @@ pub struct KdlDiagnostic {
6779
pub label: Option<String>,
6880

6981
/// Suggestion for fixing the parser error.
70-
#[help]
7182
pub help: Option<String>,
7283

7384
/// Severity level for the Diagnostic.
74-
#[diagnostic(severity)]
75-
pub severity: miette::Severity,
85+
pub severity: Severity,
86+
}
87+
88+
impl Display for KdlDiagnostic {
89+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90+
let message = self
91+
.message
92+
.clone()
93+
.unwrap_or_else(|| "Unexpected error".into());
94+
write!(f, "{message}")
95+
}
96+
}
97+
impl Error for KdlDiagnostic {}
98+
99+
impl Diagnostic for KdlDiagnostic {
100+
fn source_code(&self) -> Option<&dyn miette::SourceCode> {
101+
Some(&self.input)
102+
}
103+
104+
fn severity(&self) -> Option<Severity> {
105+
Some(self.severity)
106+
}
107+
108+
fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
109+
self.help.as_ref().map(|s| Box::new(s) as Box<dyn Display>)
110+
}
111+
112+
fn labels(&self) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + '_>> {
113+
let label = self.label.clone().unwrap_or_else(|| "here".to_owned());
114+
let labeled_span = LabeledSpan::new_with_span(Some(label), self.span);
115+
116+
Some(Box::new(iter::once(labeled_span)))
117+
}
76118
}
77119

78120
#[cfg(feature = "v1")]
@@ -87,8 +129,84 @@ impl From<kdlv1::KdlError> for KdlError {
87129
message: Some(format!("{}", value.kind)),
88130
label: value.label.map(|x| x.into()),
89131
help: value.help.map(|x| x.into()),
90-
severity: miette::Severity::Error,
132+
severity: Severity::Error,
91133
}],
92134
}
93135
}
94136
}
137+
138+
#[cfg(test)]
139+
mod tests {
140+
use super::*;
141+
142+
#[test]
143+
fn kdl_error() {
144+
let kdl_diagnostic = KdlDiagnostic {
145+
input: Default::default(),
146+
span: SourceSpan::new(0.into(), 0),
147+
message: Default::default(),
148+
label: Default::default(),
149+
help: Default::default(),
150+
severity: Default::default(),
151+
};
152+
153+
let kdl_error = KdlError {
154+
input: Arc::new("bark? i guess?".to_owned()),
155+
diagnostics: vec![kdl_diagnostic.clone(), kdl_diagnostic],
156+
};
157+
158+
// Test `Error` impl
159+
assert_eq!(kdl_error.to_string(), "Failed to parse KDL document");
160+
assert!(kdl_error.source().is_none());
161+
162+
// Test `Diagnostic` impl
163+
let related: Vec<_> = kdl_error.related().unwrap().collect();
164+
assert_eq!(related.len(), 2);
165+
assert_eq!(
166+
kdl_error
167+
.source_code()
168+
.unwrap()
169+
.read_span(&SourceSpan::new(0.into(), 5), 0, 0)
170+
.unwrap()
171+
.data(),
172+
b"bark?"
173+
);
174+
}
175+
176+
#[test]
177+
fn kdl_diagnostic() {
178+
let mut kdl_diagnostic = KdlDiagnostic {
179+
input: Arc::new("Catastrophic failure!!!".to_owned()),
180+
span: SourceSpan::new(0.into(), 3),
181+
message: None,
182+
label: Some("cute".to_owned()),
183+
help: Some("try harder?".to_owned()),
184+
severity: Severity::Error,
185+
};
186+
187+
// Test `Error` impl
188+
assert_eq!(kdl_diagnostic.to_string(), "Unexpected error");
189+
assert!(kdl_diagnostic.source().is_none());
190+
191+
kdl_diagnostic.message = Some("mega bad news, kiddo".to_owned());
192+
193+
assert_eq!(kdl_diagnostic.to_string(), "mega bad news, kiddo");
194+
assert!(kdl_diagnostic.source().is_none());
195+
196+
// Test `Diagnostic` impl
197+
let labels: Vec<_> = kdl_diagnostic.labels().unwrap().collect();
198+
assert_eq!(labels.len(), 1);
199+
assert_eq!(labels[0].label().unwrap(), "cute");
200+
assert_eq!(
201+
kdl_diagnostic
202+
.source_code()
203+
.unwrap()
204+
.read_span(labels[0].inner(), 0, 0)
205+
.unwrap()
206+
.data(),
207+
b"Cat"
208+
);
209+
assert_eq!(kdl_diagnostic.help().unwrap().to_string(), "try harder?");
210+
assert_eq!(kdl_diagnostic.severity().unwrap(), Severity::Error);
211+
}
212+
}

src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@
107107
//!
108108
//! * `span` (default) - Includes spans in the various document-related structs.
109109
//! * `v1` - Adds support for v1 parsing. This will pull in the entire previous
110-
//! version of `kdl-rs`, and so may be fairly heavy.
110+
//! version of `kdl-rs`, and so may be fairly heavy.
111111
//! * `v1-fallback` - Implies `v1`. Makes it so the various `*::parse()` and
112-
//! `FromStr` implementations try to parse their inputs as `v2`, and, if that
113-
//! fails, try again with `v1`. For `KdlDocument`, a heuristic will be applied
114-
//! if both `v1` and `v2` parsers fail, to pick which error(s) to return. For
115-
//! other types, only the `v2` parser's errors will be returned.
112+
//! `FromStr` implementations try to parse their inputs as `v2`, and, if that
113+
//! fails, try again with `v1`. For `KdlDocument`, a heuristic will be applied
114+
//! if both `v1` and `v2` parsers fail, to pick which error(s) to return. For
115+
//! other types, only the `v2` parser's errors will be returned.
116116
//!
117117
//! ## Quirks
118118
//!
@@ -140,7 +140,7 @@
140140
//!
141141
//! ## Minimum Supported Rust Version (MSRV)
142142
//!
143-
//! You must be at least `1.71.1` tall to get on this ride.
143+
//! You must be at least `1.81` tall to get on this ride.
144144
//!
145145
//! ## License
146146
//!

tools/kdl-lsp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ readme = "README.md"
99
homepage = "https://kdl.dev"
1010
repository = "https://github.com/kdl-org/kdl-rs"
1111
keywords = ["kdl", "document", "config", "lsp", "language-server"]
12-
rust-version = "1.71.1"
12+
rust-version = "1.81"
1313

1414
[dependencies]
1515
miette.workspace = true

0 commit comments

Comments
 (0)