diff --git a/crates/iwes/CHANGELOG.md b/crates/iwes/CHANGELOG.md index e256524..70a69c9 100644 --- a/crates/iwes/CHANGELOG.md +++ b/crates/iwes/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- `textDocument/rename` no longer panics when invoked on a link whose target key is missing from the graph (broken link); the request now returns no edit. + ## [0.1.2](https://github.com/iwe-org/iwe/compare/iwes-v0.1.1...iwes-v0.1.2) - 2026-05-04 ### Changed diff --git a/crates/iwes/src/router/server.rs b/crates/iwes/src/router/server.rs index 351e21d..ec17185 100644 --- a/crates/iwes/src/router/server.rs +++ b/crates/iwes/src/router/server.rs @@ -410,9 +410,9 @@ impl Server { .to_key(&self.base_path), ) .and_then(|parser| parser.url_at(params.text_document_position.position.to_model())) - .map(|url| { - let key = Key::from_rel_link_url(&url, relative_to); - + .map(|url| Key::from_rel_link_url(&url, relative_to)) + .filter(|key| query::key_exists(&self.graph, key)) + .map(|key| { let affected_keys = query::all_backlinks(&self.graph, &key) .into_iter() .filter(|k| k != &key) diff --git a/crates/iwes/tests/rename_test.rs b/crates/iwes/tests/rename_test.rs index 9f1883e..1df52e6 100644 --- a/crates/iwes/tests/rename_test.rs +++ b/crates/iwes/tests/rename_test.rs @@ -111,6 +111,17 @@ fn rename_with_empty_link_text() { ); } +#[test] +fn rename_link_to_nonexistent_file_returns_no_edit() { + let fixture = Fixture::with_documents(vec![("test", "[Another section](missing)\n")]); + + let actual = fixture.send_request::( + uri_from("test").to_rename_params(0, 18, "renamed".to_string()), + ); + + assert_eq!(actual, serde_json::Value::Null); +} + fn assert_prepare_rename(source: &str, _: &str) { Fixture::with(source).prepare_rename( uri(1).to_text_document_position_params(0, 0),