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

feat: allow list of client ids or config names in LspRestart and LspStop #3438

Merged
merged 2 commits into from
Nov 17, 2024

Conversation

guilhas07
Copy link
Contributor

Problems:

  • :LspStop doesn't support list of client ids or config names.
  • :LspRestart doesn't support config names although supports list of client ids
  • Command completion uses ids and names, not allowing the user to hit enter immediately after
    finding the desired server

Solution:

  • Unify LspStop and LspRestart implementation supporting lists of client ids and
    config names
  • Command completion only returns config names
  • Modify docs

@guilhas07 guilhas07 force-pushed the feat-list-command branch 2 times, most recently from 61b13d5 to 6439aca Compare November 17, 2024 06:39
local clients = vim.tbl_map(function(client)
return ('%d:%s'):format(client.id, client.name)
return ('%s'):format(client.name)
Copy link
Member

Choose a reason for hiding this comment

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

why remove id ? if there are multiple servers which does not support workspace folders, it will be difficult to distinguish which one want to stop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are saying that its possible to receive multiple entries like:

  • 1 lua_ls
  • 2 lua_ls

If that is the case than I will revert this.

Is there a way to show the completion with the id and name but on complete only pass the id so the user
only needs to hit enter?

Copy link
Member

Choose a reason for hiding this comment

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

revert . if you want complete with input id need imporve current custom complete and split cmdline content to get id then complete with server name

## Problems:
- `:LspStop` doesn't support list of client ids or config names.
- `:LspRestart` doesn't support config names although supports list of
client ids
- Command completion uses ids and names, not allowing the user to hit
enter immediately after
finding the desired server

## Solution:
- Unify `LspStop` and `LspRestart` implementation supporting lists of
client ids and
config names
- Command completion only returns config names
- Modify docs
Copy link
Contributor Author

@guilhas07 guilhas07 left a comment

Choose a reason for hiding this comment

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

When testing I found that lua_ls didn't close on first LspStop or LspRestart . Should LspRestart use force=true ?

client.stop()

end

local err_msg = ''
arg = arg:gsub('[%a-_]+', function(name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this enough to match all valid config names ?

Copy link
Member

@glepnir glepnir Nov 17, 2024

Choose a reason for hiding this comment

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

nope.. some server file name without underline..Because there has been no standard in the past of the server file name, the naming has become arbitrary. It is best to use xx_ls. This can be refactored later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But this matches server names without underscore too so that is not a problem. I meant if there are characters that I'm currently not matching that should be included.

@justinmk

This comment was marked as resolved.

@guilhas07
Copy link
Contributor Author

guilhas07 commented Nov 17, 2024

Supporting lists is out of scope. These commands are meant for interactive use, and the use-case for passing multiple args simulatenously is uncommon, thus not worth the code complexity (nor the extra documentation). For programmatic use the api should be used.

With these changes both LspRestart and LspStop use the same parsing function, simplifying the LspStop code (went from 47 to 25 loc), and adding the possibility to use config name for LspRestart and error logging. Overall the diff is around the same loc.

 plugin/lspconfig.lua | 93 ++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------
 1 file changed, 48 insertions(+), 45 deletions(-)

In terms of added complexity in the parsing function, only error logging and substitution from config_name to client id was added, which in my opinion its easy to follow (although I can add more comments if its necessary).

Fixing that is welcome, and should be the focus of this PR.

This was what motivate me to also add the list, because if it works correctly it would be very fast to autocomplete two Lsp
servers. Also, the LspRestart command already supported it (though not documented).

Do you have any pointers how to fix it ? I presume that I can insert some logic when accepting a completion so it uses the id.

Edit:
I think this is not possible:

I presume that I can insert some logic when accepting a completion so it uses the id.

I'm still confused on what the problem would be if only the config name is used in the completion, given that config_name is already supported and in multiple code paths it seems to be assumed that config_name is enough to identify the server. Example:

if vim.tbl_count(client.attached_buffers) > 0 then
detach_clients[client.name] = { client, lsp.get_buffers_by_client_id(client.id) }
end

README.md Outdated Show resolved Hide resolved
doc/lspconfig.txt Outdated Show resolved Hide resolved
doc/lspconfig.txt Outdated Show resolved Hide resolved
Copy link
Member

@justinmk justinmk left a comment

Choose a reason for hiding this comment

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

LGTM, let's try it. Hoping @guilhas07 will followup on any bugs :)

Co-authored-by: Justin M. Keyes <[email protected]>
@guilhas07
Copy link
Contributor Author

LGTM, let's try it. Hoping @guilhas07 will followup on any bugs :)

🫡

@justinmk justinmk merged commit f012c1b into neovim:master Nov 17, 2024
10 of 11 checks passed
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