LSP: resolve leading-slash links against the notebook root#745
Open
zmre wants to merge 2 commits into
Open
Conversation
Author
|
Just some more context: I submitted this because zk commonly flags errors in my docs that aren't errors. I don't want to suppress them because I want to know when there are bad links. The pattern of using absolute paths to refer to the top of the repo is very common and wasn't previously working for either actual absolute paths (relative to filesystem root) or for repo-relative ones, but now can work for either of those cases. Anyway, I hope it's a welcome change. |
Links like [Note](/sub/note-a) are now resolved relative to the notebook root, which aligns with the way most Markdown renderers treat root-relative destinations. So if building notes as a series of web pages, absolute refers to the project root. We still fallback to the filesystem root for absolute to allow links to anything on the drive. Previously these links were joined onto the current note's directory (ie, `/path/to/note_parent//absolute/link` which I think produced unexpected behaviors in almost all cases, failed to resolve, broke go-to-definition, hover, references, and produced false dead-link diagnostics. This was closed in zk-org#494, but I believe it has merit and I don't see any downside to supporting this behavior. Fixes zk-org#494
e972203 to
f72c853
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Links like
[Note](/sub/note-a)are now resolved relative to the notebook root, which aligns with the way most Markdown renderers treat root-relative destinations. So if building notes as a series of web pages, absolute refers to the project root. We still fallback to the filesystem root for absolute to allow links to anything on the drive.Previously these links were joined onto the current note's directory (ie,
/path/to/note_parent//absolute/linkwhich I think produced unexpected behaviors in almost all cases, broke go-to-definition, hover, references, and produced false dead-link diagnostics for any links with leading slashes.This was brought up and closed in #494 , but I believe it has merit and I don't see any downside to supporting this behavior. Obviously feel free to disagree.
Fixes #494
Note
I didn't see anything in
CONTRIBUTING.mdabout AI. I'm mostly a rust programmer and have only lightly dabbled in Go, so I did use AI to help me with this fix and especially in generating tests to validate it. If that's not okay, I completely understand. I hand wrote aspects and reviewed every line manually and I believe this is a useful contribution of good quality.