When writing module options, one ends up using various lib functions, such that using with lib; becomes tempting. Since large-scale with usage is generally considered bad practice, people sometimes opt for an alternative like this:
{ lib, ... }:
let
inherit (lib) mkOption;
inherit (lib.types) attrsOf str;
in
{
options.example = mkOption {
type = attrsOf str;
default = { };
};
}
Since it's annoying to type this out by hand, it would be really nice if nil offered a code action to turn a with into this kind of let-inherit-in construct. It won't be perfect in the case of nested withs, but I think it'll still be worth it for the 80% case.
On top of that, nil could offer a code action similar to the "add to imports" of LSPs in other languages, to easily add new things to the construct. On every unknown symbol, provide code actions such as Inherit this symbol from lib, Inherit this symbol from lib.types for every inherit (from) expression in scope:
{ lib, ... }:
let
inherit (lib) mkOption;
inherit (lib.types) attrsOf;
in
{
options.example = mkOption {
type = attrsOf str; # <- unknown symbol "str"
default = { }; # --[ Inherit "str" from lib ]
}; # ->[ Inherit "str" from lib.types ]
}
When writing module options, one ends up using various
lib
functions, such that usingwith lib;
becomes tempting. Since large-scalewith
usage is generally considered bad practice, people sometimes opt for an alternative like this:Since it's annoying to type this out by hand, it would be really nice if nil offered a code action to turn a
with
into this kind oflet-inherit-in
construct. It won't be perfect in the case of nestedwith
s, but I think it'll still be worth it for the 80% case.On top of that, nil could offer a code action similar to the "add to imports" of LSPs in other languages, to easily add new things to the construct. On every unknown symbol, provide code actions such as
Inherit this symbol from lib
,Inherit this symbol from lib.types
for everyinherit (from)
expression in scope: