Skip to content

Commit ec5032a

Browse files
committed
feat(completions): add auto_menu config for IDE-style completions
Adds `$env.config.completions.auto_menu` option (default: false) that enables automatic completion menu display as you type. When enabled: - Completion menu appears after typing 1+ character for any argument - Menu deactivates when typing just a space (waiting for next word) - First word (commands) never auto-completes Also switches hint provider from CwdAwareHinter to CompletionHinter for fish-style inline suggestions based on completions rather than history. Requires: nushell/reedline#993
1 parent ba5f920 commit ec5032a

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ bench = false
376376
# To use a development version of a dependency please use a global override here
377377
# changing versions in each sub-crate of the workspace is tedious
378378
[patch.crates-io]
379-
reedline = { git = "https://github.com/nushell/reedline", branch = "main" }
379+
# Use fork with auto_complete_menu feature (PR: https://github.com/nushell/reedline/pull/993)
380+
reedline = { git = "https://github.com/oxysoft/reedline", branch = "feat/auto-complete-menu" }
380381
# nu-ansi-term = { git = "https://github.com/nushell/nu-ansi-term.git", branch = "main" }
381382

382383
# Run all benchmarks with `cargo bench`

crates/nu-cli/src/repl.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ use nu_utils::{
3737
#[cfg(feature = "sqlite")]
3838
use reedline::SqliteBackedHistory;
3939
use reedline::{
40-
CursorConfig, CwdAwareHinter, DefaultCompleter, EditCommand, Emacs, FileBackedHistory,
40+
CompletionHinter, CursorConfig, DefaultCompleter, EditCommand, Emacs, FileBackedHistory,
4141
HistorySessionId, Reedline, Vi,
4242
};
43+
use std::sync::Mutex;
4344
use std::sync::atomic::Ordering;
4445
use std::{
4546
collections::HashMap,
@@ -400,6 +401,7 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
400401
)))
401402
.with_quick_completions(config.completions.quick)
402403
.with_partial_completions(config.completions.partial)
404+
.with_auto_complete_menu(config.completions.auto_menu)
403405
.with_ansi_colors(config.use_ansi_coloring.get(engine_state))
404406
.with_cwd(Some(
405407
engine_state
@@ -421,11 +423,15 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) {
421423

422424
start_time = std::time::Instant::now();
423425
line_editor = if config.use_ansi_coloring.get(engine_state) && config.show_hints {
424-
line_editor.with_hinter(Box::new({
425-
// As of Nov 2022, "hints" color_config closures only get `null` passed in.
426-
let style = style_computer.compute("hints", &Value::nothing(Span::unknown()));
427-
CwdAwareHinter::default().with_style(style)
428-
}))
426+
// Create a second completer for inline completion hints (fish-style autosuggestions)
427+
let hint_completer = NuCompleter::new(
428+
engine_reference.clone(),
429+
stack_arc.clone(),
430+
);
431+
let style = style_computer.compute("hints", &Value::nothing(Span::unknown()));
432+
line_editor.with_hinter(Box::new(
433+
CompletionHinter::new(Arc::new(Mutex::new(hint_completer))).with_style(style)
434+
))
429435
} else {
430436
line_editor.disable_hints()
431437
};

crates/nu-protocol/src/config/completions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub struct CompletionConfig {
105105
pub case_sensitive: bool,
106106
pub quick: bool,
107107
pub partial: bool,
108+
pub auto_menu: bool,
108109
pub algorithm: CompletionAlgorithm,
109110
pub external: ExternalCompleterConfig,
110111
pub use_ls_colors: bool,
@@ -117,6 +118,7 @@ impl Default for CompletionConfig {
117118
case_sensitive: false,
118119
quick: true,
119120
partial: true,
121+
auto_menu: false,
120122
algorithm: CompletionAlgorithm::default(),
121123
external: ExternalCompleterConfig::default(),
122124
use_ls_colors: true,
@@ -142,6 +144,7 @@ impl UpdateFromValue for CompletionConfig {
142144
"sort" => self.sort.update(val, path, errors),
143145
"quick" => self.quick.update(val, path, errors),
144146
"partial" => self.partial.update(val, path, errors),
147+
"auto_menu" => self.auto_menu.update(val, path, errors),
145148
"algorithm" => self.algorithm.update(val, path, errors),
146149
"case_sensitive" => self.case_sensitive.update(val, path, errors),
147150
"external" => self.external.update(val, path, errors),

0 commit comments

Comments
 (0)