Closed mimre25 closed 2 months ago
I'd be more than happy to contribute with a PR if that's desired.
Yeah feel free to do so! If it's too hard / you don't got the time to do that, please let me know, then I'll take this over :)
Unfortunately, jsonfly doesn't work on unnamed buffers,
How do you create unnamed buffers? I think someone else already tried to do that, but I was unable to reproduce it.
because I often have to investigate ad-hoc json object
you might find jq interesting :D
Yeah feel free to do so! If it's too hard / you don't got the time to do that, please let me know, then I'll take this over :)
Will do :slightly_smiling_face:
How do you create unnamed buffers? I think someone else already tried to do that, but I was unable to reproduce it.
Either of those three ways:
:tabe
:new
you might find jq interesting :D
I'm also using that :sweat_smile: , but at times it's just much cleaner when you can actively navigate (with visual feedback) and not just query for keys.
So it turns out the problem is that the unnamed buffers don't have the filetype json
and thus no lsp attached.
This leads to https://github.com/Myzel394/jsonfly.nvim/blob/allow-jsonfly-on-unnamed-buffers/lua/telescope/_extensions/jsonfly.lua?plain=1#L149-L162 not working.
I've created a PR #7, that fixes the issue, however, I'm not quite satisfied with the solution:
json
and wait for an LSP to attach. However, this is my personal choice, so I'm not sure if this is desired for the project or not. If it is, then we can do that and wait for the LSP to be ready before running any vim.lsp.*
commands.What do you think?
I think we've got a fundamental problem here.
When working with unnamed buffers, Neovim seems to not contain any "useful" functionality. LSP is not attaching, Treesitter isn't working, even my keymaps weren't working correctly. If that's really the case and I'm not missing something, I think it's better for jsonfly not to add support for unnamed buffers. Since probably all other plugins don't have proper support, people don't expect any support there either.
It doesn't show a live preview, probably because no LSP is attached - I haven't had time to look into that yet
I can take a look at that, but I will not spend too much time on it
When working with unnamed buffers, Neovim seems to not contain any "useful" functionality. LSP is not attaching, Treesitter isn't working, even my keymaps weren't working correctly. If that's really the case and I'm not missing something, I think it's better for jsonfly not to add support for unnamed buffers. Since probably all other plugins don't have proper support, people don't expect any support there either.
That's what I thought as well, and hence I did not start implementing it.
I'll work on a setup for myself and can share it here later in case others want the same functionality :slightly_smiling_face:
For anybody stumbling upon this, here is my solution:
vim.keymap.set("n", "<leader>j", function()
if vim.bo.filetype == '' then
vim.bo.filetype = 'json'
lsp.new_client({
filetypes = 'json',
on_attach = vim.cmd('Telescope jsonfly')
})
else
vim.cmd('Telescope jsonfly')
end
end)
It's important to call Telescope jsonfly
only on_attach
, otherwise the call runs into the problem of no attached LSP described above.
This still, as of now, doesn't give a life preview, but everything else works perfectly fine.
All right, thanks for sharing your config! I'll close this since we agreed on not implementing it.
This still, as of now, doesn't give a life preview, but everything else works perfectly fine.
I think the reason it's not giving a file preview is because (with the current setup) we give telescope a file - and since there is no file, it can't find the code
I really like jsonfly - in fact I was building something similar myself because I often have to investigate ad-hoc json objects.
Unfortunately, jsonfly doesn't work on unnamed buffers, which are usually part of my workflow:
I briefly looked through the code and I think there isn't too much that would need to change for this to be possible. I'd be more than happy to contribute with a PR if that's desired.