hinell / lsp-timeout.nvim

Start/stop LSP servers upon demand; keeps RAM usage low
Other
195 stars 6 forks source link

LSPs not restarting / null-ls #13

Closed ls-devs closed 8 months ago

ls-devs commented 8 months ago

Summary

Since last update, I can't get my LSPs to restart on refocus, only inside .tsx files.

Actually, I have to manually use LspStart to restart the timedout servers. Please see (.tsx file) :

https://github.com/hinell/lsp-timeout.nvim/assets/58638832/3ec7f487-1414-4621-ad51-5a1293022807

See the difference (.lua file) :

https://github.com/hinell/lsp-timeout.nvim/assets/58638832/871e314f-fb23-4a29-9810-ca6f967aba50

EDIT : It seems that if lsp-timeout stop the servers and we don't use LspStop command to check if it's working, on refocus the LSPs are not restarted too.

Steps to reproduce

Stop LSP servers inside .tsx file (or typescript project ?) , switch focus and then refocus the nvim window.

Versions

NVIM v0.10.0-dev-1418+g15983cf2c-dirty Build type: RelWithDebInfo LuaJIT 2.1.1697887905

hinell commented 8 months ago

@ls-devs You use null-ls. Its misbehavior has already been reported previously.

See:

Tell me whether the solution from the first link works or not. null-ls is probably the source of problem.

ls-devs commented 8 months ago

@hinell

I use legendary.nvim for creating autocmds. Actually I've this :

{
   "LspAttach",
     function()
       vim.notify("LSP Attaching")
       return require("null-ls").enable({})
     end,
     description = "Start null-ls when starting a lsp client",
},

I can tell the command works fine. But the LSPs are not restarting.

hinell commented 8 months ago

@ls-devs Disable null-ls entirely via lazy.nvim and try again.

legendary.nvim

I would advise against using this plugin. It's notorious for being hard to debug. Don't use it for autocmds.

ls-devs commented 8 months ago

@hinell As you suggested, I disabled null-ls with lazy, and the LSPs are restarted correctly.

Next, I enabled null-ls and switched the autocmd from legendary.nvim to a classic autocmd (can tell the command is working fine). And the LSPs still don't restart. So, obviously there's something to do with null-ls but the autocmd given in the doc don't fix the issue for me.

Here's the autocmd I created :

vim.api.nvim_create_autocmd({ "LspAttach" }, {
  desc = "Start null-ls when starting a lsp client",
  callback = function()
    pcall(function() require("null-ls").enable({}) end)
  end,
})

I also tried this one :

vim.api.nvim_create_autocmd("LspAttach", {
  callback = function(args)
    require("null-ls").enable({})
  end,
})

I would advise against using this plugin. It's notorious for being hard to debug. Don't use it for autocmds.

Tbh, I never had issue with this plugin.

hinell commented 8 months ago

So, obviously there's something to do with null-ls

Yes. I will look into their code later to figure out what it does. Can you provide an example of how you configured null-ls?

Tbh, I never had issue with this plugin.

It's hard to troubleshoot in some cases. This isn't strictly for autocmds. But the problem may arise if you want to register some autocmd intended to run legendary to register some more actions via autocmd. This gets out of hand quickly. Not in this case though.

ls-devs commented 8 months ago

@hinell Here's how I setup null-ls

  local null_ls = require("null-ls")
  vim.api.nvim_create_augroup("LspFormatting", {})

  null_ls.setup({
    debug = true,
    sources = {
      -- PYTHON
      null_ls.builtins.code_actions.refactoring.with({
        filetypes = { "python", "lua" },
      }),
      null_ls.builtins.diagnostics.pylint,
      null_ls.builtins.formatting.black,
      -- JS / TS
      null_ls.builtins.code_actions.eslint_d,
      null_ls.builtins.diagnostics.eslint_d,
      null_ls.builtins.formatting.prettierd.with({
        root_dir = require("null-ls.utils").root_pattern("."),
        filetypes = {
          "javascript",
          "javascriptreact",
          "typescript",
          "typescriptreact",
          "vue",
          "css",
          "scss",
          "less",
          "html",
          "json",
          "jsonc",
          "yaml",
          "markdown",
          "markdown.mdx",
          "graphql",
          "handlebars",
        },
      }),
      null_ls.builtins.diagnostics.jsonlint,
      null_ls.builtins.formatting.jq,
      -- LUA
      null_ls.builtins.formatting.stylua,
      -- PRISMA
      null_ls.builtins.formatting.prismaFmt.with({
        command = "prismaFmt",
      }),
      -- RUST
      null_ls.builtins.formatting.rustfmt.with({
        extra_args = function(params)
          local Path = require("plenary.path")
          local cargo_toml = Path:new(params.root .. "/" .. "Cargo.toml")

          if cargo_toml:exists() and cargo_toml:is_file() then
            for _, line in ipairs(cargo_toml:readlines()) do
              local edition = line:match([[^edition%s*=%s*%"(%d+)%"]])
              if edition then
                return { "--edition=" .. edition }
              end
            end
          end
          return { "--edition=2021" }
        end,
      }),
      -- CMAKE
      null_ls.builtins.diagnostics.cmake_lint,
      null_ls.builtins.formatting.cmake_format,
      -- MARKDOWN
      null_ls.builtins.code_actions.proselint,
      null_ls.builtins.diagnostics.markdownlint,
      null_ls.builtins.formatting.markdownlint,
      -- YAML
      null_ls.builtins.diagnostics.yamllint,
      null_ls.builtins.formatting.yamlfmt,
      -- PHP
      null_ls.builtins.diagnostics.phpcs.with({
        extra_args = { "--standard=ruleset.xml" },
      }),
      null_ls.builtins.formatting.phpcsfixer,
      -- SQL
      null_ls.builtins.formatting.sql_formatter,
      -- DOCKER
      null_ls.builtins.diagnostics.hadolint,
      -- Haskell
      null_ls.builtins.formatting.fourmolu,
      -- Bash
      null_ls.builtins.formatting.shellharden,
      -- XML
      null_ls.builtins.formatting.xmlformat.with({
        filetypes = { "svg", "xml" },
      }),
      -- CPP
      null_ls.builtins.diagnostics.cpplint.with({
        filetypes = { "c", "cpp" },
        extra_args = { "--filter=", "-legal/copyright" },
      }),
      null_ls.builtins.formatting.clang_format.with({
        filetypes = { "c", "cpp" },
        extra_args = { "-style=", "file" },
      }),
      -- GIT
      null_ls.builtins.diagnostics.commitlint,
      -- ZSH
      null_ls.builtins.formatting.beautysh.with({
        filetypes = { "zsh" },
      }),
    },
  })

If it can help you can still try my configuration : ls-devs/nvim

hinell commented 8 months ago

@ls-devs Thanks. You could have just linked that though lol.

Anyway. You have any ideas which of these sources may be interfering with typescript-tools? eslint_d may be?

ls-devs commented 8 months ago

Anyway. You have any ideas which of these sources may be interfering with typescript-tools? eslint_d may be?

I can't think about anything else than eslint_d but can you explain how this source can possibly be interfering with LSPs ?

ls-devs commented 8 months ago

@hinell Forgot to mention that I use none-ls because null-ls is archived. Don't know if it's changing something tho since none-ls is just a replacement maintained by the community and it should be the same code base.

Zeioth commented 8 months ago

I can confirm lsp servers are not restarting correctly after upgrading from 1.0.2 to 1.0.3. Downgrading to 1.0.3 make the plugin work again.

hinell commented 8 months ago

I've narrowed down the issue and it should be fixed in scheduled v1.2.0

Regarding null-ls:

  1. I would suggest to drop null-ls (it's slow as heck) and migrate
  2. Be aware that the null-ls has removed integration with lspconfig several years ago, meaning, it won't be managed by LspConfig https://github.com/jose-elias-alvarez/null-ls.nvim/pull/389
hinell commented 8 months ago

Please update to v1.2.0 and tell the difference

Hope this helps.

ls-devs commented 8 months ago

@hinell Thanks, it's working now

I would suggest to drop null-ls (it's slow as heck) and migrate

Do you have any recommendations on how to replace null-ls ?

hinell commented 8 months ago

@ls-devs Please close the issue if it's fixed.

Do you have any recommendations on how to replace

I would suggest to use efm. For more alternatives, follow: https://github.com/hinell/lsp-timeout.nvim/issues/7#issuecomment-1764402683