Skip to content
Open
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
- commands run for dynamic completion have no controlling terminal, and every command inshellah runs gets `SSH_ASKPASS_REQUIRE=never`, so a dynamic completion that reaches an ssh host needing a password or host key confirmation fails at once, where it used to hang until the dynamic timeout. `325e898` `5b48f8a`
- `dynamicLimit` / `INSHELLAH_DYNAMIC_LIMIT` only bounds the unfiltered listing. once a prefix is typed, providers query without it so matches past the limit are found, which costs more on very large ref or container lists. `22c6922`
- user cache entries written by another inshellah build, including every 0.2.0 cache, are dropped and resolved again on first use. caches built with `inshellah index` into the user dir go the same way, so rerun `index` on those prefixes after updating. `7090b28`
- `complete` answers nushell with a `{completions: [...], options: {cache: false}}` record wherever it used to print a bare list, so nushell stops replaying stale git refs, pids and other live values across prompts once it honours the option, which needs the still unmerged nushell#19346. scripts that read `complete` output as a list need to take `completions` from the record.

#### nixos module

- `dynamicTimeoutMs`, `dynamicLimit`, `maxCompletions`, `cacheTtlSecs` and `completeTimeoutMs` reject negative values at evaluation. negative values used to be ignored or replaced by the default at runtime. a negative `timeoutMs` or `workers = 0` already failed the build and now fails at evaluation. `ee0111c`
- `dynamicTimeoutMs`, `dynamicLimit`, `maxCompletions`, `cacheTtlSecs` and `completeTimeoutMs` reject negative values at evaluation. negative values used to be ignored or replaced by the default at runtime. a negative `timeoutMs` or `workers = 0` already failed the build and now fails at evaluation. `a348baa`
- `helpOnlyCommands` follows the `--help-only` change above and covers the subcommands of each listed command. `8fdc9c1`
- when cross compiling, a scraped package, `nushellPackage` or `package` is only replaced by its spliced build-platform twin, or by the stock build package when it is the unmodified stock package. an override is no longer matched to the stock build package by name and version. a scraped package without a twin is skipped with a warning naming it, and a `nushellPackage` or `package` without one fails evaluation, where both used to run with the host-platform tools. `1524d5f`
- when cross compiling, a scraped package, `nushellPackage` or `package` is only replaced by its spliced build-platform twin, or by the stock build package when it is the unmodified stock package. an override is no longer matched to the stock build package by name and version. a scraped package without a twin is skipped with a warning naming it, and a `nushellPackage` or `package` without one fails evaluation, where both used to run with the host-platform tools. `7980211`
13 changes: 7 additions & 6 deletions doc/nushell-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ source /path/to/inshellah-completer.nu

that's it. tab-completion now works for every command indexed.

the external completer contract is explicit. `[...]` means inshellah is
answering this position, and `[]` means nothing fits, such as a flag value
outside its known set. `{completions: [...], fallback: true}` adds nushell's
file completion beside the candidates, for git refs next to paths. `null`
means "let nushell decide", returned for file-like leaf positions with no
static or live provider candidates.
the external completer contract is explicit. `{completions: [...]}` answers
the current position, and an empty list means nothing fits, such as a flag
value outside its known set. `fallback: true` keeps nushell's file
completion beside the candidates, as with git refs next to paths, while
`options: {cache: false}` asks nushell to skip its cross-prompt completion
cache, which takes effect once the unmerged nushell#19346 lands. `null` hands the position back to nushell for file-like arguments
with no static or live candidates.

## commands

Expand Down
14 changes: 7 additions & 7 deletions src/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ impl Display for Response {
Self::Candidates(candidates) => (candidates, false),
Self::WithFiles(candidates) => (candidates, true),
};
if with_files {
f.write_str(r#"{"completions":"#)?;
}
f.write_char('[')?;
f.write_str(r#"{"completions":["#)?;
for (idx, candidate) in candidates.iter().enumerate() {
if idx > 0 {
f.write_char(',')?;
Expand All @@ -88,11 +85,14 @@ impl Display for Response {
JsonEscaped(&candidate.description)
)?;
}
f.write_char(']')?;
// nushell 0.115+ reuses answers across prompts keyed only on the line,
// serving stale git refs and pids (nushell#19297). the opt-out is the
// unmerged nushell#19346, so this option does nothing until it lands.
f.write_str(r#"],"options":{"cache":false}"#)?;
if with_files {
f.write_str(r#","fallback":true}"#)?;
f.write_str(r#","fallback":true"#)?;
}
Ok(())
f.write_char('}')
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/golden/completion/flags_dash.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"value":"-v","description":"(aka --verbose) verbose output"},{"value":"--color","description":"colorize output <WHEN>"}]
{"completions":[{"value":"-v","description":"(aka --verbose) verbose output"},{"value":"--color","description":"colorize output <WHEN>"}],"options":{"cache":false}}
2 changes: 1 addition & 1 deletion tests/golden/completion/flags_long_prefix.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"value":"--color","description":"colorize output <WHEN>"}]
{"completions":[{"value":"--color","description":"colorize output <WHEN>"}],"options":{"cache":false}}
2 changes: 1 addition & 1 deletion tests/golden/completion/resolve_extra_flags.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"value":"-n","description":"(aka --name) set a name <NAME>"},{"value":"--fast","description":"go fast"}]
{"completions":[{"value":"-n","description":"(aka --name) set a name <NAME>"},{"value":"--fast","description":"go fast"}],"options":{"cache":false}}
2 changes: 1 addition & 1 deletion tests/golden/completion/sub_build_flags.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"value":"-j","description":"(aka --jobs) parallel jobs <N>"},{"value":"--release","description":"build in release mode"}]
{"completions":[{"value":"-j","description":"(aka --jobs) parallel jobs <N>"},{"value":"--release","description":"build in release mode"}],"options":{"cache":false}}
2 changes: 1 addition & 1 deletion tests/golden/completion/subs_empty_token.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"value":"build","description":"Compile the package"},{"value":"check","description":"Analyze the package"},{"value":"clean","description":"Remove build artifacts"}]
{"completions":[{"value":"build","description":"Compile the package"},{"value":"check","description":"Analyze the package"},{"value":"clean","description":"Remove build artifacts"}],"options":{"cache":false}}
2 changes: 1 addition & 1 deletion tests/golden/completion/subs_prefix_b.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"value":"build","description":"Compile the package"}]
{"completions":[{"value":"build","description":"Compile the package"}],"options":{"cache":false}}
2 changes: 1 addition & 1 deletion tests/golden/completion/subs_prefix_c.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"value":"check","description":"Analyze the package"},{"value":"clean","description":"Remove build artifacts"}]
{"completions":[{"value":"check","description":"Analyze the package"},{"value":"clean","description":"Remove build artifacts"}],"options":{"cache":false}}
2 changes: 1 addition & 1 deletion tests/golden/completion/sudo_passthrough.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"value":"build","description":"Compile the package"}]
{"completions":[{"value":"build","description":"Compile the package"}],"options":{"cache":false}}
2 changes: 1 addition & 1 deletion tests/golden/completion/system_only_subs.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"value":"stop","description":"Stop it"},{"value":"start","description":"Start it"},{"value":"status","description":"Show status"}]
{"completions":[{"value":"stop","description":"Stop it"},{"value":"start","description":"Start it"},{"value":"status","description":"Show status"}],"options":{"cache":false}}
5 changes: 3 additions & 2 deletions tests/runtime_complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ fn completion_values(stdout: &[u8]) -> Vec<String> {
if trimmed == "null" || trimmed.is_empty() {
return Vec::new();
}
serde_json::from_str::<serde_json::Value>(trimmed)
.expect("completion JSON")
let json = serde_json::from_str::<serde_json::Value>(trimmed).expect("completion JSON");
json.get("completions")
.unwrap_or(&json)
.as_array()
.expect("completion array")
.iter()
Expand Down
2 changes: 1 addition & 1 deletion tests/seam-completer.nu
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def fail [msg: string] { error make {msg: $msg} }

def vals [spans: list<string>] {
let r = (inshellah-complete-spans $spans)
if $r == null { [] } else { $r | get value }
if $r == null { [] } else { $r.completions | get value }
}

def assert-has [spans: list<string>, needle: string] {
Expand Down
Loading