Skip to content

Commit 255caa2

Browse files
committed
Merge branch 'main' into fuzzy-underline
2 parents 1a090d1 + 3326992 commit 255caa2

File tree

16 files changed

+260
-93
lines changed

16 files changed

+260
-93
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.

crates/nu-cli/src/commands/history/history_.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ impl Command for History {
7171
})
7272
.ok()
7373
}
74+
// this variant should never happen, the config value is handled in the `UpdateFromValue` impl
75+
#[cfg(not(feature = "sqlite"))]
76+
HistoryFileFormat::Sqlite => {
77+
return Err(ShellError::GenericError {
78+
error: "Could not open history reader".into(),
79+
msg: "SQLite is not supported".to_string(),
80+
span: Some(call.head),
81+
help: "Compile Nushell with `sqlite` feature".to_string().into(),
82+
inner: vec![],
83+
});
84+
}
7485
HistoryFileFormat::Plaintext => {
7586
FileBackedHistory::with_file(history.max_size as usize, history_path.clone())
7687
.map(|inner| {
@@ -104,6 +115,17 @@ impl Command for History {
104115
history_path,
105116
))?
106117
.into_pipeline_data(head, signals)),
118+
// this variant should never happen, the config value is handled in the `UpdateFromValue` impl
119+
#[cfg(not(feature = "sqlite"))]
120+
HistoryFileFormat::Sqlite => {
121+
return Err(ShellError::GenericError {
122+
error: "Could not open history reader".into(),
123+
msg: "SQLite is not supported".to_string(),
124+
span: Some(call.head),
125+
help: "Compile Nushell with `sqlite` feature".to_string().into(),
126+
inner: vec![],
127+
});
128+
}
107129
#[cfg(feature = "sqlite")]
108130
HistoryFileFormat::Sqlite => Ok(history_reader
109131
.and_then(|h| {

crates/nu-cli/src/completions/completer.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::completions::{
77
use nu_color_config::{color_record_to_nustyle, lookup_ansi_color_style};
88
use nu_parser::{parse, parse_module_file_or_dir};
99
use nu_protocol::{
10-
CommandWideCompleter, Completion, Span, Type, Value,
10+
CommandWideCompleter, Completion, GetSpan, Span, Type, Value,
1111
ast::{
1212
Argument, Block, Expr, Expression, FindMapResult, ListItem, PipelineRedirection,
1313
RedirectionTarget, Traverse,
@@ -55,14 +55,25 @@ fn find_pipeline_element_by_position<'a>(
5555
Expr::ExternalCall(head, arguments) => arguments
5656
.iter()
5757
.find_map(|arg| arg.expr().find_map(working_set, &closure))
58-
.or(head.as_ref().find_map(working_set, &closure))
58+
.or_else(|| {
59+
// For aliased external_call, the span of original external command head should fail the
60+
// contains(pos) check, thus avoiding recursion into its head expression.
61+
// See issue #7648 for details.
62+
let span = working_set.get_span(head.span_id);
63+
if span.contains(pos) {
64+
// This is for complicated external head expressions, e.g. `^(echo<tab> foo)`
65+
head.as_ref().find_map(working_set, &closure)
66+
} else {
67+
None
68+
}
69+
})
5970
.or(Some(expr))
6071
.map(FindMapResult::Found)
6172
.unwrap_or_default(),
6273
// complete the operator
6374
Expr::BinaryOp(lhs, _, rhs) => lhs
6475
.find_map(working_set, &closure)
65-
.or(rhs.find_map(working_set, &closure))
76+
.or_else(|| rhs.find_map(working_set, &closure))
6677
.or(Some(expr))
6778
.map(FindMapResult::Found)
6879
.unwrap_or_default(),

crates/nu-cli/src/repl.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,14 @@ fn update_line_editor_history(
12351235
FileBackedHistory::with_file(history.max_size as usize, history_path)
12361236
.into_diagnostic()?,
12371237
),
1238+
// this path should not happen as the config setting is captured by `nu-protocol` already
1239+
#[cfg(not(feature = "sqlite"))]
1240+
HistoryFileFormat::Sqlite => {
1241+
return Err(miette::miette!(
1242+
help = "compile Nushell with the `sqlite` feature to use this",
1243+
"Unsupported history file format",
1244+
));
1245+
}
12381246
#[cfg(feature = "sqlite")]
12391247
HistoryFileFormat::Sqlite => Box::new(
12401248
SqliteBackedHistory::with_file(

crates/nu-cli/tests/completions/mod.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -760,17 +760,13 @@ fn dotnu_completions_const_nu_lib_dirs() {
760760
}
761761

762762
#[test]
763-
#[ignore]
764763
fn external_completer_trailing_space() {
765764
// https://github.com/nushell/nushell/issues/6378
766765
let block = "{|spans| $spans}";
767766
let input = "gh alias ";
768767

769768
let suggestions = run_external_completion(block, input);
770-
assert_eq!(3, suggestions.len());
771-
assert_eq!("gh", suggestions.first().unwrap().value);
772-
assert_eq!("alias", suggestions.get(1).unwrap().value);
773-
assert_eq!("", suggestions.get(2).unwrap().value);
769+
match_suggestions(&vec!["gh", "alias", ""], &suggestions);
774770
}
775771

776772
#[test]
@@ -2640,7 +2636,6 @@ fn exact_match_case_insensitive() {
26402636
});
26412637
}
26422638

2643-
#[ignore = "was reverted, still needs fixing"]
26442639
#[rstest]
26452640
fn alias_offset_bug_7648() {
26462641
let (_, _, mut engine, mut stack) = new_engine();
@@ -2650,16 +2645,15 @@ fn alias_offset_bug_7648() {
26502645
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack).is_ok());
26512646

26522647
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
2648+
let suggestions = completer.complete("e", 1);
2649+
assert!(!suggestions.is_empty());
26532650

2654-
// Issue #7648
2655-
// Nushell crashes when an alias name is shorter than the alias command
2656-
// and the alias command is a external command
2657-
// This happens because of offset is not correct.
2658-
// This crashes before PR #7779
2659-
let _suggestions = completer.complete("e", 1);
2651+
// Make sure completion in complicated external head expression still works
2652+
let input = "^(ls | e";
2653+
let suggestions = completer.complete(input, input.len());
2654+
assert!(!suggestions.is_empty());
26602655
}
26612656

2662-
#[ignore = "was reverted, still needs fixing"]
26632657
#[rstest]
26642658
fn alias_offset_bug_7754() {
26652659
let (_, _, mut engine, mut stack) = new_engine();
@@ -2669,12 +2663,8 @@ fn alias_offset_bug_7754() {
26692663
assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack).is_ok());
26702664

26712665
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
2672-
2673-
// Issue #7754
2674-
// Nushell crashes when an alias name is shorter than the alias command
2675-
// and the alias command contains pipes.
2676-
// This crashes before PR #7756
2677-
let _suggestions = completer.complete("ll -a | c", 9);
2666+
let suggestions = completer.complete("ll -a | c", 9);
2667+
assert!(!suggestions.is_empty());
26782668
}
26792669

26802670
#[rstest]

crates/nu-command/src/network/version_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Command for VersionCheck {
2525
fn signature(&self) -> Signature {
2626
Signature::build("version check")
2727
.category(Category::Platform)
28-
.input_output_types(vec![(Type::Nothing, Type::String)])
28+
.input_output_types(vec![(Type::Nothing, Type::record())])
2929
}
3030

3131
fn examples(&self) -> Vec<Example<'_>> {

crates/nu-command/src/strings/ansi/strip.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,37 @@ impl Command for AnsiStrip {
5151
call: &Call,
5252
input: PipelineData,
5353
) -> Result<PipelineData, ShellError> {
54-
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 1)?;
54+
let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 0)?;
5555
let cell_paths = (!cell_paths.is_empty()).then_some(cell_paths);
5656
let config = stack.get_config(engine_state);
5757
let args = Arguments { cell_paths, config };
5858
operate(action, args, input, call.head, engine_state.signals())
5959
}
6060

6161
fn examples(&self) -> Vec<Example<'_>> {
62-
vec![Example {
63-
description: "Strip ANSI escape sequences from a string",
64-
example: r#"$'(ansi green)(ansi cursor_on)hello' | ansi strip"#,
65-
result: Some(Value::test_string("hello")),
66-
}]
62+
vec![
63+
Example {
64+
description: "Strip ANSI escape sequences from a string",
65+
example: r#"$'(ansi green)(ansi cursor_on)hello' | ansi strip"#,
66+
result: Some(Value::test_string("hello")),
67+
},
68+
Example {
69+
description: "Strip ANSI escape sequences from a record field",
70+
example: r#"{ greeting: $'hello (ansi red)world' exclamation: false } | ansi strip greeting"#,
71+
result: Some(Value::test_record(record! {
72+
"greeting" => Value::test_string("hello world"),
73+
"exclamation" => Value::test_bool(false)
74+
})),
75+
},
76+
Example {
77+
description: "Strip ANSI escape sequences from multiple table columns",
78+
example: r#"[[language feature]; [$'(ansi red)rust' $'(ansi i)safety']] | ansi strip language feature"#,
79+
result: Some(Value::test_list(vec![Value::test_record(record! {
80+
"language" => Value::test_string("rust"),
81+
"feature" => Value::test_string("safety")
82+
})])),
83+
},
84+
]
6785
}
6886
}
6987

0 commit comments

Comments
 (0)