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

Merge 0.7 branch (rebased to master) #1984

Merged
merged 1 commit into from
Aug 23, 2022
Merged

Conversation

ranjithshegde
Copy link
Contributor

Since the 0.7 branch had no one taking initiative, this is essentially #1838 rebased to master.

I have been running the branch of the PR since it was created, have zero issues.
Seeing as 0.7.2 is released and master already requires nvim >=0.7, it seems like the ideal time to revisit and merge this.

All credits go to the excellent work of mjlbach, who I wont tag to respect his privacy.

@justinmk justinmk mentioned this pull request Jul 4, 2022
@justinmk
Copy link
Member

justinmk commented Jul 4, 2022

I have been running the branch of the PR since it was created, have zero issues.

Thank you! That is valuable to know.

Why again was commands renamed to user_commands ? Doesn't look like there was a technical reason for it, nor is it an aesthetic improvement. It implies a distinction between "non user commands", which doesn't serve any purpose. It's just an interface to allow specifying commands, there is no risk of confusion, so making users type out user_commands instead of a simpler name is just pedantry.

@ranjithshegde
Copy link
Contributor Author

ranjithshegde commented Jul 4, 2022

I have been running the branch of the PR since it was created, have zero issues.

Thank you! That is valuable to know.

Why again was commands renamed to user_commands ?

This is straight from the comments on the main PR

"rename commands -> user commands to match API and free up commands
namespace"

On the one hand, the api resemblance is nice. But do you think its too confusing for the users? as these commands are essentially wrappers around unique lsp/commands?

Edit: after reading your edits, do you say it just be changed back to commands?

@justinmk
Copy link
Member

justinmk commented Jul 4, 2022

"API resemblance" here means "it literally matches nvim_create_user_command ? This is questionable because:

  1. nvim_create_user_command itself is probably over-specific and should have been named nvim_create_command (if ever it becomes theoretically possible to define non-user commands, why would we want a separate interface?! and, if it never becomes possible, what's the point of mentioning it over and over? Not even :command itself mentions this, it's literaly named :command.)
  2. this is not a strong enough motivation to ask users to perform a migration

@ranjithshegde
Copy link
Contributor Author

"API resemblance" here means "it literally matches nvim_create_user_command ? This is questionable because:

  1. nvim_create_user_command itself is probably over-specific and should have been named nvim_create_command (if ever it becomes theoretically possible to define non-user commands, why would we want a separate interface?! and, if it never becomes possible, what's the point of mentioning it over and over? Not even :command itself mentions this, it's literaly named :command.)
  2. this is not a strong enough motivation to ask users to perform a migration

Will change it back to command

@justinmk
Copy link
Member

justinmk commented Jul 4, 2022

Looking closer, and reviewing #1838 , I see that a migration will be required anyway, because the command structure changed.

I wonder if instead we should maintain the old interface. And deprecate it. Because it's not really needed, people can just call nvim_create_user_comand from on_init or on_attach.

@ranjithshegde
Copy link
Contributor Author

ranjithshegde commented Jul 4, 2022

Looking closer, and reviewing #1838 , I see that a migration will be required anyway, because the command structure changed.

I wonder if instead we should maintain the old interface. And deprecate it. Because it's not really needed, people can just call nvim_create_user_comand from on_init or on_attach.

Perhaps we remove the interface for user to define the commands, seeing as they could just use nvim_create_user_command where appropriate. But many internally defined commands (ClangdSwitchSourceHeader as an example) rely on this mechanism.

Not sure if any language specific plugins make use of them either.

So perhaps just remove it from user_space?

EDIT: Defining the commands in the setup/config of the language_server has the advantage of being able to access the server specific functions with little code.

An example from the help.txt of this PR

  commands = {
     {
      name = "TexlabBuild"
      command = function()
        buf_build(0)
      end,
      opts = {
        desc = "Build the current buffer",
      }
    },
  },

---The `configs.__newindex` metamethod consumes the config definition and returns
---an object with a `setup()` method, to be invoked by users:

    require'lspconfig'.SERVER_NAME.setup{}

---After you set `configs.SERVER_NAME` you can add arbitrary language-specific
---functions to it if necessary.

---Example
    configs.texlab.buf_build = buf_build

@justinmk
Copy link
Member

justinmk commented Jul 5, 2022

Perhaps we remove the interface for user to define the commands, seeing as they could just use nvim_create_user_command where appropriate.

I'm in favor of that. We would need to provide a simple example of using nvim_create_user_command in on_attach.

EDIT: Defining the commands in the setup/config of the language_server has the advantage of being able to access the server specific functions with little code.

An example from the help.txt of this PR

I don't see the advantage. The nvim_create_user_command call could just reference require'lspconfig'.texlab.buf_build.

@ranjithshegde
Copy link
Contributor Author

ranjithshegde commented Jul 5, 2022

I don't see the advantage. The nvim_create_user_command call could just reference require'lspconfig'.texlab.buf_build.

Many methods from this repo (chiefly lspconfig/utils like vim.fs) are already in core, along with the addition of au-events like LspAttach.
Maybe after the release of nvim 0.8 + an appropriate "settle-in" period, this repo could be stripped down to a growing collection of lsp-configs with strong defaults?

With that in mind, this PR could supply a deprecation warning concerning commands, with some examples of how to set the nvim_create_user_commands in an on_attach function?
Removing it now might be too radical for some users just yet!

@ranjithshegde
Copy link
Contributor Author

I have added a deprecation notice for commands as discussed. There is also an example in lspconfig.txt to set them up in on_attach function.

Still not entirely sure this is ideal, having commands in individual LSP setups seems cleaner than having them in a common on_attach function where the commands are filtered by client.name.

@justinmk Would appreciate your review and thoughts on this matter

@ranjithshegde ranjithshegde force-pushed the 0.7 branch 5 times, most recently from 1b24cb4 to cf1c616 Compare August 2, 2022 16:18
@ranjithshegde ranjithshegde force-pushed the 0.7 branch 2 times, most recently from 5b3c2cc to ec8a6a0 Compare August 6, 2022 16:55
@ranjithshegde
Copy link
Contributor Author

@justinmk Gentle ping
Requesting your review

@ranjithshegde
Copy link
Contributor Author

Not sure who the maintainers are now to request review from.
@williamboman?

doc/lspconfig.txt Outdated Show resolved Hide resolved
lua/lspconfig/configs.lua Outdated Show resolved Hide resolved
lua/lspconfig/server_configurations/zk.lua Outdated Show resolved Hide resolved
plugin/lspconfig.lua Outdated Show resolved Hide resolved
test/minimal_init.lua Outdated Show resolved Hide resolved
Copy link
Contributor

@williamboman williamboman left a comment

Choose a reason for hiding this comment

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

I'm personally really opposed to breaking the command API, if the plan is to deprecate it anyway.

lua/lspconfig/server_configurations/zk.lua Outdated Show resolved Hide resolved
lua/lspconfig/configs.lua Show resolved Hide resolved
plugin/lspconfig.lua Outdated Show resolved Hide resolved
plugin/lspconfig.lua Outdated Show resolved Hide resolved
scripts/docgen.lua Outdated Show resolved Hide resolved
lua/lspconfig/configs.lua Outdated Show resolved Hide resolved
lua/lspconfig/configs.lua Show resolved Hide resolved
plugin/lspconfig.lua Outdated Show resolved Hide resolved
plugin/lspconfig.lua Show resolved Hide resolved
plugin/lspconfig.lua Show resolved Hide resolved
doc/lspconfig.txt Outdated Show resolved Hide resolved
lua/lspconfig/configs.lua Outdated Show resolved Hide resolved
@justinmk
Copy link
Member

justinmk commented Aug 21, 2022

When I opened this PR (still 95% his work), other maintainers first suggested it be just called commands instead, which I changed, then it was discussed it was best to deprecate it entirely.

Right now it reflect all of those changes, in a single PR!. What is the suggestion? Keep it as the original PR by mjlbach and then deprecate it in the next nvim release cycle? Or something else?

@ranjithshegde this is my fault, sorry. Let's see if we can make progress here without too much work. Here's what I suggest:

  1. soft deprecate (show warning/error but continue to work) the commands API without a breaking change (so don't need to change the code)
  2. add the documentation examples for nvim_create_user_command
  3. remove the examples for commands
  4. update the existing lspconfigs to avoid commands

@ranjithshegde ranjithshegde force-pushed the 0.7 branch 2 times, most recently from 5cb37e5 to 5851ac0 Compare August 22, 2022 15:00
@ranjithshegde ranjithshegde requested review from justinmk and removed request for justinmk August 22, 2022 15:33
@ranjithshegde
Copy link
Contributor Author

Is there a way to see on which file and line codespell action fails at?

@glepnir
Copy link
Member

glepnir commented Aug 23, 2022

image

@ranjithshegde ranjithshegde force-pushed the 0.7 branch 4 times, most recently from ae467d4 to 61e2a79 Compare August 23, 2022 08:23
@ranjithshegde ranjithshegde requested review from kylo252 and removed request for justinmk August 23, 2022 08:25
ranjithshegde referenced this pull request Aug 23, 2022
* test: add failing test

* fix(lspconfig): only consider servers that have been set up as available
return lspconfig.available_servers()
return require("lspconfig.util").available_servers()

This comment was marked as off-topic.

Copy link
Contributor Author

@ranjithshegde ranjithshegde Aug 23, 2022

Choose a reason for hiding this comment

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

Well at the moment, the lspconfig.lua simply sets up the metatable for lspconfig.configs and nothing else. If we add this, then it will setup a metatable + a single function that can actually be in utils.
Utils holds all similar fucntions such as get_managed_clients, get_active_clients. It is perhaps a better place for it.

Then the logic is simple. The "main" portion of plugin simply sets up LSPs. Some commands in plugin/ and some useful functions in /utils.

Any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, too many PRs are being merged that potentially clash with this. Requires a bit of reshuffling

Copy link
Contributor

Choose a reason for hiding this comment

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

Then the logic is simple. The portion of plugin simply sets up LSPs, with some commands in plugin/ and some useful functions in /utils.

Yeah I agree it makes sense to remove it, I'm just thinking about not breaking parity with master. This will for sure break some user configs and plugins out there, although easily remedied.

Also, too many PRs are being merged that potentially clash with this. Requires a bit of reshuffling

Yeah there seems to be a lot happening with this big PR still being open, I'll eject myself from further comments, let's get this merged haha

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree it makes sense to remove it, I'm just thinking about not breaking parity with master. This will for sure break some user configs and plugins out there, although easily remedied.

Well this is changing/simplifying the core mechanism of the project. We could merge this as a breaking change, with a tag for previous versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@williamboman Seems this discussion was not reflected in the commit messages. Whats the best stragety to notify that M.available_servers have been moved to utils?

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.

Thanks everyone for the help here.

* switch to lua api for autocommands
* switch to nvim_create_user_command
* move to lua plugin initialization

NOTICE: Defining commands in server configurations will be deprecated in
future releases.
Please refer to the exaple in `:help lspconfig.txt` to setup the same
in an `on_attach` function
@ranjithshegde
Copy link
Contributor Author

Squashed all the changes into single commit!

@justinmk
Copy link
Member

justinmk commented Aug 23, 2022

Will merge this now. Can someone open a PR that removes stuff for 0.8? It won't be merged until 0.8 is released, but a PR will help us figure out what changes are expected.

@justinmk justinmk merged commit fe7a6f4 into neovim:master Aug 23, 2022
@ranjithshegde
Copy link
Contributor Author

Will merge this now. Can someone open a PR that removes stuff for 0.8? It won't be merged until 0.8 is released, but a PR will help us figure out what changes are expected.

Will start with an issue. Maybe deprecation is requried as the first step. Many functions in util are available upstream.
A strategy could be to redirect those calls to upstream with a deprecation warning

ranjithshegde added a commit to ranjithshegde/nvim-lspconfig that referenced this pull request Aug 23, 2022
Commit neovim#1984 included a breaking change.
Function `require("lspconfig").available_servers` has been moved to the
utils module. The new call is
`require("lspconfig.util").available_servers`
ranjithshegde added a commit to ranjithshegde/nvim-lspconfig that referenced this pull request Aug 23, 2022
BREAKING CHANGE: Functions from `lspconfig.lua`

Commit neovim#1984 included a breaking change.
Function `require("lspconfig").available_servers` has been moved to the
utils module. The new call is
`require("lspconfig.util").available_servers`
@mike-lloyd03
Copy link

I almost just opened an issue for this but did a bit more digging first. I see that this commit introduces a breaking change. But I cannot tell from the conversation here what needs to be changed in my config to accommodate this change. Or if it's a problem with another plugin that depends on lspconfig and I should roll back to a previous version of this plug until other plug developers can update. Is there recommended guidance somewhere I should be looking at?

Thanks and sorry for this annoying message. I did my research first but came up short.

@justinmk
Copy link
Member

@ranjithshegde I wasn't expecting breaking changes here per #1984 (comment) :

soft deprecate (show warning/error but continue to work) the commands API without a breaking change (so don't need to change the code)

What did we break?

@ii14
Copy link
Member

ii14 commented Aug 23, 2022

@justinmk looks like require("lspconfig").available_servers is now require("lspconfig.util").available_servers.

@ii14
Copy link
Member

ii14 commented Aug 23, 2022

If this is a problem, it could just be added back:

diff --git a/lua/lspconfig.lua b/lua/lspconfig.lua
index 1178202..7838f53 100644
--- a/lua/lspconfig.lua
+++ b/lua/lspconfig.lua
@@ -4,6 +4,11 @@ local M = {
   util = require 'lspconfig.util',
 }
 
+function M.available_servers()
+  vim.deprecate('lspconfig.available_servers', 'lspconfig.util.available_servers', '0.1.4', 'lspconfig')
+  return M.util.available_servers()
+end
+
 local mt = {}
 function mt:__index(k)
   if configs[k] == nil then

edit: added vim.deprecate

@glepnir
Copy link
Member

glepnir commented Aug 23, 2022

@justinmk like i said in #2078 I had search in github some configs and plugins use it .but it move to utils.lua

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.

8 participants