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

api.lua - attempt to index a nil value #188

Open
2 tasks done
njnygaard opened this issue Sep 13, 2024 · 3 comments
Open
2 tasks done

api.lua - attempt to index a nil value #188

njnygaard opened this issue Sep 13, 2024 · 3 comments

Comments

@njnygaard
Copy link
Contributor

Check if applicable

  • I have searched the existing issues (required)
  • I'm willing to help fix the problem and contribute a pull request

Describe the bug

I'm not really sure how to reliably reproduce this.
If I leave an nvim session over night, I will notice this pretty reliably.
Restarting nvim will fix the issue.

E5108: Error executing lua: .../njnygaard/.local/share/nvim/lazy/zk-nvim/lua/zk/api.lua:19: attempt to index a nil value
stack traceback:
        .../njnygaard/.local/share/nvim/lazy/zk-nvim/lua/zk/api.lua:19: in function 'execute_command'
        .../njnygaard/.local/share/nvim/lazy/zk-nvim/lua/zk/api.lua:61: in function 'list'
        /Users/njnygaard/.local/share/nvim/lazy/zk-nvim/lua/zk.lua:103: in function 'pick_notes'
        /Users/njnygaard/.local/share/nvim/lazy/zk-nvim/lua/zk.lua:131: in function 'edit'
        ...ocal/share/nvim/lazy/zk-nvim/lua/zk/commands/builtin.lua:61: in function <...ocal/share/nvim/lazy/zk-nvim/lua/zk/commands/builtin.lua:60>
        ...d/development/dot-files/.config/nvim/after/plugin/zk.lua:44: in function <...d/development/dot-files/.config/nvim/after/plugin/zk.lua:43>

How to reproduce?

  1. Leave a note open for 24h
  2. :ZkNotes
  3. Get error.

zk configuration

[notebook]

[note]
language = "en"
default-title = "Untitled"
filename = "{{slug title}}"
extension = "md"
template = "default.md"
id-charset = "alphanum"
id-length = 6
id-case = "lower"

[group.journal]
paths = ["journal"]

[group.journal.note]
filename = "{{format-date now}}"
extension = "md"
template = "journal.md"

[format.markdown]
hashtags = false
colon-tags = false
multiword-tags = false

[tool]
editor = "nvim"
shell = "/bin/zsh"
pager = "less -FIRX"
fzf-preview = "bat -p --color always {-1}"

[filter]
recents = "--sort created- --created-after 'last two weeks'"

[alias]

# Edit the last modified note.
#edlast = "zk edit --limit 1 --sort modified- $@"

# Edit the notes selected interactively among the notes created the last two weeks.
#recent = "zk edit --sort created- --created-after 'last two weeks' --interactive"

# Show a random note.
#lucky = "zk list --quiet --format full --sort random --limit 1"

[lsp]

[lsp.diagnostics]
# Report titles of wiki-links as hints.
wiki-title = "hint"
# Warn for dead links between notes.
dead-link = "error"

[lsp.completion]
# Show the note title in the completion pop-up, or fallback on its path if empty.
note-label = "{{title}}"
# Filter out the completion pop-up using the note title or its path.
note-filter-text = "{{title}}"
# Show the note filename without extension as detail.
note-detail = "{{title}}"
use-additional-text-edits = true

Neovim configuration

There's a lot in there and multiple files.
I'm not sure what to post.
Here's the zk-nvim specific file (telescope):


require("zk").setup({
  -- Can be "telescope", "fzf", "fzf_lua" or "select" (`vim.ui.select`).
  -- It's recommended to use "telescope", "fzf" or "fzf_lua".
  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 = true,
      filetypes = { "markdown" },
    },
  },
})

-- Create a new note after asking for its title.
vim.keymap.set("n", "<leader>zn", function()
  local title = vim.fn.input("Title: ")

  require("zk.commands").get("ZkNew")(
    {
      dir = "unsorted",
      title = title,
    })
end)

-- Open notes associated with the selected tags.
vim.keymap.set("n", "<leader>zt", function()
  require("zk.commands").get("ZkTags")(
    {
      sort = "modified",
    })
end)

-- Open notes, recently modified first.
vim.keymap.set("n", "<leader>zo", function()
  require("zk.commands").get("ZkNotes")({
      sort = { "modified" },
    })
end)


### Environment

```bash
zk 0.14.1
uname: illegal option -- o
usage: uname [-amnprsv]
system:
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713773202
Run "nvim -V1 -v" for more info
@njnygaard
Copy link
Contributor Author

Honestly, I don't see how this class of error could be caused by zk-nvim but any experiences or ideas would be useful in debugging.

@tjex
Copy link
Member

tjex commented Sep 14, 2024

I've also experienced this. And also don't know how to recreate it consistently 😮‍💨

By feel, it's an issue with the lsp and I think it happens when the line numbers in the document change, but the lsp doesn't get that update.

I say "by feel", because it almost seems similar to a bug I encountered with formatter.nvim, where this was the case.

@tjex tjex changed the title ZkNotes Throwing an Error Intermittently api.lua - attempt to index a nil value Sep 14, 2024
@blastmaster
Copy link

I also see this issue, not necessarily after a day but after some time.

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

No branches or pull requests

3 participants