Skip to content

Commit 94e9fd9

Browse files
committed
inputs/pin: skip inputs without url
1 parent 41321ac commit 94e9fd9

13 files changed

+152
-30
lines changed

src/update.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ impl Updater {
176176
pub fn new(text: Rope, map: InputMap) -> Self {
177177
let mut inputs = vec![];
178178
for (_id, input) in map {
179+
// Skip inputs without a URL (e.g. expanded type/owner/repo/ref format
180+
// or follows-only stubs) — there is no quoted URL value to modify.
181+
if input.url.is_empty() || input.range.start == 0 && input.range.end == 0 {
182+
continue;
183+
}
179184
inputs.push(UpdateInput { input });
180185
}
181186
Self {

src/walk/inputs.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub fn insert_with_ctx(
5454
if let Some(node) = inputs.get_mut(&id) {
5555
if !input.url.to_string().is_empty() {
5656
node.url = input.url;
57+
node.range = input.range;
5758
}
5859
if !input.flake {
5960
node.flake = input.flake;
@@ -380,7 +381,7 @@ fn handle_nested_input(
380381
for binding in attr.children() {
381382
if binding.to_string() == "url" {
382383
let url = binding.next_sibling().unwrap();
383-
let input = Input::with_url(id_str.clone(), url.to_string(), input_id.text_range());
384+
let input = Input::with_url(id_str.clone(), url.to_string(), url.text_range());
384385
insert_with_ctx(inputs, id_str.clone(), input, ctx);
385386
}
386387
if should_remove_input(change, ctx, &id_str) {
@@ -1001,8 +1002,9 @@ fn handle_input_attr_set(
10011002
// `inputs = { nixpkgs = { follows = "nixpkgs"; }; }`
10021003
if leaf.to_string() == "inputs"
10031004
&& change.is_remove()
1004-
&& let Some(inputs_attrset) =
1005-
attr.children().find(|c| c.kind() == SyntaxKind::NODE_ATTR_SET)
1005+
&& let Some(inputs_attrset) = attr
1006+
.children()
1007+
.find(|c| c.kind() == SyntaxKind::NODE_ATTR_SET)
10061008
{
10071009
for nested_entry in inputs_attrset.children() {
10081010
if nested_entry.kind() != SyntaxKind::NODE_ATTRPATH_VALUE {
@@ -1014,11 +1016,7 @@ fn handle_input_attr_set(
10141016
let Some(nested_id) = nested_path.first_child() else {
10151017
continue;
10161018
};
1017-
if should_remove_nested_input(
1018-
change,
1019-
&ctx_some,
1020-
&nested_id.to_string(),
1021-
) {
1019+
if should_remove_nested_input(change, &ctx_some, &nested_id.to_string()) {
10221020
let new_inputs_attrset = remove_child_with_whitespace(
10231021
&inputs_attrset,
10241022
&nested_entry,

tests/snapshots/edit__flake_edit_list@completely_flat_toplevel_alt.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ crane:
2020
- rust-overlay
2121
- "\"rust-overlay\""
2222
range:
23-
start: 0
24-
end: 0
23+
start: 466
24+
end: 488
2525
flake-utelinos:
2626
id: flake-utelinos
2727
flake: true
@@ -50,5 +50,5 @@ rust-overlay:
5050
- nixpkgs
5151
- "\"nixpkgs\""
5252
range:
53-
start: 0
54-
end: 0
53+
start: 256
54+
end: 285

tests/snapshots/edit__flake_edit_list@completely_flat_toplevel_not_a_flake_nested.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ not-a-flake:
4444
url: "\"github:a-kenji/not-a-flake\""
4545
follows: []
4646
range:
47-
start: 585
48-
end: 596
47+
start: 611
48+
end: 639
4949
rust-overlay:
5050
id: rust-overlay
5151
flake: true

tests/snapshots/edit__flake_edit_list@one_level_nesting_flat_not_a_flake.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ also-not-a-flake:
1111
url: "\"github:a-kenji/also-not-a-flake\""
1212
follows: []
1313
range:
14-
start: 72
15-
end: 88
14+
start: 131
15+
end: 164
1616
crane:
1717
id: crane
1818
flake: true

tests/snapshots/edit__flake_edit_list@toplevel_nesting.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ crane:
2020
- rust-overlay
2121
- "\"rust-overlay\""
2222
range:
23-
start: 272
24-
end: 277
23+
start: 292
24+
end: 314
2525
nixpkgs:
2626
id: nixpkgs
2727
flake: true
@@ -42,5 +42,5 @@ rust-overlay:
4242
- nixpkgs
4343
- "\"nixpkgs\""
4444
range:
45-
start: 111
46-
end: 123
45+
start: 138
46+
end: 167
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: tests/update.rs
3+
expression: updater.get_changes()
4+
---
5+
{
6+
inputs = {
7+
myInput = {
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
url = "github:foo/bar/abc123";
10+
};
11+
};
12+
13+
outputs = { self, myInput }: { };
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
source: tests/update.rs
3+
expression: updater.get_changes()
4+
---
5+
{
6+
inputs = {
7+
myInput = {
8+
type = "github";
9+
owner = "NixOS";
10+
repo = "nixpkgs";
11+
ref = "nixos-25.11";
12+
};
13+
pinned.url = "github:foo/bar";
14+
};
15+
16+
outputs = { self, myInput, pinned }: { };
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: tests/update.rs
3+
expression: updater.get_changes()
4+
---
5+
{
6+
inputs = {
7+
myInput = {
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
url = "github:foo/bar";
10+
};
11+
};
12+
13+
outputs = { self, myInput }: { };
14+
}

tests/snapshots/walker__walker_list_inputs@completely_flat_toplevel_alt.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ crane:
2020
- rust-overlay
2121
- "\"rust-overlay\""
2222
range:
23-
start: 0
24-
end: 0
23+
start: 466
24+
end: 488
2525
flake-utelinos:
2626
id: flake-utelinos
2727
flake: true
@@ -50,5 +50,5 @@ rust-overlay:
5050
- nixpkgs
5151
- "\"nixpkgs\""
5252
range:
53-
start: 0
54-
end: 0
53+
start: 256
54+
end: 285

0 commit comments

Comments
 (0)