88with lib ;
99let
1010 lspCfg = config . plugins . lsp ;
11+ initPlugin = ''
12+ require("ltex_extra").setup(${ lib . nixvim . toLuaObject cfg . settings } )
13+ '' ;
1114in
1215lib . nixvim . plugins . mkNeovimPlugin {
1316 name = "ltex-extra" ;
@@ -17,7 +20,8 @@ lib.nixvim.plugins.mkNeovimPlugin {
1720 maintainers = [ maintainers . loicreynier ] ;
1821
1922 description = ''
20- This plugin works with both the ltex or ltex_plus language servers and will enable ltex_plus if neither are.
23+ This plugin works with either the ltex or ltex_plus language servers.
24+ Enabling this plugin will also enable ltex_plus, unless ltex is already enabled.
2125 '' ;
2226
2327 callSetup = false ;
@@ -81,15 +85,29 @@ lib.nixvim.plugins.mkNeovimPlugin {
8185 inherit name ;
8286 inherit ( e ) file ;
8387 } ;
84- external = foldlAttrs anyExternal null options . plugins . lsp . servers . ltex ;
88+ srvOpts = options . plugins . lsp . servers ;
89+ external = foldlAttrs anyExternal null srvOpts . ltex ;
90+
91+ activeCfg = o :
92+ foldlAttrs ( acc : name : val :
93+ if val == null then acc
94+ else if isAttrs val then
95+
96+ else acc // { ${ name } = val }
97+ ) { }
98+ if isAttrs o then
99+ # redir
100+ else a == b ;
101+
102+ inherit ( lspCfg . servers ) ltex ;
85103 in
86104 {
87105 # TODO: Added 2025-03-30; remove after 25.05
88106 # Warn if servers.ltex seems to be configured outside of ltex-extra
89- when = ! lspCfg . servers . ltex . enable && external != null ;
107+ when = ! ltex . enable && ltex !=
90108 message = ''
91109 in ${ external . file }
92- You seem to have configured `plugins.lsp.servers. ltex.${ external . name } ` for `ltex-extra`.
110+ You seem to have configured `${ srvOpts . ltex . ${ external . name } } ` for `ltex-extra`.
93111 It now uses `plugins.lsp.servers.ltex_plus` by default,
94112 either move the configuration or explicitly enable `ltex` with `plugins.lsp.servers.ltex.enable = true`
95113 '' ;
@@ -99,16 +117,13 @@ lib.nixvim.plugins.mkNeovimPlugin {
99117
100118 plugins . lsp =
101119 let
102- attachLua = ''
103- require("ltex_extra").setup(${ lib . nixvim . toLuaObject cfg . settings } )
104- '' ;
105120 in
106121 {
107- servers . ltex . onAttach . function = attachLua ;
122+ servers . ltex . onAttach . function = initPlugin ;
108123 servers . ltex_plus = {
109124 # Enable ltex_plus if ltex is not already enabled
110125 enable = mkIf ( ! lspCfg . servers . ltex . enable ) ( mkDefault true ) ;
111- onAttach . function = attachLua ;
126+ onAttach . function = initPlugin ;
112127 } ;
113128 } ;
114129 } ;
0 commit comments