Skip to content

Feature: migrate builtin commands #3734

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

TheRealLorenz
Copy link
Contributor

@TheRealLorenz TheRealLorenz commented Apr 16, 2025

See #3714
CC @justinmk

Things to note:

  • LspStart starts the selected LSP and attaches to every buffer which has the right filetype. Should I only attach it to the current buffer?

  • LspStop stops the selected LSP.

  • LspRestart restart the selected LSPs, but I don't get how and why it used a timer.

  • Should we add LspEnable? Maybe in a future PR.

EDIT:

Should I add checks for neovim 0.11?

Something like:

  if not has_eleven then
    error('nvim-lspconfig 2.x only supports vim.lsp.config. If you dont want to migrate, pin to nvim-lspconfig 1.x')
  end

@seblyng
Copy link
Contributor

seblyng commented Apr 18, 2025

I don't think LspStart and LspRestart will work when root_dir is a function with this. I think you must do something like this:

if type(config.root_dir) == 'function' then
  ---@param root_dir string
  config.root_dir(bufnr, function(root_dir)
    config.root_dir = root_dir
    vim.schedule(function()
      vim.lsp.start(config, {
        bufnr = bufnr,
        reuse_client = config.reuse_client,
        _root_markers = config.root_markers,
      })
    end)
  end)
else
  vim.lsp.start(config, {
    bufnr = bufnr,
    reuse_client = config.reuse_client,
    _root_markers = config.root_markers,
  })
end

Inspiration taken from neovim source code, in lsp_enable_callback function in vim/lsp.lua

@TheRealLorenz
Copy link
Contributor Author

I don't think LspStart and LspRestart will work when root_dir is a function with this. I think you must do something like this:

if type(config.root_dir) == 'function' then
  ---@param root_dir string
  config.root_dir(bufnr, function(root_dir)
    config.root_dir = root_dir
    vim.schedule(function()
      vim.lsp.start(config, {
        bufnr = bufnr,
        reuse_client = config.reuse_client,
        _root_markers = config.root_markers,
      })
    end)
  end)
else
  vim.lsp.start(config, {
    bufnr = bufnr,
    reuse_client = config.reuse_client,
    _root_markers = config.root_markers,
  })
end

Inspiration taken from neovim source code, in lsp_enable_callback function in vim/lsp.lua

Thank you, I totally missed that. The vim.lsp API is a little but cumbersome as for now.

@TheRealLorenz
Copy link
Contributor Author

Opened a PR at neovim/neovim#33578 to make :LspStart less ugly.

})

api.nvim_create_user_command('LspStop', function(info)
vim.api.nvim_create_user_command('LspStop', function(info)
Copy link
Member

@justinmk justinmk Apr 23, 2025

Choose a reason for hiding this comment

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

Nvim 0.11+, LspStop can do this, to "disable" the configs :

vim.lsp.enable(..., false)

Requested in #2216

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll add it. Should I re-enable the config in LspStart?

@TheRealLorenz
Copy link
Contributor Author

TheRealLorenz commented Apr 23, 2025

@justinmk On further thinking, probably these commands do not suit vim.lsp quite well (at least semantically).

We could use LspEnable (with optional ++now), LspDisable, LspStart and LspStop "systemctl-like"

EDIT: or we could have enable + start as LspStart and disable + stop as LspStop

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.

3 participants