fix(lsp): resolve wikilinks that include the .wiki file extension

`[[page.wiki]]` should resolve identically to `[[page]]`. The index
keyed by stem, so links with the explicit extension fell through to
the broken-link diagnostic and to-page navigation failed. Strip the
configured extension before every page lookup (resolve, definition,
backlinks, classify_link, classify_outgoing) and stop appending the
extension in synthesise_page_uri when it's already present.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 22:00:03 -03:00
parent 6ae642dbee
commit 2aec51274e
4 changed files with 69 additions and 16 deletions
+15 -8
View File
@@ -240,7 +240,8 @@ impl Backend {
};
let path = target.path.as_deref()?;
if let Ok(idx) = target_wiki.index.read() {
if let Some(uri) = idx.pages_by_name.get(path).cloned() {
let normalized = idx.strip_link_extension(path);
if let Some(uri) = idx.pages_by_name.get(normalized).cloned() {
return Some(uri);
}
}
@@ -711,7 +712,10 @@ impl LanguageServer for Backend {
index::page_name_from_uri(uri, wiki.as_ref().map(|w| w.config.root.as_path()));
let target_page = match nav::find_inline_at(&doc.ast, line, col) {
Some(InlineNode::WikiLink(w)) => match w.target.kind {
nuwiki_core::ast::LinkKind::Wiki => w.target.path.clone(),
nuwiki_core::ast::LinkKind::Wiki => w.target.path.as_ref().map(|p| {
let ext = wiki.as_ref().map(|w| w.config.file_extension.as_str());
index::strip_wiki_extension(p, ext).to_string()
}),
nuwiki_core::ast::LinkKind::AnchorOnly => Some(source_page.clone()),
_ => None,
},
@@ -977,12 +981,15 @@ fn synthesise_page_uri(cfg: &crate::config::WikiConfig, path: &str) -> Option<Ur
}
let ext = cfg.file_extension.trim_start_matches('.');
if !ext.is_empty() {
let stem = p
.file_name()
.map(|s| s.to_string_lossy().into_owned())
.unwrap_or_default();
if !stem.is_empty() {
p.set_file_name(format!("{stem}.{ext}"));
let current_ext = p.extension().and_then(|e| e.to_str()).unwrap_or("");
if current_ext != ext {
let stem = p
.file_name()
.map(|s| s.to_string_lossy().into_owned())
.unwrap_or_default();
if !stem.is_empty() {
p.set_file_name(format!("{stem}.{ext}"));
}
}
}
Url::from_file_path(p).ok()