Myzel394 / jsonfly.nvim

❴🦋❵ Fly through your JSON / XML / YAML files with ease. Search ✨ blazingly fast ✨ for keys via Telescope.
125 stars 2 forks source link

Error: attempt to index a nil value #15

Closed Integralist closed 1 week ago

Integralist commented 1 week ago

👋🏻 I stumbled into this error...

Error executing vim.schedule lua callback: .../lazy/jsonfly.nvim/lua/telescope/_extensions/jsonfly.lua:209: attempt to index a nil value
stack traceback:
        .../lazy/jsonfly.nvim/lua/telescope/_extensions/jsonfly.lua:209: in function 'handler'
        .../Cellar/neovim/0.10.0/share/nvim/runtime/lua/vim/lsp.lua:923: in function 'handler'
        .../neovim/0.10.0/share/nvim/runtime/lua/vim/lsp/client.lua:685: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

From what I can tell if I open nvim with the following file and trigger the :Telescope jsonfly then I'll see the above error:

{
  "foo": true,
  "bar": 0,
  "baz": "example",
  "qux": [
    "a"
  ],
  "qiz": [],
  "ziz": {}
}

The problem at first looked to be the last two fields qiz and ziz.

But even if I remove those fields and restart nvim, then the error will persist.

Interestingly, it's the qux field that's the problem, even though it has a value in its array: ["a"]?

The following will parse fine...

{
  "foo": true,
  "bar": 0,
  "baz": "example",
  "qiz": [],
  "ziz": {}
}
Myzel394 commented 1 week ago

There seems to be some issue with the LSP you're using. As a temporary workaround you can force jsonfly to use the lua json parser using:

telescope.setup({
    extensions = {
        jsonfly = {
            backend = "lua",
        },
    },
}

What LSP do you use? You can find this out by entering the command: :LspInfo

Integralist commented 1 week ago

Weeeell, shoot.

I just went to run :LspInfo to find out for you (details below anyway) and I noticed there's no more error (WAT!? 😅)

Screenshot 2024-06-19 at 07 16 30
 Press q or <Esc> to close this window. Press <Tab> to view server doc.

 Language client log: /Users/integralist/.local/state/nvim/lsp.log
 Detected filetype:   json

 2 client(s) attached to this buffer: 

 Client: jsonls (id: 1, bufnr: [1])
    filetypes:       json, jsonc
    autostart:       true
    root directory:  Running in single file mode.
    cmd:             /Users/integralist/.local/share/nvim/mason/bin/vscode-json-language-server --stdio

 Client: spectral (id: 2, bufnr: [1])
    filetypes:       yaml, json, yml
    autostart:       true
    root directory:  Running in single file mode.
    cmd:             /Users/integralist/.local/share/nvim/mason/bin/spectral-language-server --stdio

 Configured servers list: phpactor, perlnavigator, eslint, rubocop, gopls, terraformls, solargraph, cmake, bashls, jsonls, lua_ls, marksman, pylsp, tsserver, zls, taplo, spectral, yamlls, tflint

If the error comes back I'll try your suggestion for forcing a particular lsp 👍🏻

Thanks for looking into this. I'll close this issue for now 🙇🏻