Skip to content

Commit

Permalink
LSP: Deprecate title matching for wiki links (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu committed May 22, 2022
1 parent dbd791f commit 1a05a04
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

All notable changes to this project will be documented in this file.

<!--## Unreleased-->
## Unreleased

### Deprecated

* The LSP server does not support resolving a wiki link to a note title anymore.
* For example, `[[Planet]]` can match a note with filename `i4w0 Planet.md` but not `i4w0.md` with a Markdown title `Planet` anymore.
* This "smart" fallback resolution based on note titles was too fragile and not supported by the `zk` CLI.


## 0.10.1

Expand Down
17 changes: 0 additions & 17 deletions internal/adapter/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,6 @@ func (s *Server) noteForLink(link documentLink, doc *document, notebook *core.No
if note == nil && err == nil && link.IsWikiLink {
// Try to find a partial href match.
note, err = notebook.FindByHref(link.Href, true)
if note == nil && err == nil {
// Fallback on matching the note title.
note, err = s.noteMatchingTitle(link.Href, notebook)
}
}
if note == nil || err != nil {
return nil, err
Expand Down Expand Up @@ -552,19 +548,6 @@ func (s *Server) noteForHref(href string, doc *document, notebook *core.Notebook
return note, err
}

// noteMatchingTitle returns the LSP documentUri for the note matching the given search terms.
func (s *Server) noteMatchingTitle(terms string, notebook *core.Notebook) (*core.MinimalNote, error) {
if terms == "" {
return nil, nil
}

note, err := notebook.FindMatching("title:(" + terms + ")")
if err != nil {
s.logger.Printf("findMatching(title: %s): %s", terms, err.Error())
}
return note, err
}

type Note struct {
core.MinimalNote
URI protocol.DocumentUri
Expand Down

4 comments on commit 1a05a04

@pkazmier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that one has to create notes with explicit names from this point forward? Is there a way to force the note file name via zk new and ask edit —interactive or corresponding zk-nvim commands? Thanks!

@pkazmier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm … I think I’m confused. If one uses markdown links and not wiki style links, does that mean this change has no impact?

@mickael-menu
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkazmier This change has no impact on [Markdown](links), only [[Wiki links]].

Basically before [[Wiki links]] were able to contain either a part of a note's filename or a part of the title (as in YAML frontmatter / Markdown first heading). This was quite fragile and didn't fare well with the index database.
Instead now a [[Wiki link]] must be any unique portion of a note's filename.

You're probably fine, but I'll answer your other questions:

Does this mean that one has to create notes with explicit names from this point forward?

No, you can still use a random ID, e.g. i3br.md and then reference it as [[i3br]] or [A note](i3br).
If you add the note title in the filename as well, e.g i3br A note.md, you can use:

[[i3br]]
[[i3br A note]]
[[A note]]

[A note](i3br)
[A note](i3br A note)

Is there a way to force the note file name via zk new?

Not directly, but you can use a {{title}} template for the filename in the config, then run zk new with zk new --title "My title".

[note]
filename = "{{title}}"

@pkazmier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the detailed explanation.

Please sign in to comment.