Skip to content

Instantly share code, notes, and snippets.

@PatOConnor43
Created September 24, 2020 15:24
Show Gist options
  • Save PatOConnor43/88156409b03794f5e05280dbfb42faa6 to your computer and use it in GitHub Desktop.
Save PatOConnor43/88156409b03794f5e05280dbfb42faa6 to your computer and use it in GitHub Desktop.
A small gist to show a dartls setup function to allow all the codeactions. These can be shown with `:lua vim.lsp.buf.code_action()`
local dart_capabilities = vim.lsp.protocol.make_client_capabilities()
dart_capabilities.textDocument.codeAction = {
dynamicRegistration = false;
codeActionLiteralSupport = {
codeActionKind = {
valueSet = {
"",
"quickfix",
"refactor",
"refactor.extract",
"refactor.inline",
"refactor.rewrite",
"source",
"source.organizeImports",
};
};
};
}
nvim_lsp.dartls.setup({
on_attach = dart_attach;
init_options = {
onlyAnalyzeProjectsWithOpenFiles = true,
suggestFromUnimportedLibraries = false,
closingLabels = true,
};
capabilities = dart_capabilities;
})
@PatOConnor43
Copy link
Author

Hi, thanks for the comment.

I don't know if there was a recent change (like the past couple days) that could have fixed this but I just pulled neovim and rebuilt and updated my plugins as well (probably not necessary for this case 🤷). Everything seems to work though. I would make sure that your server is actually running. You can print your active clients by calling:
:lua print(vim.inspect(vim.lsp.get_active_clients()))
That should print a table of clients. Next, I would check the log file. You can get the path to this file by doing :lua print(vim.lsp.get_log_path()). Then open that file and see if there were any errors thrown by your language server. Hope that helps!

@ninjawithaneedle
Copy link

The language server is running. Except code actions, everything is working fine. I tried setting this:

local dart_capabilities = vim.lsp.protocol.make_client_capabilities()
dart_capabilities.textDocument.codeAction = {
  dynamicRegistration = true;
}

Now, I can see code actions. But, only a few of them. Like

1. Sort Members                                                                                                                                               
2. Organize Imports                                                                                                                                           
3. Extract Method

Thanks for the tips. I'll keep debugging

@ninjawithaneedle
Copy link

After reinstalling dart, flutter and neovim one by one, I found that it was a problem with the version of neovim I was using. Upgrading that to the latest nightly has fixed the problem. Thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment