Skip to content

Commit ec6325a

Browse files
committed
plugins/ltex-extra: prefer ltex_plus over ltex
ltex_plus is a maintained fork that recently got supported by ltex-extra barreiroleo/ltex_extra.nvim#66 Enable it unless the user explicitly use ltex
1 parent 107ed54 commit ec6325a

File tree

1 file changed

+63
-14
lines changed

1 file changed

+63
-14
lines changed

plugins/by-name/ltex-extra/default.nix

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22
lib,
33
helpers,
44
config,
5+
options,
56
...
67
}:
78
with lib;
9+
let
10+
lspCfg = config.plugins.lsp;
11+
in
812
lib.nixvim.plugins.mkNeovimPlugin {
913
name = "ltex-extra";
1014
packPathName = "ltex_extra.nvim";
1115
package = "ltex_extra-nvim";
1216

1317
maintainers = [ maintainers.loicreynier ];
1418

19+
description = ''
20+
This plugin works with both the ltex or ltex_plus language servers and will enable ltex_plus if neither are.
21+
'';
22+
1523
callSetup = false;
1624

1725
settingsOptions = {
@@ -44,24 +52,65 @@ lib.nixvim.plugins.mkNeovimPlugin {
4452
};
4553

4654
extraConfig = cfg: {
47-
warnings = lib.nixvim.mkWarnings "plugins.ltex-extra" {
48-
when = !config.plugins.lsp.enable;
49-
message = ''
50-
You have enabled `ltex-extra` but not the lsp (`plugins.lsp`).
51-
You should set `plugins.lsp.enable = true` to make use of the LTeX_extra plugin's features.
52-
'';
53-
};
54-
55-
plugins.lsp = {
56-
servers.ltex = {
57-
# Enable the ltex language server
58-
enable = true;
55+
warnings = lib.nixvim.mkWarnings "plugins.ltex-extra" [
56+
{
57+
when = !lspCfg.enable;
58+
message = ''
59+
You have enabled `ltex-extra` but not the lsp (`plugins.lsp`).
60+
You should set `plugins.lsp.enable = true` to make use of the LTeX_extra plugin's features.
61+
'';
62+
}
63+
(
64+
let
65+
expectedDefs = map toString [
66+
./.
67+
../../lsp/language-servers
68+
];
69+
isExternal = d: !elem d.file expectedDefs;
70+
anyExternal =
71+
acc: name: v:
72+
let
73+
e = findFirst isExternal null v.definitionsWithLocations;
74+
in
75+
if acc != null then
76+
acc
77+
else if e == null then
78+
null
79+
else
80+
{
81+
inherit name;
82+
inherit (e) file;
83+
};
84+
external = foldlAttrs anyExternal null options.plugins.lsp.servers.ltex;
85+
in
86+
{
87+
# TODO: Added 2025-03-30; remove after 25.05
88+
# Warn if servers.ltex seems to be configured outside of ltex-extra
89+
when = !lspCfg.servers.ltex.enable && external != null;
90+
message = ''
91+
in ${external.file}
92+
You seem to have configured `plugins.lsp.servers.ltex.${external.name}` for `ltex-extra`.
93+
It now uses `plugins.lsp.servers.ltex_plus` by default,
94+
either move the configuration or explicitly enable `ltex` with `plugins.lsp.servers.ltex.enable = true`
95+
'';
96+
}
97+
)
98+
];
5999

60-
onAttach.function = ''
100+
plugins.lsp =
101+
let
102+
attachLua = ''
61103
require("ltex_extra").setup(${lib.nixvim.toLuaObject cfg.settings})
62104
'';
105+
in
106+
{
107+
servers.ltex.onAttach.function = attachLua;
108+
servers.ltex_plus = {
109+
# Enable ltex_plus if ltex is not already enabled
110+
enable = mkIf (!lspCfg.servers.ltex.enable) (mkDefault true);
111+
onAttach.function = attachLua;
112+
};
63113
};
64-
};
65114
};
66115

67116
settingsExample = {

0 commit comments

Comments
 (0)