From 0718fca59b82e53aef07699db7e1bbd86ba8dacf Mon Sep 17 00:00:00 2001 From: oxalica Date: Thu, 30 Mar 2023 22:04:10 +0800 Subject: [PATCH] Parse rec attrsets in flake.nix --- crates/ide/src/def/kind.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/ide/src/def/kind.rs b/crates/ide/src/def/kind.rs index 3cf837e..c62efa6 100644 --- a/crates/ide/src/def/kind.rs +++ b/crates/ide/src/def/kind.rs @@ -58,12 +58,13 @@ fn parse_flake_nix(module: &Module) -> ModuleKind { let mut explicit_inputs = HashMap::new(); let mut param_inputs = HashMap::new(); let mut outputs_expr = None; - if let Expr::Attrset(flake_set) = &module[module.entry_expr()] { + if let Expr::Attrset(flake_set) | Expr::RecAttrset(flake_set) = &module[module.entry_expr()] { for &(name_id, value) in flake_set.statics.iter() { let BindingValue::Expr(value_expr) = value else { continue }; match &*module[name_id].text { "inputs" => { - let Expr::Attrset(inputs) = &module[value_expr] else { continue }; + let (Expr::Attrset(inputs) | Expr::RecAttrset(inputs)) = &module[value_expr] + else { continue }; explicit_inputs = inputs .statics .iter() @@ -189,7 +190,7 @@ mod tests { } #[test] - fn flake_nix() { + fn flake_nix_normal() { check( r#" #- /flake.nix input:nixpkgs=/nix/store/eeee @@ -202,6 +203,24 @@ mod tests { ); } + #[test] + fn flake_nix_rec() { + check( + r#" +#- /flake.nix input:nixpkgs=/nix/store/eeee +rec { + inputs = rec { + nil = rec { + url = "github:oxalica/nil"; + }; + }; + outputs = { self, nixpkgs, ... }: rec { }; +} + "#, + expect!["FlakeNix: explicit_inputs=nil param_inputs=nixpkgs outputs={ self, nixpkgs, ... }: rec { }"], + ); + } + #[test] fn package() { check(