-
Notifications
You must be signed in to change notification settings - Fork 183
fix(links): unify resolution for Markdown and WikiLinks and fix LSP p… #677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sfgartland
wants to merge
3
commits into
zk-org:dev
Choose a base branch
from
sfgartland:markdown-links-bug
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,31 +296,48 @@ func (d *NoteDAO) findIDsByHrefs(hrefs []string, allowPartialHrefs bool) ([]core | |
| // FindIdsByHref finds note IDs which match the given href string. | ||
| // This implements logic similar to NoteIndex.linkMatchesPath. | ||
| func (d *NoteDAO) FindIdsByHref(href string, allowPartialHref bool) ([]core.NoteID, error) { | ||
| var err error | ||
| // Remove any anchor at the end of the HREF, since it's most likely | ||
| // matching a sub-section in the note. | ||
| href = strings.SplitN(href, "#", 2)[0] | ||
|
|
||
| href = strings.NewReplacer("%", "\\%", "_", "\\_").Replace(href) | ||
|
|
||
| // Treat leading slash as relative to the notebook root. | ||
| rootHref := strings.TrimPrefix(href, "/") | ||
|
|
||
| // Prioritise exact match with extension. | ||
| id, err := d.FindIDByPath(href + "." + d.extension) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if id.IsValid() { | ||
| return []core.NoteID{id}, nil | ||
| // 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 | ||
| } | ||
|
Comment on lines
+309
to
+317
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
|
|
||
| // Try with extension. | ||
| if !strings.HasSuffix(h, "."+d.extension) { | ||
| id, err = d.FindIDByPath(h + "." + d.extension) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if id.IsValid() { | ||
| return []core.NoteID{id}, nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| var ids []core.NoteID | ||
| if allowPartialHref { | ||
| // Filename (not path) contains 'href' anywhere. | ||
| ids, err = d.findIDsByFilenameLike("%" + href + "%") | ||
| ids, err = d.findIDsByFilenameLike("%" + rootHref + "%") | ||
| if len(ids) > 0 || err != nil { | ||
| return ids, err | ||
| } | ||
|
|
||
| // Path contains 'href' anywhere. | ||
| ids, err = d.findIDsByPathLike("%" + href + "%") | ||
| ids, err = d.findIDsByPathLike("%" + rootHref + "%") | ||
| if len(ids) > 0 || err != nil { | ||
| return ids, err | ||
| } | ||
|
|
@@ -329,7 +346,7 @@ func (d *NoteDAO) FindIdsByHref(href string, allowPartialHref bool) ([]core.Note | |
| // Path either: | ||
| // 1. starts with 'href' and has no slash after href. | ||
| // 2. starts with 'href/', followed by more content. | ||
| ids, err = d.findIDsByPathPrefix(href) | ||
| ids, err = d.findIDsByPathPrefix(rootHref) | ||
| if len(ids) > 0 || err != nil { | ||
| return ids, err | ||
| } | ||
|
|
@@ -528,17 +545,25 @@ func (d *NoteDAO) findRows(opts core.NoteFindOpts, selection noteSelection) (*sq | |
| } | ||
|
|
||
| idSelects := make([]string, 0) | ||
| hrefList := "(" + joinStrings(hrefs, ",", "'") + ")" | ||
| if direction <= 0 { | ||
| idSelects = append(idSelects, fmt.Sprintf( | ||
| " SELECT target_id FROM %s WHERE target_id IS NOT NULL AND source_id IN %s", | ||
| linksSrc, idsList, | ||
| )) | ||
| } | ||
| if direction >= 0 { | ||
| idSelects = append(idSelects, fmt.Sprintf( | ||
| " SELECT source_id FROM %s WHERE target_id IS NOT NULL AND target_id IN %s", | ||
| linksSrc, idsList, | ||
| )) | ||
| if linksSrc == "links" { | ||
| idSelects = append(idSelects, fmt.Sprintf( | ||
| " SELECT source_id FROM %s WHERE (target_id IN %s OR (target_id IS NULL AND href IN %s))", | ||
| linksSrc, idsList, hrefList, | ||
| )) | ||
| } else { | ||
| idSelects = append(idSelects, fmt.Sprintf( | ||
| " SELECT source_id FROM %s WHERE target_id IS NOT NULL AND target_id IN %s", | ||
| linksSrc, idsList, | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| idExpr += " IN (\n" + strings.Join(idSelects, "\n UNION\n") + "\n)" | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change required here?