question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code actions not working in neovim

See original GitHub issue

Describe the bug In neovim, code actions work when choosing one of the “correction” option, but not when choosing one of the following:

  • Add <word> to dictionary
  • Hide false positives
  • Disable rule

Steps to reproduce Steps to reproduce the behavior:

  1. Create a markdown file with the following line CustomWord is not a word
  2. CustomWord is rightly marked as not a correct word
  3. Move the cursor on it
  4. Type: :lua vim.lsp.buf.code_action()
  5. Choose 5: Add 'CustomWord' to dictionary
  6. Nothing happens, the error is still here. And there is no error message either.

Expected behavior I expect it to add the CustomWord to dictionary and remove errors linked to it in the rest of the document, without having to manually add the word in the configuration.

Sample document

CustomWord is not a word

LTeX configuration I’m using it in neovim with lspconfig and nvim-lsp-installer with the default config, just calling it:

nvim_lsp.ltex.setup {
  on_attach = on_attach
  }

LTeX LS log No error log unfortunately.

Version information

  • OS: Linux <hostname> 5.18.3-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 09 Jun 2022 16:14:10 +0000 x86_64 GNU/Linux
  • ltex-ls: 15.2.0
  • Java: 11.0.12

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
tunakasifcommented, Jul 14, 2022

Based on the work-around @David-Else provided in the comment above, I added a local dictionary capability. The VS Code extension version creates ltex.dictionary.en-US.txt file under .vscode/ directory and adds the word to this text file, by default, when add-to-dictionary option is selected in VS Code. Based on this behavior, I come up with the following solution. The code snippet vim.fn.expand("%:p:h") gets the absolute path of the Neovim buffer, so the provided solution looks for a .vscode/ltex.dictionary.en-US.txt hierarchy in the same directory. Then, the lines in both global user dictionary and local dictionary are utilized if these paths are valid. You can change/add different paths as well. One of the caveats is that the provided solution is not dynamic as in the VS Code extension, i.e., if you update the dictionary .txt file, you need to restart Neovim. This problem can be prevented by defining an autocmd to revaluate the table of words.

local paths = {
    vim.fn.stdpath("config") .. "/spell/ltex.dictionary.en-US.txt",
    vim.fn.expand("%:p:h") .. "/.vscode/ltex.dictionary.en-US.txt",
}

local words = {}
for _, path in ipairs(paths) do
    local f = io.open(path)
    if f then
        for word in f:lines() do
	    table.insert(words, word)
	end
	f:close()
    end
end

lspconfig.ltex.setup {
  on_attach = on_attach,
  settings = {
    ltex = {
      dictionary = {
        ['en-US'] = words,
        ['en-GB'] = words,
      },
    },
  },
}
1reaction
David-Elsecommented, Jun 22, 2022

I use this workaround, you can add words to your normal Neovim spelling directory and ltex-ls will use them. Not perfect, but works!

-- add vim user dictionary for ltex-ls
local path = vim.fn.stdpath 'config' .. '/spell/en.utf-8.add'
local words = {}

for word in io.open(path, 'r'):lines() do
  table.insert(words, word)
end

lspconfig.ltex.setup {
  on_attach = on_attach,
  settings = {
    ltex = {
      dictionary = {
        ['en-US'] = words,
        ['en-GB'] = words,
      },
    },
  },
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Code actions and renaming not working in Neovim #1888
Code actions ("textDocument/codeAction") and renaming ("textDocument/rename") seems not to be working with neovim builtin lsp. To Reproduce
Read more >
LspConfig code action does not work : r/neovim - Reddit
LspConfig code action does not work. I have problems with LspConfig when extracting a method to a new file. When executing the following...
Read more >
neovim - LspConfig code action does not work
I have problems with LspConfig when extracting a method to a new file. When executing the following command buf_set_keymap("n","<space>ca" ...
Read more >
Neovim built-in LSP shows No code actions available for ...
When I open a python file, diagnostics seem to be working fine. Then I navigate to a line with a ...
Read more >
User Manual - rust-analyzer
Toolchain; VS Code; rust-analyzer Language Server Binary; Emacs; Vim/NeoVim ... Note that installing via xtask install does not work for VS Code Remote, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found