Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

NullLsStop and NullLsStart #896

Closed
1 task done
mosheavni opened this issue Jun 5, 2022 · 7 comments
Closed
1 task done

NullLsStop and NullLsStart #896

mosheavni opened this issue Jun 5, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@mosheavni
Copy link
Contributor

Issues

  • I have checked existing issues and there are no existing ones with the same request.

Feature description

2 additional ex-commands:
NullLsStop and NullLsStart
Since lsp-config's LspStart and LspStop don't know about clients not started through it, we need to have an easy way of stopping and starting the client.

Help

No

Implementation help

@mosheavni mosheavni added the enhancement New feature or request label Jun 5, 2022
@jose-elias-alvarez
Copy link
Owner

jose-elias-alvarez commented Jun 6, 2022

Stopping the client is pretty simple and works as expected

local null_ls_stop = function()
    local null_ls_client
    for _, client in ipairs(vim.lsp.get_active_clients()) do
        if client.name == "null-ls" then
            null_ls_client = client
        end
    end
    if not null_ls_client then
        return
    end

    null_ls_client.stop()
end

vim.api.nvim_create_user_command("NullLsStop", null_ls_stop, {})

Restarting clients, however, is harder. lspconfig has different logic to do this and it's not directly implemented in Neovim itself.

A more null-ls-friendly way of doing this would be to use the source API to manipulate all registered sources:

vim.api.nvim_create_user_command("NullLsToggle", function()
    -- you can also create commands to disable or enable sources
    require("null-ls").toggle({})
end, {})

This isn't exactly the same, since the client will still be active and shown in the :LspInfo window, but in terms of functionality it does what you want. I wouldn't necessarily be opposed to a PR that allows restarting the client but would be hesitant to merge anything that adds more than a few lines of code, since it's a case that we are (mostly) already handling.

@mosheavni
Copy link
Contributor Author

Stopping the client is pretty simple and works as expected

local null_ls_stop = function()
    local null_ls_client
    for _, client in ipairs(vim.lsp.get_active_clients()) do
        if client.name == "null-ls" then
            null_ls_client = client
        end
    end
    if not null_ls_client then
        return
    end

    null_ls_client.stop()
end

vim.api.nvim_create_user_command("NullLsStop", null_ls_stop, {})

Restarting clients, however, is harder. lspconfig has different logic to do this and it's not directly implemented in Neovim itself.

A more null-ls-friendly way of doing this would be to use the source API to manipulate all registered sources:

vim.api.nvim_create_user_command("NullLsToggle", function()
    -- you can also create commands to disable or enable sources
    require("null-ls").toggle({})
end, {})

This isn't exactly the same, since the client will still be active and shown in the :LspInfo window, but in terms of functionality it does what you want. I wouldn't necessarily be opposed to a PR that allows restarting the client but would be hesitant to merge anything that adds more than a few lines of code, since it's a case that we are (mostly) already handling.

Thanks man that'll be enough for me.
The NullLsStop is very handy, I'm sure not only for me, so if you want me to open a PR, gladly, it's just that it's your code.
Let me know if I can help.

@jose-elias-alvarez
Copy link
Owner

I think this would require more work to align with user expectations. For example, because of how the null-ls client works, stopping it doesn't clear existing diagnostics. Likewise, I tried messing with the code to make it possible to start a client if the old one is stopped, but it doesn't attach to the current buffer right away and generally behaves weirdly.

I'm not against including these as part of the API (I'd leave it up to users to define commands) so I'm happy to leave this open, but I think the underlying use case of "I want to stop null-ls from running but maybe restart it later" is already handled by the source API, so I won't work on it myself or accept a PR that adds complexity.

@mosheavni
Copy link
Contributor Author

makes perfect sense.
I wish neovim would handle those gaps with the lsp client sooner rather than later.
btw thanks for this awesome project. you're the best.

@jose-elias-alvarez
Copy link
Owner

Closing this as I think the source API already provides a solution.

@mosheavni
Copy link
Contributor Author

Closing this as I think the source API already provides a solution.

Sounds good, can you share what was added?

@jose-elias-alvarez
Copy link
Owner

Nothing was added - what I meant is that the source API (docs linked) already provides ways to start, stop, and toggle the availability of null-ls. Adding a stop command would be easy, but adding a restart command is not, and I don't think the complexity is worth it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants