mirror of
https://github.com/nushell/nushell.git
synced 2025-08-13 12:17:42 +02:00
feat(completion): stdlib virtual path completion & exportable completion (#15270)
# Description More completions for `use` command. ~Also optimizes the span fix of #15238 to allow changing the text after the cursor.~ # User-Facing Changes <img width="299" alt="image" src="https://github.com/user-attachments/assets/a5c45f46-40e4-4c50-9408-7b147ed11dc4" /> <img width="383" alt="image" src="https://github.com/user-attachments/assets/fbeec173-511e-4c72-8995-bc1caa3ef0d3" /> # Tests + Formatting +3 # After Submitting
This commit is contained in:
@ -11,6 +11,7 @@ use nu_engine::eval_block;
|
||||
use nu_parser::parse;
|
||||
use nu_path::expand_tilde;
|
||||
use nu_protocol::{debugger::WithoutDebug, engine::StateWorkingSet, Config, PipelineData};
|
||||
use nu_std::load_standard_library;
|
||||
use reedline::{Completer, Suggestion};
|
||||
use rstest::{fixture, rstest};
|
||||
use support::{
|
||||
@ -513,7 +514,7 @@ fn dotnu_completions() {
|
||||
|
||||
match_suggestions(&vec!["sub.nu`"], &suggestions);
|
||||
|
||||
let expected = vec![
|
||||
let mut expected = vec![
|
||||
"asdf.nu",
|
||||
"bar.nu",
|
||||
"bat.nu",
|
||||
@ -546,6 +547,8 @@ fn dotnu_completions() {
|
||||
match_suggestions(&expected, &suggestions);
|
||||
|
||||
// Test use completion
|
||||
expected.push("std");
|
||||
expected.push("std-rfc");
|
||||
let completion_str = "use ";
|
||||
let suggestions = completer.complete(completion_str, completion_str.len());
|
||||
|
||||
@ -577,6 +580,65 @@ fn dotnu_completions() {
|
||||
match_dir_content_for_dotnu(dir_content, &suggestions);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dotnu_stdlib_completions() {
|
||||
let (_, _, mut engine, stack) = new_dotnu_engine();
|
||||
assert!(load_standard_library(&mut engine).is_ok());
|
||||
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
|
||||
|
||||
let completion_str = "export use std/ass";
|
||||
let suggestions = completer.complete(completion_str, completion_str.len());
|
||||
match_suggestions(&vec!["assert"], &suggestions);
|
||||
|
||||
let completion_str = "use `std-rfc/cli";
|
||||
let suggestions = completer.complete(completion_str, completion_str.len());
|
||||
match_suggestions(&vec!["clip"], &suggestions);
|
||||
|
||||
let completion_str = "use \"std";
|
||||
let suggestions = completer.complete(completion_str, completion_str.len());
|
||||
match_suggestions(&vec!["\"std", "\"std-rfc"], &suggestions);
|
||||
|
||||
let completion_str = "overlay use \'std-rfc/cli";
|
||||
let suggestions = completer.complete(completion_str, completion_str.len());
|
||||
match_suggestions(&vec!["clip"], &suggestions);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exportable_completions() {
|
||||
let (_, _, mut engine, mut stack) = new_dotnu_engine();
|
||||
let code = r#"export module "🤔🐘" {
|
||||
export const foo = "🤔🐘";
|
||||
}"#;
|
||||
assert!(support::merge_input(code.as_bytes(), &mut engine, &mut stack).is_ok());
|
||||
assert!(load_standard_library(&mut engine).is_ok());
|
||||
|
||||
let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));
|
||||
|
||||
let completion_str = "use std null";
|
||||
let suggestions = completer.complete(completion_str, completion_str.len());
|
||||
match_suggestions(&vec!["null-device", "null_device"], &suggestions);
|
||||
|
||||
let completion_str = "export use std/assert eq";
|
||||
let suggestions = completer.complete(completion_str, completion_str.len());
|
||||
match_suggestions(&vec!["equal"], &suggestions);
|
||||
|
||||
let completion_str = "use std/assert \"not eq";
|
||||
let suggestions = completer.complete(completion_str, completion_str.len());
|
||||
match_suggestions(&vec!["'not equal'"], &suggestions);
|
||||
|
||||
let completion_str = "use std-rfc/clip ['prefi";
|
||||
let suggestions = completer.complete(completion_str, completion_str.len());
|
||||
match_suggestions(&vec!["prefix"], &suggestions);
|
||||
|
||||
let completion_str = "use std/math [E, `TAU";
|
||||
let suggestions = completer.complete(completion_str, completion_str.len());
|
||||
match_suggestions(&vec!["TAU"], &suggestions);
|
||||
|
||||
let completion_str = "use 🤔🐘 'foo";
|
||||
let suggestions = completer.complete(completion_str, completion_str.len());
|
||||
match_suggestions(&vec!["foo"], &suggestions);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dotnu_completions_const_nu_lib_dirs() {
|
||||
let (_, _, engine, stack) = new_dotnu_engine();
|
||||
|
Reference in New Issue
Block a user