R-nvim / R.nvim

Neovim plugin to edit R files
GNU General Public License v3.0
155 stars 16 forks source link

Is `after_R_start()` broken in `hook`? #103

Closed wurli closed 6 months ago

wurli commented 6 months ago

When I attempt to set this in any way I get an error:

Client 1 quit with exit code 1 and signal 0

The rest of the package works fine after this, but nothing I put in after_R_start() gets run. This happens with even the basic configuration example from the docs:

hook = {
    after_config = function() vim.notify("R.nvim is configured") end,
    after_R_start = function() vim.notify("R was launched") end,
    after_ob_open = nil,
},
jalvesaq commented 6 months ago

With nvim-notify installed, I get this:

2024-03-30T16:11:32  INFO R.nvim is configured
2024-03-30T16:11:32  INFO R.nvim is configured
2024-03-30T16:11:43  INFO R was launched

The only strange thing is that after_config was run twice.

Could you discover what client exited with status 1?

wurli commented 6 months ago

Hm - it looks like my Client 1 quit message was because I was still manually setting up the R language server from before I started using R.nvim:

local lspconfig = require("lspconfig")
local capabilities = require("cmp_nvim_lsp").default_capabilities()
lspconfig.r_language_server.setup({ capabilities = capabilities })

I've now removed this and it seems to have removed the warning - so thankfully not an issue with R.nvim! Unfortunately, getting rid of this warning hasn't solved my real problem - I'm still unable to get after_R_start() to run, using nvim-notify or otherwise 🙁

jalvesaq commented 6 months ago

Sometimes, messages echoed during window splitting aren't visible. So, you could follow a different approach to test the hook:

                hook = {
                    after_config = function() vim.notify("R.nvim is configured") end,
                    after_R_start = function() vim.g.HookTest = true end,
                    after_ob_open = nil,
                },

Then, after starting R, do :echo HookTest.

jalvesaq commented 6 months ago

The hook functions now run within vim.schedule() calls and should be more reliable.

wurli commented 6 months ago

Thank you! I was trying to track down the cause of some lingering weirdness, but my problems seem to have been solved by the change. Many thanks!

jalvesaq commented 6 months ago

I was trying to track down the cause of some lingering weirdness

Lua is less disruptive of editing tasks than VimScript. I guess that because Neovim was busy splitting the window and opening the terminal, it ignored the vim.notify() command. This might be a bug in Neovim because even if the message was not immediately displayed, it should be stored and then displayed with :messages.