Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code actions not working in neovim #168

Open
ned-si opened this issue Jun 15, 2022 · 9 comments
Open

Code actions not working in neovim #168

ned-si opened this issue Jun 15, 2022 · 9 comments
Labels
1-bug 🐛 Issue type: Bug report (something isn't working as expected) 2-unconfirmed Issue status: Bug that needs to be reproduced (all new bugs have this label)

Comments

@ned-si
Copy link

ned-si commented Jun 15, 2022

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
@ned-si ned-si added 1-bug 🐛 Issue type: Bug report (something isn't working as expected) 2-unconfirmed Issue status: Bug that needs to be reproduced (all new bugs have this label) labels Jun 15, 2022
@David-Else
Copy link

At this point code actions need to be added into Neovim it seems: neovim/nvim-lspconfig#863 , I don't know if that can be addressed by ltex-ls or not?

grammar-guard.nvim seems dead, it would be great if someone could continue the work and merge some functionality into https://github.com/neovim/nvim-lspconfig

@ned-si
Copy link
Author

ned-si commented Jun 22, 2022

Thanks for the feedback. I tried to follow the different threads but must say that I'm not sure I understand the state of everything atm.

Good point. As it seems that the code actions making a change in the document itself work, but not the ones that try to make a change in the config file, could it be related to the fact that ltex-ls doesn't seem to be able to dynamically update a local dictionary?

I am sorry if it actually can and I'm just talking nonsense...

@David-Else
Copy link

David-Else commented 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,
      },
    },
  },
}

@ned-si
Copy link
Author

ned-si commented Jun 30, 2022

Well actually it's a pretty nice way of using built-in neovim capabilities, thanks!

Hopefully the other code actions will be available soon. Should I already close the issue then?

@tunakasif
Copy link

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,
      },
    },
  },
}

@00sapo
Copy link

00sapo commented Jul 25, 2022

See #171

@weakish
Copy link

weakish commented Sep 5, 2022

Based on David-Else's work around, I added the following configuration to LunarVim and it works.

local dictionary_file_path = os.getenv "LUNARVIM_CONFIG_DIR" .. "/spell/en.utf-8.add"
local words = {}
for word in io.lines(dictionary_file_path) do
  table.insert(words, word)
end
local ltex_opts = {
  settings = {
    ltex = {
      dictionary = {
        ["en-US"] = words
      },
    }
  }
}
require("lvim.lsp.manager").setup("ltex", ltex_opts)

I use the environment variable LUNARVIM_CONFIG_DIR instead of vim.fn.stdpath 'config',
since the latter returns ~/.config/nvim instead of ~/.config/lvim under LunarVim.

@weakish
Copy link

weakish commented Apr 20, 2023

ltex_extra.nvim provide code actions for add to dictionary, disable rules and hidde false positives under NeoVim.

@aginiewicz
Copy link

There is vigoux/ltex-ls.nvim as well, with similar features.

Julian added a commit to Julian/dotfiles that referenced this issue Sep 28, 2023
Modified from valentjn/ltex-ls#168 (comment)

As that issue mentions there's also vigoux/ltex-ls (which seems not
updated ever since ltex-ls actually became a distinct upstream project)
and then also barreiroleo/ltex_extra.nvim which seems to be keeping up a
bit better -- but let's see later if we go with that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1-bug 🐛 Issue type: Bug report (something isn't working as expected) 2-unconfirmed Issue status: Bug that needs to be reproduced (all new bugs have this label)
Projects
None yet
Development

No branches or pull requests

6 participants