Skip to content

Commit 2a2bd9d

Browse files
committed
feat!: migrate config to support KDL v2
This change updates kdl-rs to the latest release with support for KDL V2 spec. The release notes are [here](https://github.com/kdl-org/kdl/releases/tag/2.0.0) BREAKING CHANGE
1 parent 77b7394 commit 2a2bd9d

File tree

8 files changed

+197
-160
lines changed

8 files changed

+197
-160
lines changed

Cargo.lock

Lines changed: 132 additions & 97 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ gix = { version = "0.69.1", default-features = false, features = [ "max-performa
2929
indexmap = "2.7.0"
3030
itertools = "0.13.0"
3131
jwalk = "0.8.1"
32-
kdl = "4.6.0"
33-
miette = { version = "5.10.0", features = ["fancy"] }
32+
kdl = "6.1.0"
33+
miette = { version = "7.4.0", features = ["fancy"] }
3434
nucleo = "0.5.0"
3535
ratatui = "0.29.0"
3636
rayon = "1.10.0"

config.kdl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
// Configure the list of search paths used to search for valid workspaces.
22
// Tux uses these valid workspaces as options to attach to.
3-
// paths {
3+
/-paths {
44
// Workspace paths are paths to recursivly search to find valid workspaces.
55
// Tux will recursivly search the workspace paths until the max depth is
66
// reached. To override the default workspace value set optional
7-
// `default=false`.
7+
// `default=#false`.
88
//
99
// Default:
1010
// - "~"
1111
//
12-
// workspace default=true {
13-
// - "~/code"
14-
// }
12+
/-workspace default=#true {
13+
- "~/code"
14+
}
1515

1616
// Single paths are paths that are added to the list of valid workspace
1717
// paths. This is useful if you want to add a path that would not be defined
1818
// as a valid workspace.
1919
//
2020
// Default: (empty)
2121
//
22-
// single default=false {
23-
// - "~/.config/nvim"
24-
// }
25-
// }
22+
/-single default=#false {
23+
- "~/.config/nvim"
24+
}
25+
}
2626

2727
// Search depth for workspace paths.
2828
// Default: 5
2929
//
30-
// depth 3
30+
/-depth 3
3131

3232
// Select the repositories remote default branch if multiple worktrees are found. If the default
3333
// worktree cannot be found the fallback will be to select the correct one.
3434
//
35-
// Default: false
35+
// Default: #false
3636
//
37-
// default_worktree true
37+
/-default_worktree #true
3838

3939
// Workspace directory crawler will prune the paths containing any of these components.
4040
// Options:
41-
// - default: boolean = true # Append to default value if true.
41+
// - default: boolean = #true # Append to default value if true.
4242
//
4343
// Default:
44-
// exclude_path default=true {
44+
// exclude_path default=#true {
4545
// - ".direnv"
4646
// - "node_modules"
4747
// }
4848
//
49-
// exclude_path {
50-
// - ".direnv"
51-
// - "node_modules"
52-
// }
49+
/-exclude_path {
50+
- ".direnv"
51+
- "node_modules"
52+
}

doc/configuration.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Default: `false`
5959

6060
[source,javascript]
6161
----
62-
default_worktree true
62+
default_worktree #true
6363
----
6464

6565
=== exclude_paths
@@ -76,7 +76,7 @@ Default: `{ - ".direnv" "node_modules" }`
7676

7777
[source,javascript]
7878
----
79-
exclude_paths default=false {
79+
exclude_paths default=#false {
8080
- ".direnv"
8181
- "node_modules"
8282
}
@@ -90,7 +90,7 @@ attach to.
9090
==== paths.workspace
9191

9292
Workspace paths are paths to recursivly search to find valid workspaces. Tux will recursivly search the workspace paths
93-
until the max depth is reached. To override the default workspace value set optional `default=false`
93+
until the max depth is reached. To override the default workspace value set optional `default=#false`
9494

9595
Optional arguments:
9696

@@ -103,7 +103,7 @@ Default: `{ - "~" }`
103103
[source, javascript]
104104
----
105105
paths {
106-
workspaces default=false {
106+
workspaces default=#false {
107107
- "~/code"
108108
}
109109
}
@@ -125,7 +125,7 @@ Default: `{}`
125125
[source, javascript]
126126
----
127127
paths {
128-
single default=false {
128+
single default=#false {
129129
- "~/.config/nvim"
130130
}
131131
}

readme.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ Default: `false`
263263

264264
[source,javascript]
265265
----
266-
default_worktree true
266+
default_worktree #true
267267
----
268268

269269
=== exclude_paths
@@ -280,7 +280,7 @@ Default: `{ - ".direnv" "node_modules" }`
280280

281281
[source,javascript]
282282
----
283-
exclude_paths default=false {
283+
exclude_paths default=#false {
284284
- ".direnv"
285285
- "node_modules"
286286
}
@@ -294,7 +294,7 @@ attach to.
294294
==== paths.workspace
295295

296296
Workspace paths are paths to recursivly search to find valid workspaces. Tux will recursivly search the workspace paths
297-
until the max depth is reached. To override the default workspace value set optional `default=false`
297+
until the max depth is reached. To override the default workspace value set optional `default=#false`
298298

299299
Optional arguments:
300300

@@ -307,7 +307,7 @@ Default: `{ - "~" }`
307307
[source, javascript]
308308
----
309309
paths {
310-
workspaces default=false {
310+
workspaces default=#false {
311311
- "~/code"
312312
}
313313
}
@@ -329,7 +329,7 @@ Default: `{}`
329329
[source, javascript]
330330
----
331331
paths {
332-
single default=false {
332+
single default=#false {
333333
- "~/.config/nvim"
334334
}
335335
}

src/config/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ impl Config {
6767
let config_path = util::get_config(&["config.kdl"]);
6868
if config_path.exists() {
6969
config = Parser::new(Source::load(config_path.display().to_string())?)
70-
.parse_with_default(Some(config))?;
70+
.parse_with_config(Some(config))?;
7171
}
7272

7373
let local_path = util::get_local(&["config.kdl"]);
7474
if local_path.exists() {
7575
config = Parser::new(Source::load(local_path.display().to_string())?)
76-
.parse_with_default(Some(config))?;
76+
.parse_with_config(Some(config))?;
7777
}
7878

7979
Ok(config)

src/config/parser.rs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ pub struct Parser {
1010

1111
fn type_from_value(value: &KdlValue) -> &'static str {
1212
match value {
13-
KdlValue::RawString(_) | KdlValue::String(_) => "string",
14-
KdlValue::Null => "null",
13+
KdlValue::String(_) => "string",
14+
KdlValue::Integer(_) => "integer",
15+
KdlValue::Float(_) => "float",
1516
KdlValue::Bool(_) => "boolean",
16-
KdlValue::Base10Float(_) => "float",
17-
_ => "number",
17+
KdlValue::Null => "null",
1818
}
1919
}
2020

21-
fn get_dash_values<'a>(doc: &'a KdlDocument, name: &'static str) -> Vec<&'a KdlEntry> {
21+
fn get_dash_values<'a>(doc: &'a KdlDocument, name: &'static str) -> Vec<&'a KdlValue> {
2222
doc.get(name)
2323
.and_then(|n| n.children())
2424
.map(|doc| doc.nodes())
@@ -35,11 +35,11 @@ impl Parser {
3535
}
3636

3737
pub fn parse(self) -> Result<Config, ParseError> {
38-
self.parse_with_default(None)
38+
self.parse_with_config(None)
3939
}
4040

41-
pub fn parse_with_default(self, default: Option<Config>) -> Result<Config, ParseError> {
42-
self.inner_parse(default.unwrap_or_default())
41+
pub fn parse_with_config(self, config: Option<Config>) -> Result<Config, ParseError> {
42+
self.inner_parse(config.unwrap_or_default())
4343
}
4444

4545
fn inner_parse(self, mut config: Config) -> Result<Config, ParseError> {
@@ -94,7 +94,7 @@ impl Parser {
9494
return Err(ParseError::UnknownConfigurationOption(
9595
option.to_owned(),
9696
self.src.clone(),
97-
*node.name().span(),
97+
node.name().span(),
9898
));
9999
}
100100
}
@@ -107,7 +107,7 @@ impl Parser {
107107
node.entries()
108108
.iter()
109109
.next()
110-
.ok_or(ParseError::MissingValue(self.src.clone(), *node.span()))
110+
.ok_or(ParseError::MissingValue(self.src.clone(), node.span()))
111111
}
112112

113113
// fn first_entry_as_string<'a>(&'a self, node: &'a KdlNode) -> Result<&'a str, ParseError> {
@@ -123,12 +123,16 @@ impl Parser {
123123

124124
fn first_entry_as_i64<'a>(&'a self, node: &'a KdlNode) -> Result<i64, ParseError> {
125125
self.first_entry(node).and_then(|entry| {
126-
entry.value().as_i64().ok_or(ParseError::TypeMismatch(
127-
"number",
128-
type_from_value(entry.value()),
129-
self.src.clone(),
130-
*entry.span(),
131-
))
126+
entry
127+
.value()
128+
.as_integer()
129+
.map(|n| n as i64)
130+
.ok_or(ParseError::TypeMismatch(
131+
"integer",
132+
type_from_value(entry.value()),
133+
self.src.clone(),
134+
entry.span(),
135+
))
132136
})
133137
}
134138

@@ -138,18 +142,18 @@ impl Parser {
138142
"bool",
139143
type_from_value(entry.value()),
140144
self.src.clone(),
141-
*entry.span(),
145+
entry.span(),
142146
))
143147
})
144148
}
145149

146150
fn get_default_optional(&self, node: &KdlNode) -> Result<bool, ParseError> {
147151
match node.get("default") {
148-
Some(value) => value.value().as_bool().ok_or(ParseError::TypeMismatch(
152+
Some(value) => value.as_bool().ok_or(ParseError::TypeMismatch(
149153
"boolean",
150-
type_from_value(value.value()),
154+
type_from_value(value),
151155
self.src.clone(),
152-
*value.span(),
156+
node.span(),
153157
)),
154158
None => Ok(true),
155159
}
@@ -162,15 +166,14 @@ impl Parser {
162166
) -> Result<Vec<String>, ParseError> {
163167
get_dash_values(doc, name)
164168
.into_iter()
165-
.map(|entry| {
166-
entry
167-
.value()
169+
.map(|value| {
170+
value
168171
.as_string()
169172
.ok_or(ParseError::TypeMismatch(
170173
"string",
171-
type_from_value(entry.value()),
174+
type_from_value(value),
172175
self.src.clone(),
173-
*entry.span(),
176+
doc.span(),
174177
))
175178
.map(|s| s.to_string())
176179
})
@@ -184,15 +187,14 @@ impl Parser {
184187
) -> Result<Vec<String>, ParseError> {
185188
get_dash_values(doc, name)
186189
.into_iter()
187-
.map(|entry| {
188-
entry
189-
.value()
190+
.map(|value| {
191+
value
190192
.as_string()
191193
.ok_or(ParseError::TypeMismatch(
192194
"string",
193-
type_from_value(entry.value()),
195+
type_from_value(value),
194196
self.src.clone(),
195-
*entry.span(),
197+
doc.span(),
196198
))
197199
.map(|s| shellexpand::tilde(s).to_string())
198200
})

src/config/source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl SourceCode for Source {
4747
}
4848
}
4949

50-
impl From<&Source> for NamedSource {
50+
impl From<&Source> for NamedSource<String> {
5151
fn from(source: &Source) -> Self {
5252
let name = source.path.clone();
5353
let input = source.raw.clone();

0 commit comments

Comments
 (0)