-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[WIP] Support ltex-ls #863
Conversation
I started reviewing, but I would highly recommend looking at another configuration example (rust-analyzer is a good one) to see the form these should take, you shouldn't have a setup{} call in the config for example, you shouldn't check for configs.ltex-ls etc. |
Ok |
Ok, so I looked more into this when I wanted to use it. I am considering reconsidering allowing custom commands to be registered per language server. This https://github.com/neovim/nvim-lspconfig/pull/863/files#diff-b6698738921d6c7c76e0bb67c33623ba1d213719c995c8353468bcdb3411049bR156-R186 is extremely messy, and I'd like to avoid it somehow. I'm not sure what the appropriate way to do this is @mfussenegger For now, I would recommend instead of overriding execute_command, I would override the handler for |
lua/lspconfig/ltex.lua
Outdated
dictionary_files = { ["en"] = {vim.fn.getcwd() .. "dictionary.ltex"} }; | ||
disabledrules_files = { ["en"] = {vim.fn.getcwd() .. "disable.ltex"} }; | ||
falsepositive_files = { ["en"] = {vim.fn.getcwd() .. "false.ltex"}}; | ||
settings = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure everything under settings is either a default, or too opinionated to be worth using.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the size of this my module, my recommendation is to create ltex-ls.nvim and add a smaller minimal config in lspconfig to start. The following "works". We can gradually add back in the functionality while making any necessary changes in neovim core to support more "off-spec" language servers like this one:
local configs = require'lspconfig/configs' local util = require 'lspconfig/util' local server_name = "ltex-ls" configs[server_name] = { default_config = { cmd = {"ltex-ls"}; filetypes = {'tex', 'bib', 'markdown'}; root_dir = function(filename) return util.path.dirname(filename) end; settings = { ltex = { checkFrequency="edit", }; }; }; docs = { package_json = 'https://raw.githubusercontent.com/valentjn/vscode-ltex/develop/package.json', description = [[ https://github.com/valentjn/ltex-ls LTeX Language Server: LSP language server for LanguageTool 🔍✔️ with support for LaTeX 🎓, Markdown 📝, and others To install, download the latest [release](https://github.com/valentjn/ltex-ls/releases) and ensure `ltex-ls` is on your path. ]]; }; };edit: Actually we need to send at least one setting for the server to trigger... seems like a bug.
What exactly didn't work? At least in my test, except to the "add to ..." and pickyrules which is disabled by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The server doesn't provide any diagnostics if not at least one settings
item is sent, I'm advocating for the first round of inclusion of lspconfig, using the simpler config you quoted while we clean up this PR.
lua/lspconfig/ltex.lua
Outdated
}; | ||
on_attach = function(client, bufnr) | ||
-- local lang = client.config.settings.ltex.language | ||
for lang,_ in ipairs(client.config.dictionary_files) do -- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
settings are automatically sent on_attach, I don't thin you need to update this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This came from my use case, where I use two languages in the same document with different files for each language.
Do you have a better suggestion how to do this with multiple languages?
With the size of this my module, my recommendation is to create ltex-ls.nvim and add a smaller minimal config in lspconfig to start. The following "works". We can gradually add back in the functionality while making any necessary changes in neovim core to support more "off-spec" language servers like this one: local configs = require'lspconfig/configs'
local util = require 'lspconfig/util'
local server_name = "ltex-ls"
configs[server_name] = {
default_config = {
cmd = {"ltex-ls"};
filetypes = {'tex', 'bib', 'markdown'};
root_dir = function(filename)
return util.path.dirname(filename)
end;
settings = {
ltex = {
checkFrequency="edit",
};
};
};
docs = {
package_json = 'https://raw.githubusercontent.com/valentjn/vscode-ltex/develop/package.json',
description = [[
https://github.com/valentjn/ltex-ls
LTeX Language Server: LSP language server for LanguageTool 🔍✔️ with support for LaTeX 🎓, Markdown 📝, and others
To install, download the latest [release](https://github.com/valentjn/ltex-ls/releases) and ensure `ltex-ls` is on your path.
]];
};
}; edit: Actually we need to send at least one setting for the server to trigger... seems like a bug. |
neovim/neovim#14115 would help :) In nvim-jdtls I provide a dedicated But I only do that because otherwise I can't access the original code_action_params which are required for the java specific client commands. (the VSCode code action API gives access to them, so language servers naturally ended up depending on them). Otherwise I'd probably also override the handler. But the problem with that is that different plugins can become incompatible with each other, so the handler should only be overriden in the scope of the language specific client and not globally. |
I totally forgot about that :) , we should stop punting on the decision about breaking symmetry in the args. Maybe we can convince @tjdevries to review next Friday.
For sure, in this case I'd advocate just adding a default handler in the config that overrides it just for ltex-ls, as I believe the current PR overrides a global function which IMO is not good. We can always make this cleaner once neovim/neovim#14115 in one form or another. |
lua/lspconfig/ltex.lua
Outdated
|
||
local function findLtexFiles(filetype, value) | ||
local buf_clients = vim.lsp.buf_get_clients() | ||
for _, client in ipairs(buf_clients) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pairs
lua/lspconfig/ltex.lua
Outdated
local function updateConfig(lang, configtype) | ||
local buf_clients = vim.lsp.buf_get_clients() | ||
local client = nil | ||
for _, lsp in ipairs(buf_clients) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pairs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I would love to see this merged. Is there a hold up we could help with? In the meantime, this is an option: https://github.com/brymer-meneses/grammar-guard.nvim |
The hacks around buffer_execute command can be removed with the new handler signature, and this: neovim/neovim#14115 once merged will make adding client side commands easier. I also have an unresolved comment that hasn't been addressed. |
@lbiaggi Neovim 0.5.1 is out, I think neovim/neovim#15504 might be the relevant change in the handler signature @mjlbach mentioned. Really looking forward to this getting merged :) |
The client side command registry wasn't backported so this would still need to be gated behind a 0.6 'has' neovim/neovim#14115 Also, given the amount of client-side code I think this is probably better as a separate plugin, we'll see. |
Is there a better way to check nvim version (from lua) than this? vim.fn.has('nvim-0.6') |
That's what I would recommend. |
I've also added this in williamboman/nvim-lsp-installer#134 for the time being. Hopefully should be fairly straight forward to eject the custom code from that plugin, and only keep the installer, once things are figured out. |
Hi, I removed the custom code from the MR. I will send later a working patch with 0.6 changes to the project from @brymer-meneses (I got almost everything working as in VS Code) 😄 |
Brand new version 14 of ltex-ls just came out, https://github.com/valentjn/ltex-ls/releases/tag/14.0.0 , can't wait to get this in Neovim! |
@lbiaggi let me know if you have any questions |
@David-Else for your info (only, and if you care): valentjn/ltex-ls#103 (comment). |
@oblitum Thanks for the info! Unfortunately I am not using coc, so will have to wait until this PR lands. |
If a user wants to use this now, I recommend https://github.com/brymer-meneses/grammar-guard.nvim which is an extension that provides ltex-ls support for the built-in client (it's now added to the wiki). Having it in the monorepo is great (many users like/prefer the convenience of the monorepo, similar to how vim itself ships runtime filetype and syntax plugins in a "monorepo"), but this shouldn't be blocking anyone. |
@mjlbach This can get merged now I think? It makes |
fa4e657
to
39caff8
Compare
I'm merging this by popular demand (lspconfig is ofc community contributed), a couple notes:
For those reasons, I highly encourage people to either contribute to grammar-guard, or start their own custom plugin which provides additional features (which we can then reference in the wiki as with the other growing number of language specific plugins that integrate or bypass lspconfig to use the client directly). Lspconfig is always going to try to be as "on-spec" and minimal as possible (for servers that are on-spec/may not necessitate their own plugin since it would be about 10 LOC, are unpopular, etc.). I updated CONTRIBUTING to make this more clear the other day. |
Co-authored-by: William Boman <william@redwill.se>
if you're just aliasing the commands, the directory is not in your |
The thread previously referred by me here is originally about language auto detection, which ltex/language-tool does support (with the given limitations as per thread). |
@disrupted Can't believe I made such a dumb error! Here is the install script I just made, in case in saves anyone some time. No need to add anything to the path if you install to the proper directory and add a symlink :) NOTE: You need Java on your computer using the version of ltex-ls I download in the script, headless minimal version should be OK, I use Rocky Linux package:
|
Also, if people want to use the ngram data this is now working great:
You get a lot more corrections, brings it closer to the online grammarly results while keeping everything on your own computer. |
I'd advice to not extract directly at |
If the user doesn't add
I understand that adding words to the dictionary is something that needs a plugin. |
@David-Else The reason for the missing spelling corrections is that the default config in this PR uses the language On a related note, generally, I would advise not setting defaults explicitly and let LTEX take care of those, if possible—except for good client-specific reasons. This makes changes of settings structure/default values easier and it enables a more consistent experience across clients. Plus, there are some thoughts behind most default values. Picky rules for instance, which this PR activates, are disabled by default as they generate quite some false positives, which can confuse users (e.g., valentjn/vscode-ltex#419). |
@valentjn Thank you so much for stopping by, it's extremely appreciated when upstream authors provide direct input.
Is there any setting here we need to be sending? I'm fine just wiping this, I believe I had asked about this before during review from the original PR author.
I'm fine doing a quick follow-up PR based on your feedback, although it would be great if a neovim user who actively uses ltex-ls can take ownership over maintaining these settings from time-to time (perhaps keeping it in sync with grammar guard). |
LTEX itself doesn't need any setting to be set. Missing settings are automatically set to their default values. The only setting that's actually necessary in this case should be We had that problem before for the coc.nvim version in valentjn/vscode-ltex#425, where the problem was fixed by changing the mapping of filetypes to LSP language IDs in coc.nvim. Not sure if something like this would be possible here. If not, then I'd suggest setting
The other settings can be removed. I haven't tried it, though. |
Yes, we can pass |
ref: for those in the thread #1364 Haven't tested, will check everything works later. |
I am not sure grammar guard is happening any time soon, getting the ability to define a file to be the user dictionary and have the code action to add to it work would be pretty amazing at this point :) |
I encourage someone else to start an additiona ltexls.nvim then, it's out of scope of lspconfig to add off-spec handlers/requests. Lspconfig should always be a fallback/backup to a dedicated extension (or the defacto if the client is on-spec I guess). |
Initial working code to support ltex-ls with suggestion to address #858
thanks, @mjlbach, @mfussenegger
Looking for help/suggestion about these things:
dictionary, disabledRules, hiddenFalsePositives
, they currently need to be hardcoded using a valid table entry with an existing file previously created.