[BUG] cannot format using the built-in lsp
akbng opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
Running LSP format fails with the message:
lsp format request failed, no matching language servers.
It was working previously. Suddenly it stopped formatting! without any changes made to the configs.
Expected Behavior
It should format the current document using the LSP format command.
Steps To Reproduce
Using NvChad with the below config in the custom/plugins.lua
that uses Lazy.nvim:
{
"akinsho/flutter-tools.nvim",
lazy = false,
dependencies = {
"nvim-lua/plenary.nvim",
"stevearc/dressing.nvim", -- optional for vim.ui.select
"neovim/nvim-lspconfig",
},
config = function()
local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities
require("flutter-tools").setup {
lsp = {
on_attach = on_attach,
capabilities = capabilities,
},
}
end,
}
Environment
- OS: Windows 10 pro 22H2 19045.2965
- Flutter version: 3.10.6
- Dart version: 3.0.6
- Is flutter in $PATH: yes
- neovim version: 0.9.1
Anything else?
Other functionalities like code actions are working fine.
It was attached to the buffer, I forgot to include it. Also, how would the code actions, and LSP rename would have worked?
Anyway, I have configured the LSP server separately with lspconfig along with this plugin's default configuration. It seems to work fine. But that's just a workaround, I need to know why this was happening at all!
Here's the lspconfig.lua
:
lspconfig.dartls.setup {
on_attach = on_attach,
capabilities = capabilities,
settings = {
dart = {
showTodos = true,
completeFunctionCalls = true,
renameFilesWithClasses = "prompt",
enableSnippets = true,
updateImportsOnRename = true,
enableSdkFormatter = true
}
}
}
Here's the Lazy plugin inside plugins.lua
:
{
"akinsho/flutter-tools.nvim",
lazy = false,
dependencies = {
"nvim-lua/plenary.nvim",
"stevearc/dressing.nvim", -- optional for vim.ui.select
},
config = true,
},
Here's the output of the :LspInfo
if you use null_ls.nvim
, you can add null_ls.builtins.formatting.dart_format
into it's sources, and then can format code auto.
if you use
null_ls.nvim
, you can addnull_ls.builtins.formatting.dart_format
into it's sources, and then can format code auto.
🙏Thank you, this resolves the issue completely. And I was also able to auto-format on save using null_ls