Skip to content
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

LSP Go-to-reference does not work, if notes are in a folder. #243

Closed
bibor opened this issue Jul 12, 2022 · 2 comments · Fixed by #245
Closed

LSP Go-to-reference does not work, if notes are in a folder. #243

bibor opened this issue Jul 12, 2022 · 2 comments · Fixed by #245

Comments

@bibor
Copy link
Contributor

bibor commented Jul 12, 2022

Description

The find-references feature of the LSP (tracked in #22) does not work if the notes are organized in folders.

Expected Behaviour

find-reference should return all references to the given note.

Steps to Reproduce

  1. have a zettelkasten with the following layout
$ tree 
.
└── old
    ├── eso7.md
    ├── jbxt.md
    └── vlix.md
  1. set a link from vlix.md to jbxt.md
# top-note

blub

I reference another note: [ref-note](jbxt)
  1. open jbxt.md
  2. call find-references on the language server client.
The links are recognized by `zk` as the graph output shows:
$ zk graph --format=json | jq
{
  "notes": [
    {
      "filename": "eso7.md",
      "filenameStem": "eso7",
      "path": "old/eso7.md",
      "absPath": "/home/user/Documents/zk-test2/old/eso7.md",
      "title": "newly generated note",
      "link": "[newly generated note](old/eso7)",
      "lead": "generated with `zk new` directly in the old folder",
      "body": "generated with `zk new` directly in the old folder",
      "snippets": [
        "generated with `zk new` directly in the old folder"
      ],
      "rawContent": "# newly generated note\n\ngenerated with `zk new` directly in the old folder\n\n",
      "wordCount": 13,
      "tags": [],
      "metadata": {},
      "created": "2022-07-12T09:21:40.15040095Z",
      "modified": "2022-07-12T09:22:06.859619184Z",
      "checksum": "002388945a56d9be780edc458230055057439a5c89eb6474eb9f1490c906a1bb"
    },
    {
      "filename": "jbxt.md",
      "filenameStem": "jbxt",
      "path": "old/jbxt.md",
      "absPath": "/home/user/Documents/zk-test2/old/jbxt.md",
      "title": "ref-note",
      "link": "[ref-note](old/jbxt)",
      "lead": "Blub",
      "body": "Blub\n\nOriginal note: [top-note](vlix)",
      "snippets": [
        "Blub"
      ],
      "rawContent": "# ref-note\n\nBlub\n\nOriginal note: [top-note](vlix)\n",
      "wordCount": 6,
      "tags": [],
      "metadata": {},
      "created": "2022-07-12T09:16:54.491128191Z",
      "modified": "2022-07-12T09:18:30.498392496Z",
      "checksum": "6b54952eb7a1442bc0b778fe49ee00e307ffb23e3622f8d9cb54a1fe841ff076"
    },
    {
      "filename": "vlix.md",
      "filenameStem": "vlix",
      "path": "old/vlix.md",
      "absPath": "/home/user/Documents/zk-test2/old/vlix.md",
      "title": "top-note",
      "link": "[top-note](old/vlix)",
      "lead": "blub",
      "body": "blub\n\nI reference another note: [ref-note](jbxt)",
      "snippets": [
        "blub"
      ],
      "rawContent": "# top-note\n\nblub\n\nI reference another note: [ref-note](jbxt)\n",
      "wordCount": 8,
      "tags": [],
      "metadata": {},
      "created": "2022-07-12T09:16:54.491451242Z",
      "modified": "2022-07-12T08:33:16.160193606Z",
      "checksum": "383e4807211ba6d5f066efa09a70b6ca628c4e50fe080f4b6fb623c9e4f81fc2"
    }
  ],
  "links": [
    {
      "title": "top-note",
      "href": "old/vlix",
      "type": "markdown",
      "isExternal": false,
      "rels": [],
      "snippet": "Original note: [top-note](vlix)",
      "snippetStart": 18,
      "snippetEnd": 49,
      "sourceId": 3,
      "sourcePath": "old/jbxt.md",
      "targetId": 4,
      "targetPath": "old/vlix.md"
    },
    {
      "title": "ref-note",
      "href": "old/jbxt",
      "type": "markdown",
      "isExternal": false,
      "rels": [],
      "snippet": "I reference another note: [ref-note](jbxt)",
      "snippetStart": 18,
      "snippetEnd": 60,
      "sourceId": 4,
      "sourcePath": "old/vlix.md",
      "targetId": 3,
      "targetPath": "old/jbxt.md"
    }
  ]
}

my environment

zk 0.11.0 cloned from master. Language server client: vim-lsp. Everything works fine, if the notes are in the root folder of a zettelkasten.

@mickael-menu
Copy link
Member

@bibor Thanks for spotting that, it should be fixed in main. Let me know if you see regressions as the LSP server doesn't have automated tests yet.

@bibor
Copy link
Contributor Author

bibor commented Jul 14, 2022

Thank you very much!
Unfortunatley the fix introduces a new bug, resulting in the go-to-reference feature still not working.

notebook.RelPath() is called on a relative path from the root, but it expands the path relative to the note. This causes a new, wrong relative path, because it is calculated from the note's paths.

for example an input of folder/note produces folder/folder/note.

I think it's possible to just remove the second call to RelPath(), but I'm not 100% sure, that this does not produce any unwanted side-effects. However, everything was working fine, when I tested it. I'll open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants