fix(lsp): match wikilink anchors against raw heading text
`[[Page#Heading text]]` parsed the anchor as the literal string after `#`, but the index stored each heading's anchor as `slugify(title)`. The two never compared equal, so every TOC-style anchor link (`[[#1. Topologia atual]]`, etc.) was reported as a broken anchor and goto-definition couldn't jump to the right heading either. Slugify the request before comparing — `slugify` is idempotent on valid-slug input, so the same code path now accepts both `[[Page#some-heading]]` (slug form) and `[[Page#Some Heading]]` (raw text). Applied to diagnostics, navigation, and hover preview so all three agree on what "an anchor matches a heading" means. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -62,6 +62,18 @@ pub struct HeadingInfo {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
impl IndexedPage {
|
||||
/// Find a heading whose anchor matches `request`. The on-disk wikilink
|
||||
/// syntax lets users write either the slug (`[[Page#some-heading]]`) or
|
||||
/// the raw heading text (`[[Page#Some Heading]]`). `slugify` is
|
||||
/// idempotent on valid slug input, so applying it to the request
|
||||
/// before comparison handles both forms in a single pass.
|
||||
pub fn find_heading_by_anchor(&self, request: &str) -> Option<&HeadingInfo> {
|
||||
let needle = slugify(request);
|
||||
self.headings.iter().find(|h| h.anchor == needle)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct OutgoingLink {
|
||||
/// Resolved target page name (for `LinkKind::Wiki`) or `None` for kinds
|
||||
|
||||
Reference in New Issue
Block a user