Skip to content
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

Code actions: convert with lib; to let inherit (lib) ...;, add unknown symbols to inherit #145

Open
max-privatevoid opened this issue Aug 4, 2024 · 0 comments
Labels
A-assist Area: assistence/code action C-feature Catagory: feature

Comments

@max-privatevoid
Copy link

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 ]
}
@oxalica oxalica added C-feature Catagory: feature A-assist Area: assistence/code action labels Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assist Area: assistence/code action C-feature Catagory: feature
Projects
None yet
Development

No branches or pull requests

2 participants