fix(links): unify resolution for Markdown and WikiLinks and fix LSP p…#677
fix(links): unify resolution for Markdown and WikiLinks and fix LSP p…#677sfgartland wants to merge 3 commits into
Conversation
|
The correct order is:
If we always default to the root, then In general terms, markdown links are relative to the current file. The other two behaviours are fallbacks for unusual usages. |
0e482c7 to
ace01eb
Compare
Includes tests for Wikilinks, Markdown links, relative paths, root-absolute paths, and resolution priority.
Verifies that the LSP definition handler handles nil or incomplete client capability objects without crashing.
…anic Markdown and WikiLinks are now resolved using an identical three-step hierarchy: 1. Match relative to the current file. 2. Exact match relative to the vault root. 3. Fallback to partial path matching. This priority ensures that relative links are not hijacked by root-level files with the same name. This also fixes the issue where Markdown links requiring extensions were not properly indexed, and ensures consistent link resolution across CLI and LSP functionalities. Additionally, added a nil-pointer check to the LSP definition handler to prevent crashes when resolving definitions for editors that do not provide full TextDocument LinkSupport capabilities.
I had not considered this issue. I have always defaulted to using the zettel root as a quasi-absolute path for the sake of making refractoring links on move easier, but I can see the other use-cases as well. I've amended my commit to reflect the followin priority:
And also added relevant end-to-end and unit tests |
ace01eb to
0916f62
Compare
| linkSupport := false | ||
| if clientCapabilities.TextDocument != nil && clientCapabilities.TextDocument.Definition != nil { | ||
| linkSupport = isTrue(clientCapabilities.TextDocument.Definition.LinkSupport) | ||
| } | ||
|
|
||
| if linkSupport { |
There was a problem hiding this comment.
Why is this change required here?
| // 1. Prioritize exact match (either literal href or root-relative). | ||
| for _, h := range []string{href, rootHref} { | ||
| id, err := d.FindIDByPath(h) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if id.IsValid() { | ||
| return []core.NoteID{id}, nil | ||
| } |
There was a problem hiding this comment.
In x/a.md, a link b.md will prefer note b.md, but should prefer x/b.md.
…anic
Markdown and WikiLinks are now resolved using an identical three-step hierarchy:
This fixes the issue where Markdown links requiring extensions were not properly indexed, and ensures consistent link resolution across CLI and LSP functionalities.
Additionally, added a nil-pointer check to the LSP definition handler to prevent crashes when resolving definitions for editors that do not provide full TextDocument LinkSupport capabilities.
...
Fixes #676