zk-org / zk-nvim

Neovim extension for zk
https://github.com/zk-org/zk
GNU General Public License v3.0
503 stars 40 forks source link

`vim.lsp.get_active_clients()` is Deprecated #165

Closed prikhi closed 2 months ago

prikhi commented 3 months ago

With neovim nightly & the latest version of zk-nvim, I get the following warning when opening up a zk file:

vim.lsp.get_active_clients() is deprecated, use vim.lsp.get_clients() instead. :help deprecated
Feature will be removed in Nvim 0.12
stack traceback:
        /usr/share/nvim/runtime/lua/vim/lsp.lua:785: in function 'get_active_clients'
        /home/prikhi/.vim/plugged/zk-nvim/lua/zk/lsp.lua:14: in function 'external_client'
        /home/prikhi/.vim/plugged/zk-nvim/lua/zk/lsp.lua:31: in function 'start'
        /home/prikhi/.vim/plugged/zk-nvim/lua/zk/lsp.lua:43: in function 'buf_add'
        /home/prikhi/.vim/plugged/zk-nvim/lua/zk.lua:34: in function '_lsp_buf_auto_add'
        /home/prikhi/.vim/plugged/zk-nvim/lua/zk.lua:18: in function 'setup_lsp_auto_attach'
        /home/prikhi/.vim/plugged/zk-nvim/lua/zk.lua:44: in function 'setup'
        [string ":lua"]:1: in main chunk

It seems like get_clients is just a simple renaming as the docs say it returns active clients?

get_clients({filter})                                  *vim.lsp.get_clients()*
    Get active clients.

    Parameters: ~
      • {filter}  (`table?`) Key-value pairs used to filter the returned
                  clients.
                  • {id}? (`integer`) Only return clients with the given id
                  • {bufnr}? (`integer`) Only return clients attached to this
                    buffer
                  • {name}? (`string`) Only return clients with the given name
                  • {method}? (`string`) Only return clients supporting the
                    given method

    Return: ~
        (`vim.lsp.Client[]`) List of |vim.lsp.Client| objects
tjex commented 3 months ago

Nice one, thanks for taking the moment to lodge the issue and for posting the updated API. That makes it much easier:

This is the v0.9 api

get_active_clients({filter})                    *vim.lsp.get_active_clients()*
    Get active clients.

    Parameters:  
      • {filter}  (table|nil) A table with key-value pairs used to filter the
                  returned clients. The available keys are:
                  • id (number): Only return clients with the given id
                  • bufnr (number): Only return clients attached to this
                    buffer
                  • name (string): Only return clients with the given name

    Return:  
        (table) List of |vim.lsp.client| objects

So, while not a direct name change only, should be seemingly straight forward 👍

tjex commented 3 months ago

Looks like we're only filtering by name, which is still supported in the updated api.

lua/zk/lsp.lua:

local active_clients = vim.lsp.get_active_clients({ name = client_name })
tjex commented 3 months ago

@kabouzeid would this be the occasion to start making releases for zk-nvim, in order to support api changes? Or what was the approach before I came on board for this situation?

Tags? Or do we just support the latest build of neovim?

willruggiano commented 3 months ago

local active_clients = (vim.lsp.get_clients or vim.lsp.get_active_clients)({ name = client_name })

willruggiano commented 3 months ago

or vim.fn.has("nvim-0.10")

tjex commented 2 months ago

the if check isn't working somehow. As reported in #170 Reopening to check this out again. Although the latest commits will work anyway for v0.10.* users

tjex commented 2 months ago

fixed with https://github.com/zk-org/zk-nvim/commit/b3b40469286d3dd7071d2b68703abd5287a47e39