zk-org / zk-nvim

Neovim extension for zk
https://github.com/zk-org/zk
GNU General Public License v3.0
502 stars 40 forks source link

Error executing vim.schedule Cannont insert link for `:ZkNewFromTitleSelection` `:ZkNewFromContentSelection` #104

Closed mr-majkel closed 1 year ago

mr-majkel commented 1 year ago

Hi,

first of all thanks for the great tool that is zk and the neovim plugin! I am one of the poor users who are commited (forced?) to using zk on Windows. This issue is occurring for both Windows 10 and WSL with Ubuntu.

No matter if I use zk on native Windows or in WSL, I seem not to be able to use either of the linking commands coming with the plugin. However :ZkNew works, so the problem seems to be connected with inserting the link to the document. This is the error I'm getting (this one is from WSL run, but it differs from the Windows one only by how the path is formatted):

Error executing vim.schedule lua callback: ...cal/share/nvim/site/pack/packer/start/zk-nvim/lua/zk.lua:68: RPC[Error] code_name = InvalidRequest, message = "Cannot insert link in 'file:///mnt/c/Users/modzmi01/zk_notebook/index.md'"
stack traceback:
        [C]: in function 'assert'
        ...cal/share/nvim/site/pack/packer/start/zk-nvim/lua/zk.lua:68: in function 'handler'
        ...l/.local/nvim-linux64/share/nvim/runtime/lua/vim/lsp.lua:1383: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

I'm using nvim 0.8.3.

I'm configuring and attaching zk lsp through lspconfig, so I have turned off auto attach in the setup. Here are the bits of my config related to zk:

```lua -- plugin config require("zk").setup({ -- can be "telescope", "fzf" or "select" (`vim.ui.select`) -- it's recommended to use "telescope" or "fzf" picker = "telescope", lsp = { -- `config` is passed to `vim.lsp.start_client(config)` config = { cmd = { "zk", "lsp" }, name = "zk", -- on_attach = ... -- etc, see `:h vim.lsp.start_client()` }, -- automatically attach buffers in a zk notebook that match the given filetypes auto_attach = { enabled = false, filetypes = { "markdown" }, }, }, }) ``` ```lua --lsp setup local zk_on_attach = function(client, bufnr) local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') -- Mappings. local opts = { noremap=true, silent=true } buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) local opts = { noremap=true, silent=false } -- Open the link under the caret. buf_set_keymap("n", "", "lua vim.lsp.buf.definition()", opts) -- Create a new note after asking for its title. -- This overrides the global `zn` mapping to create the note in the same directory as the current buffer. buf_set_keymap("n", "zn", "ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }", opts) -- Create a new note in the same directory as the current buffer, using the current selection for title. buf_set_keymap("v", "znt", ":'<,'>ZkNewFromTitleSelection { dir = vim.fn.expand('%:p:h') }", opts) -- Create a new note in the same directory as the current buffer, using the current selection for note content and asking for its title. buf_set_keymap("v", "znc", ":'<,'>ZkNewFromContentSelection { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }", opts) buf_set_keymap("n", "zj", "ZkNew { dir = 'journal/daily', title = vim.fn.input('Title: ')}", opts) -- Open notes linking to the current buffer. buf_set_keymap("n", "zb", "ZkBacklinks", opts) -- Alternative for backlinks using pure LSP and showing the source context. --map('n', 'zb', 'lua vim.lsp.buf.references()', opts) -- Open notes linked by the current buffer. buf_set_keymap("n", "zl", "ZkLinks", opts) -- Open the code actions for a visual selection. buf_set_keymap("v", "za", ":'<,'>lua vim.lsp.buf.range_code_action()", opts) end nvim_lsp["zk"].setup({capabilities = capabilities, on_attach = zk_on_attach, handlers = handlers}) ```
mickael-menu commented 1 year ago

Fixed in https://github.com/mickael-menu/zk-nvim/pull/105, thanks!