-
-
Notifications
You must be signed in to change notification settings - Fork 347
plugins/ltes-extra: support ltex_plus #3129
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,24 @@ | |
lib, | ||
helpers, | ||
config, | ||
options, | ||
... | ||
}: | ||
with lib; | ||
let | ||
lspCfg = config.plugins.lsp; | ||
in | ||
lib.nixvim.plugins.mkNeovimPlugin { | ||
name = "ltex-extra"; | ||
packPathName = "ltex_extra.nvim"; | ||
package = "ltex_extra-nvim"; | ||
|
||
maintainers = [ maintainers.loicreynier ]; | ||
|
||
description = '' | ||
This plugin works with both the ltex or ltex_plus language servers and will enable ltex_plus if neither are. | ||
Kirens marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e.g. this |
||
''; | ||
|
||
callSetup = false; | ||
|
||
settingsOptions = { | ||
|
@@ -44,24 +52,65 @@ lib.nixvim.plugins.mkNeovimPlugin { | |
}; | ||
|
||
extraConfig = cfg: { | ||
warnings = lib.nixvim.mkWarnings "plugins.ltex-extra" { | ||
when = !config.plugins.lsp.enable; | ||
message = '' | ||
You have enabled `ltex-extra` but not the lsp (`plugins.lsp`). | ||
You should set `plugins.lsp.enable = true` to make use of the LTeX_extra plugin's features. | ||
''; | ||
}; | ||
|
||
plugins.lsp = { | ||
servers.ltex = { | ||
# Enable the ltex language server | ||
enable = true; | ||
warnings = lib.nixvim.mkWarnings "plugins.ltex-extra" [ | ||
{ | ||
when = !lspCfg.enable; | ||
message = '' | ||
You have enabled `ltex-extra` but not the lsp (`plugins.lsp`). | ||
You should set `plugins.lsp.enable = true` to make use of the LTeX_extra plugin's features. | ||
''; | ||
} | ||
( | ||
let | ||
expectedDefs = map toString [ | ||
./. | ||
../../lsp/language-servers | ||
]; | ||
isExternal = d: !elem d.file expectedDefs; | ||
anyExternal = | ||
acc: name: v: | ||
let | ||
e = findFirst isExternal null v.definitionsWithLocations; | ||
in | ||
if acc != null then | ||
acc | ||
else if e == null then | ||
null | ||
else | ||
{ | ||
inherit name; | ||
inherit (e) file; | ||
}; | ||
external = foldlAttrs anyExternal null options.plugins.lsp.servers.ltex; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting approach using the definition location 😎 I wonder if it'd be better to filter for external definitions, instead of reducing to the first match? That way we could list all offending definitions in the warning. I'm also a little concerned about false-pisitives where there are irrelevant low-prio defs. I can't recall ottomh whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, it was sort of inspired by your options priority-suggestion. If I recall from my testing, it filters based on priority, but only at the top level. So if there are recursive attributes, such as in In this particular case, it would basically only be encountered if there is a config with an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another consideration is if/how |
||
in | ||
{ | ||
# TODO: Added 2025-03-30; remove after 25.05 | ||
# Warn if servers.ltex seems to be configured outside of ltex-extra | ||
when = !lspCfg.servers.ltex.enable && external != null; | ||
message = '' | ||
in ${external.file} | ||
You seem to have configured `plugins.lsp.servers.ltex.${external.name}` for `ltex-extra`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we have a reference to the option itself, we can interpolate it here. "${options.foo}"
=> "programs.nixvim.foo" options come with a This has the advantage of automatically including path prefixes, such as |
||
It now uses `plugins.lsp.servers.ltex_plus` by default, | ||
either move the configuration or explicitly enable `ltex` with `plugins.lsp.servers.ltex.enable = true` | ||
Comment on lines
+93
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm probably being a bit dense, but I struggle to follow what "it" is refering to. Also what/where the "configuration" should be moved. Layout nit: I wonder if bullet points would be slightly clearer? If not, maybe we should consider an Oxford-comma before the "or"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I struggled to layout that part for a bit. Good suggestions, I'll revisit this. |
||
''; | ||
} | ||
) | ||
]; | ||
|
||
onAttach.function = '' | ||
plugins.lsp = | ||
let | ||
attachLua = '' | ||
require("ltex_extra").setup(${lib.nixvim.toLuaObject cfg.settings}) | ||
''; | ||
in | ||
{ | ||
servers.ltex.onAttach.function = attachLua; | ||
servers.ltex_plus = { | ||
# Enable ltex_plus if ltex is not already enabled | ||
enable = mkIf (!lspCfg.servers.ltex.enable) (mkDefault true); | ||
onAttach.function = attachLua; | ||
Kirens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
settingsExample = { | ||
|
Uh oh!
There was an error while loading. Please reload this page.