1- def "nu-complete dart commands" [] {
2- ^ dart -- help
1+ def "nu-complete dart commands" [context : string , offset : int ] {
2+ # Get the list of built-in commands from `dart --help`
3+ let commands = (^ dart -- help
34 | lines
45 | skip until { $in | str contains " Available commands:" }
56 | where { $in | str starts-with " " } # Indented lines
@@ -10,7 +11,26 @@ def "nu-complete dart commands" [] {
1011 | parse " {value} {description}"
1112 }
1213 | flatten
13- | where value not-in [" pub" " create" ]
14+ # Filter out subcommands that are already handled by `export extern` definitions
15+ # to avoid duplication in the completion list.
16+ | where value not-in [" pub" " create" ])
17+
18+ # Extract the current token from the context using the offset.
19+ # We need this to support completion in subdirectories (e.g. `bin/`).
20+ let token = ($context | str substring 0 .. $offset | split row ' ' | last )
21+
22+ # Glob for files matching the token, filtering for directories (for traversal)
23+ # and .dart files (as valid script targets).
24+ let files = (glob $" ($token )*"
25+ | where { |item | ($item | path type ) == ' dir' or ($item | str ends-with " .dart" ) }
26+ | each { |item |
27+ # Convert absolute paths from `glob` to relative paths to ensure Nushell
28+ # correctly filters and displays them.
29+ let relative = (try { $item | path relative-to $env .PWD } catch { $item })
30+ { value : $relative , description : (if ($item | path type ) == ' dir' { " Directory" } else { " Dart script" }) }
31+ })
32+
33+ $commands | append $files
1434}
1535
1636def "nu-complete dart pub commands" [] {
0 commit comments