Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 33 additions & 31 deletions custom-completions/dart/dart-completions.nu
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
def "nu-complete dart commands" [context: string, offset: int] {
# Get the list of built-in commands from `dart --help`
let commands = (^dart --help
| lines
| skip until { $in | str contains "Available commands:" }
| where { $in | str starts-with " " } # Indented lines
| where { |line| not ($line | str trim | str starts-with "-") } # Ignore options
| each {
str trim
| str replace --regex '\s+' ' '
| parse "{value} {description}"
}
| flatten
# Filter out subcommands that are already handled by `export extern` definitions
# to avoid duplication in the completion list.
| where value not-in ["pub" "create"])
let commands = [
{value: "analyze", description: "Analyze the project's Dart code."}
{value: "build", description: "Build a Dart application for production deployment."}
{value: "compile", description: "Compile Dart to various formats."}
{value: "devtools", description: "Open DevTools (optionally connecting to an existing application)."}
{value: "doc", description: "Generate API documentation for Dart projects."}
{value: "fix", description: "Apply automated fixes to Dart source code."}
{value: "format", description: "Idiomatically format Dart source code."}
{value: "info", description: "Show diagnostic information about the installed tooling."}
{value: "run", description: "Run a Dart program."}
{value: "test", description: "Run tests for a project."}
]

# Extract the current token from the context using the offset.
# We need this to support completion in subdirectories (e.g. `bin/`).
Expand All @@ -24,27 +21,34 @@ def "nu-complete dart commands" [context: string, offset: int] {
let files = (glob $"($token)*"
| where { |item| ($item | path type) == 'dir' or ($item | str ends-with ".dart") }
| each { |item|
# Convert absolute paths from `glob` to relative paths to ensure Nushell
# correctly filters and displays them.
let is_dir = ($item | path type) == 'dir'
let relative = (try { $item | path relative-to $env.PWD } catch { $item })
{ value: $relative, description: (if ($item | path type) == 'dir' { "Directory" } else { "Dart script" }) }
let final_value = if $is_dir { $"($relative)/" } else { $relative }
{ value: $final_value, description: (if $is_dir { "Directory" } else { "Dart script" }) }
})

$commands | append $files
}

def "nu-complete dart pub commands" [] {
^dart pub --help
| lines
| skip until { $in | str contains "Available subcommands:" }
| where { $in | str starts-with " " }
| where { |line| not ($line | str trim | str starts-with "-") }
| each {
str trim
| str replace --regex '\s+' ' '
| parse "{value} {description}"
}
| flatten
[
{value: "add", description: "Add a dependency to pubspec.yaml."}
{value: "cache", description: "Work with the Pub system cache."}
{value: "deps", description: "Print package dependencies."}
{value: "downgrade", description: "Downgrade packages in a Dart project."}
{value: "get", description: "Get the current package's dependencies."}
{value: "global", description: "Work with globally hosted packages."}
{value: "login", description: "Log into pub.dev."}
{value: "logout", description: "Log out of pub.dev."}
{value: "outdated", description: "Analyze dependencies to find which ones can be upgraded."}
{value: "publish", description: "Publish the current package to pub.dartlang.org."}
{value: "remove", description: "Remove a dependency from the current package."}
{value: "token", description: "Manage authentication tokens for hosted pub repositories."}
{value: "top-level", description: "Print the top-level directory of the current package."}
{value: "unpack", description: "Downloads a package and unpacks it in a directory."}
{value: "upgrade", description: "Upgrade the current package's dependencies to latest versions."}
{value: "workspaces", description: "Work with workspaces."}
]
}

def "nu-complete dart templates" [] {
Expand All @@ -53,7 +57,6 @@ def "nu-complete dart templates" [] {

export extern "dart" [
command?: string@"nu-complete dart commands"
--help(-h) # Print this usage information.
--verbose(-v) # Print detailed logging.
--version # Print the VM version.
--enable-analytics # Enable telemetry reporting.
Expand All @@ -67,7 +70,6 @@ export extern "dart create" [
--pub # Run "pub get" after creation (default)
--no-pub # Do not run "pub get"
--force # Force project generation, even if the target directory already exists
--help(-h) # Print this usage information
]

export extern "dart pub" [
Expand Down
74 changes: 49 additions & 25 deletions custom-completions/flutter/flutter-completions.nu
Original file line number Diff line number Diff line change
@@ -1,30 +1,56 @@
def "nu-complete flutter commands" [] {
^flutter --help --verbose
| lines
| skip until { $in | str contains "Available commands:" }
| where { $in | str starts-with " " } # Indented lines
| where { |line| not ($line | str trim | str starts-with "-") } # Ignore options
| each {
str trim
| str replace --regex '\s+' ' '
| parse "{value} {description}"
}
| flatten
| where value not-in ["pub" "create"]
[
{value: "analyze", description: "Analyze the project's Dart code."}
{value: "assemble", description: "Assemble and build Flutter resources."}
{value: "attach", description: "Attach to a running app."}
{value: "bash-completion", description: "Output command line shell completion setup scripts."}
{value: "build", description: "Build an executable app or install bundle."}
{value: "channel", description: "List or switch Flutter channels."}
{value: "clean", description: "Delete the build/ and .dart_tool/ directories."}
{value: "config", description: "Configure Flutter settings."}
{value: "custom-devices", description: "List, reset, add and delete custom devices."}
{value: "daemon", description: "Run a persistent, JSON-RPC based server to communicate with devices."}
{value: "debug-adapter", description: "Run a Debug Adapter Protocol (DAP) server to communicate with the Flutter tool."}
{value: "devices", description: "List all connected devices."}
{value: "doctor", description: "Show information about the installed tooling."}
{value: "downgrade", description: "Downgrade Flutter to the last active version for the current channel."}
{value: "drive", description: "Builds and installs the app, and runs a Dart program that connects to the app, often to run externally facing integration tests, such as with package:test and package:flutter_driver."}
{value: "emulators", description: "List, launch and create emulators."}
{value: "gen-l10n", description: "Generate localizations for the current project."}
{value: "install", description: "Install a Flutter app on an attached device."}
{value: "logs", description: "Show log output for running Flutter apps."}
{value: "precache", description: "Populate the Flutter tool's cache of binary artifacts."}
{value: "run", description: "Run your Flutter app on an attached device."}
{value: "running-apps", description: "List running applications."}
{value: "screenshot", description: "Take a screenshot from a connected device."}
{value: "symbolize", description: "Symbolize a stack trace from an AOT-compiled Flutter app."}
{value: "test", description: "Run Flutter unit tests for the current project."}
{value: "upgrade", description: "Upgrade your copy of Flutter."}
{value: "widget-preview", description: "Manage the widget preview environment."}
]
}

def "nu-complete pub commands" [] {
^flutter pub --help
| lines
| skip until { $in | str contains "Available subcommands:" }
| where { $in | str starts-with " " }
| where { |line| not ($line | str trim | str starts-with "-") }
| each {
str trim
| str replace --regex '\s+' ' '
| parse "{value} {description}"
}
| flatten
[
{value: "add", description: "Add a dependency to pubspec.yaml."}
{value: "cache", description: "Work with the Pub system cache."}
{value: "deps", description: "Print package dependencies."}
{value: "downgrade", description: "Downgrade packages in a Flutter project."}
{value: "get", description: "Get the current package's dependencies."}
{value: "global", description: "Work with Pub global packages."}
{value: "login", description: "Log into pub.dev."}
{value: "logout", description: "Log out of pub.dev."}
{value: "outdated", description: "Analyze dependencies to find which ones can be upgraded."}
{value: "pub", description: "Pass the remaining arguments to Dart's \"pub\" tool."}
{value: "publish", description: "Publish the current package to pub.dartlang.org."}
{value: "remove", description: "Removes a dependency from the current package."}
{value: "run", description: "Run an executable from a package."}
{value: "test", description: "Run the \"test\" package."}
{value: "token", description: "Manage authentication tokens for hosted pub repositories."}
{value: "upgrade", description: "Upgrade the current package's dependencies to latest versions."}
{value: "uploader", description: "Manage uploaders for a package on pub.dev."}
{value: "version", description: "Print Pub version."}
]
}

def "nu-complete android-languages" [] {
Expand All @@ -41,7 +67,6 @@ def "nu-complete platforms" [] {

export extern "flutter" [
command?: string@"nu-complete flutter commands"
--help(-h) # Print this usage information.
--verbose(-v) # Noisy logging, including all shell commands executed.
--device-id(-d): string # Target device id or name (prefixes allowed).
--version # Reports the version of this tool.
Expand All @@ -63,7 +88,6 @@ export extern "flutter create" [
--platforms: string@"nu-complete platforms" # The platforms supported by this project
--template(-t): string@"nu-complete project-templates" # Specify the type of project to create
--empty(-e) # Specifies creating using an application template with a main.dart that is minimal
--help(-h) # Print this usage information
]

export extern "flutter pub" [
Expand Down