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

Use handlers instead of callbacks #399

Merged
merged 9 commits into from
Nov 16, 2020
Merged

Use handlers instead of callbacks #399

merged 9 commits into from
Nov 16, 2020

Conversation

Iron-E
Copy link
Contributor

@Iron-E Iron-E commented Nov 13, 2020

The recent changes in Neovim head cause loading this file to create an error. These changes have resolved that on my machine.

Note: neovim/neovim#12655

@lithammer
Copy link
Collaborator

I suspect you have to fix the obsolete callbacks references in lua/nvim_lsp/util.lua and lua/nvim_lsp/configs.lua as well...? It might work without obvious errors, but I have a feeling some functionality is just going into a void since they're never called anymore.

@Iron-E
Copy link
Contributor Author

Iron-E commented Nov 13, 2020

You're right! I missed those. Gonna change them and commit.

@Iron-E
Copy link
Contributor Author

Iron-E commented Nov 13, 2020

Changed the rest of them.

@teto
Copy link
Member

teto commented Nov 14, 2020

@tjdevries

assert(lsp.callbacks, "Update to Nvim HEAD. This is an incompatible interface.")
assert(lsp.callbacks["window/logMessage"], "Callback for window/logMessage notification is not defined")
lsp.callbacks["window/logMessage"](err, method, params, client_id)
assert(lsp.handlers, "Update to Nvim HEAD. This is an incompatible interface.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should assert(not lsp.callbacks, ... with an informative message and a help section to look at .

Once we do that, we can merge. ("Update to Nvim HEAD" doesn't tell people what / how they need to fix anything)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the most recent commit address this well?

assert(lsp.callbacks, "Update to Nvim HEAD. This is an incompatible interface.")
assert(lsp.callbacks["window/logMessage"], "Callback for window/logMessage notification is not defined")
lsp.callbacks["window/logMessage"](err, method, params, client_id)
assert(not lsp.callbacks, "lsp.callbacks has been deprecated. See here for more: https://github.com/nvim-lua/diagnostic-nvim/issues/73")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be moved out of the inner function. This should be on line 36 I think (where we add the handlers).

We don't need to check this every time.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it should reference this PR: neovim/neovim#12655 Which is the one with the most information and most context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the line out, although now every time I initiate an LSP it causes an error. The repo doesn't have any more mentions of callbacks, so is this working right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe what we should do is check this each time a new config is registered (to make sure no deprecated settings are being added).

I'll look into that more tonight, since it looks like callbacks is getting populated still somehow.

local function add_callbacks(config)
config.callbacks["window/logMessage"] = function(err, method, params, client_id)
local function add_handlers(config)
assert(not lsp.callbacks, "lsp.callbacks has been deprecated. See here for more: https://github.com/neovim/neovim/pull/12655")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, we should also chdck that config.callbacks is nil.

Sorry to be so pedantic about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's no problem! We want to make sure it's right before it goes someplace people use it everyday.

I'll add it in a little bit and push, just leaving this here to say I've seen it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, ping me on Monday if I haven't looked again. Idk what my schedule is tomorrow.

@@ -34,7 +34,7 @@ function configs.__newindex(t, config_name, config_def)
-- which is why this is a function, so that it can refer to the settings
-- object on the server.
local function add_handlers(config)
assert(not lsp.callbacks, "lsp.callbacks has been deprecated. See here for more: https://github.com/neovim/neovim/pull/12655")
assert(not config.callbacks, "lsp.callbacks has been deprecated. See here for more: https://github.com/neovim/neovim/pull/12655")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested JDT LS using the provided config on master and the proposed config in this pull. Using this assert it fails on master and works for patch-1 😌

As for lsp.callbacks, I tried the following:

nvim -u NORC -c 'lua assert(not vim.lsp.callbacks, "Failed!")'

and it failed. So I replaced the lsp reference with config.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yeah, that's what I mean to say. I wanted you to assert about the config (which is the thing the user can control).

assert(lsp.callbacks and lsp.callbacks[method], "Update to Nvim HEAD. This is an incompatible interface.")
assert(lsp.callbacks["window/showMessage"], "Callback for window/showMessage notification is not defined")
lsp.callbacks["window/showMessage"](err, method, params, client_id)
assert(lsp.handlers and lsp.handlers[method], "Update to Nvim HEAD. This is an incompatible interface.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think is needed anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. If we're aiming to assert on addition, we don't need to ship back a function which makes assertions about that again.

@h-michael
Copy link
Contributor

@Iron-E Sorry I've merged this PR. Could you rebase?
#348

@Iron-E
Copy link
Contributor Author

Iron-E commented Nov 15, 2020

No problem. Good time to get that one through

Copy link
Contributor

@h-michael h-michael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjdevries Is there anything else?

@tjdevries
Copy link

LGTM I think

@h-michael h-michael merged commit 35b0064 into neovim:master Nov 16, 2020
@h-michael
Copy link
Contributor

@Iron-E Thank you for your work :)

@Iron-E
Copy link
Contributor Author

Iron-E commented Nov 16, 2020

Happy we could do it!

@Iron-E Iron-E deleted the patch-1 branch November 16, 2020 15:49
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

Successfully merging this pull request may close these issues.

6 participants