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

lsp: Add more configuration for handlers #13977

Closed
wants to merge 1 commit into from

Conversation

tjdevries
Copy link
Contributor

If someone wants to take this over, this is pretty similar to the concept that we were going for in #12966

This will allow you to more easily manage / re-use internal logic for doing location handling, without having to copy and paste.

vim.lsp.handlers["textDocument/definition"] = vim.lsp.with(
  vim.lsp.handlers.location, {
    location_callback = function(location)
      vim.cmd [[vsplit]]
      vim.lsp.util.jump_to_location(location)
    end
  }
)

@neovim-discourse
Copy link

This pull request has been mentioned on Neovim Discourse. There might be relevant details there:

https://neovim.discourse.group/t/how-to-customize-lsp-actions/349/5

@jlesquembre
Copy link
Contributor

Found this issue while trying to configure the jump-to-definition handler. With this approach, I guess that if we want to have multiple mappings (e.g.: open definition in split and vsplit), it would look something like this:

function open_definition_vsplit ()
  local handler = vim.lsp.with(
    vim.lsp.handlers.location, {
      location_callback = function(location)
        vim.cmd [[vsplit]]
        vim.lsp.util.jump_to_location(location)
      end
    }

  local params = vim.lsp.util.make_position_params()
  vim.lsp.buf_request(0, 'textDocument/definition', params, handler)
end

vim.api.nvim_set_keymap("n", "gdv", "<cmd>lua open_definition_vsplit()<cr>", opts)

@mjlbach
Copy link
Contributor

mjlbach commented May 15, 2021

@tjdevries What needs to get done for this to get merged? I'll take it over.

@tjdevries
Copy link
Contributor Author

Probably just add a test and fix conflicts?

@mjlbach
Copy link
Contributor

mjlbach commented Oct 31, 2021

This is pretty out of date, closing as we've changed a lot of this code now.

@mjlbach mjlbach closed this Oct 31, 2021
@mmoya
Copy link

mmoya commented Dec 12, 2022

Found this issue while trying to configure the jump-to-definition handler. With this approach, I guess that if we want to have multiple mappings (e.g.: open definition in split and vsplit), it would look something like this:
...

@jlesquembre do you have by any chance a 2022 version of your snippet?

@justinmk
Copy link
Member

justinmk commented Dec 13, 2022

I am looking at reviving some form of this. #22598

justinmk added a commit to justinmk/neovim that referenced this pull request Mar 10, 2023
Problem:
No easy way to hook into LSP request/response handlers. (No mention of
"before" or "after" in `:help lsp`...)

Solution:
Introduce `vim.on_before()`.

Example:

    vim.on_before(vim.lsp.handlers, 'textDocument/definition', function()
      vim.notify('before, yay')
    end)

Fixes neovim#20568
Fixes neovim#22075
Fixes neovim#22323
Related: neovim#13977
justinmk added a commit to justinmk/neovim that referenced this pull request Mar 10, 2023
Problem:
No easy way to hook into LSP request/response handlers. (No mention of
"before" or "after" in `:help lsp`...)

Solution:
Introduce `vim.on_before()`.

Example:

    vim.on_before(vim.lsp.handlers, 'textDocument/definition', function()
      vim.notify('before, yay')
    end)

Fixes neovim#20568
Fixes neovim#22075
Fixes neovim#22323
Related: neovim#13977
justinmk added a commit to justinmk/neovim that referenced this pull request Mar 11, 2023
Problem:
No easy way to hook into LSP request/response handlers. (No mention of
"before" or "after" in `:help lsp`...)

Solution:
Introduce vim.on_fun(), a generic way to "hook into" any function
before/after it is called.

Example:

    vim.on_fun(vim.lsp.handlers, 'textDocument/definition', function()
      vim.print('before, yay')
    end)

Fixes neovim#20568
Fixes neovim#22075
Fixes neovim#22323
Related: neovim#13977
justinmk added a commit to justinmk/neovim that referenced this pull request Mar 11, 2023
Problem:
No easy way to hook into LSP request/response handlers. (No mention of
"before" or "after" in `:help lsp`...)

Solution:
Introduce vim.on_fun(), a generic way to "hook into" any function
before/after it is called.

Example:

    vim.on_fun(vim.lsp.handlers, 'textDocument/definition', function()
      vim.print('before, yay')
    end)

Fixes neovim#20568
Fixes neovim#22075
Fixes neovim#22323
Related: neovim#13977
justinmk added a commit to justinmk/neovim that referenced this pull request Mar 11, 2023
Problem:
No easy way to hook into LSP request/response handlers. (No mention of
"before" or "after" in `:help lsp`...)

Solution:
Introduce vim.on_fun(), a generic way to "hook into" any function
before/after it is called.

Example:

    vim.on_fun(vim.lsp.handlers, 'textDocument/definition', function()
      vim.print('before, yay')
    end)

Fixes neovim#20568
Fixes neovim#22075
Fixes neovim#22323
Related: neovim#13977
justinmk added a commit to justinmk/neovim that referenced this pull request Mar 11, 2023
Problem:
No easy way to hook into LSP request/response handlers. (No mention of
"before" or "after" in `:help lsp`...)

Solution:
Introduce vim.on_fun(), a generic way to "hook into" any function
before/after it is called.

Example:

    vim.on_fun(vim.lsp.handlers, 'textDocument/definition', function()
      vim.print('before, yay')
    end)

Fixes neovim#20568
Fixes neovim#22075
Fixes neovim#22323
Related: neovim#13977
justinmk added a commit to justinmk/neovim that referenced this pull request Mar 12, 2023
Problem:
No easy way to hook into LSP request/response handlers. (No mention of
"before" or "after" in `:help lsp`...)

Solution:
Introduce vim.on_fun(), a generic way to "hook into" any function
before/after it is called.

Example:

    vim.on_fun(vim.lsp.handlers, 'textDocument/definition', function()
      vim.print('before, yay')
    end)

Fixes neovim#20568
Fixes neovim#22075
Fixes neovim#22323
Related: neovim#13977
justinmk added a commit to justinmk/neovim that referenced this pull request Mar 12, 2023
Problem:
No easy way to hook into LSP request/response handlers. (No mention of
"before" or "after" in `:help lsp`...)

Solution:
Introduce vim.on_fun(), a generic way to "hook into" any function
before/after it is called.

Example:

    vim.on_fun(vim.lsp.handlers, 'textDocument/definition', function()
      vim.print('before, yay')
    end)

Fixes neovim#20568
Fixes neovim#22075
Fixes neovim#22323
Related: neovim#13977
justinmk added a commit to justinmk/neovim that referenced this pull request Mar 13, 2023
Problem:
No easy way to hook into LSP request/response handlers. (No mention of
"before" or "after" in `:help lsp`...)

Solution:
Introduce vim.on_fun(), a generic way to "hook into" any function
before/after it is called.

Example:

    vim.on_fun(vim.lsp.handlers, 'textDocument/definition', function()
      vim.print('before, yay')
    end)

Fixes neovim#20568
Fixes neovim#22075
Fixes neovim#22323
Related: neovim#13977
justinmk added a commit to justinmk/neovim that referenced this pull request Mar 15, 2023
Problem:
No easy way to hook into LSP request/response handlers. (No mention of
"before" or "after" in `:help lsp`...)

Solution:
Introduce vim.on_fun(), a generic way to "hook into" any function
before/after it is called.

Example:

    vim.on_fun(vim.lsp.handlers, 'textDocument/definition', function()
      vim.print('before, yay')
    end)

Fixes neovim#20568
Fixes neovim#22075
Fixes neovim#22323
Related: neovim#13977
justinmk added a commit to justinmk/neovim that referenced this pull request Mar 15, 2023
Problem:
No easy way to hook into LSP request/response handlers. (No mention of
"before" or "after" in `:help lsp`...)

Solution:
Introduce vim.on_fun(), a generic way to "hook into" any function
before/after it is called.

Example:

    vim.on_fun(vim.lsp.handlers, 'textDocument/definition', function()
      vim.print('before, yay')
    end)

Fixes neovim#20568
Fixes neovim#22075
Fixes neovim#22323
Related: neovim#13977
justinmk added a commit to justinmk/neovim that referenced this pull request Mar 20, 2023
Problem:
No easy way to hook into LSP request/response handlers. (No mention of
"before" or "after" in `:help lsp`...)

Solution:
Introduce vim.on_fun(), a generic way to "hook into" any function
before/after it is called.

Example:

    vim.on_fun(vim.lsp.handlers, 'textDocument/definition', function()
      vim.print('before, yay')
    end)

Fixes neovim#20568
Fixes neovim#22075
Fixes neovim#22323
Related: neovim#13977
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants