Adds multi-file support to IDE support (#8857)

# Description

This adds multi-file support to the in-progress IDE support. The main
new features are a `-I` flag that allows you to add a new source search
path when starting up the nu binary, and fixes for the current IDE
support to support spans in other files.

This needs accompanying fixes to the vscode/lsp implementation to pass
along the project directory via `-I`.

UPDATE: Marking this draft until we have a means to test this.

# User-Facing Changes

_(List of all changes that impact the user experience here. This helps
us keep track of breaking changes.)_

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
JT
2023-04-13 05:36:29 +12:00
committed by GitHub
parent b3d6896977
commit 487789b45b
5 changed files with 51 additions and 10 deletions

View File

@ -37,7 +37,9 @@ pub(crate) fn gather_commandline_args() -> (Vec<String>, String, Vec<String>) {
#[cfg(feature = "plugin")]
"--plugin-config" => args.next().map(|a| escape_quote_string(&a)),
"--log-level" | "--log-target" | "--testbin" | "--threads" | "-t"
| "--ide-goto-def" | "--ide-hover" | "--ide-complete" => args.next(),
| "--include-path" | "-I" | "--ide-goto-def" | "--ide-hover" | "--ide-complete" => {
args.next()
}
_ => None,
};
@ -109,6 +111,7 @@ pub(crate) fn parse_commandline_args(
let log_level: Option<Expression> = call.get_flag_expr("log-level");
let log_target: Option<Expression> = call.get_flag_expr("log-target");
let execute: Option<Expression> = call.get_flag_expr("execute");
let include_path: Option<Expression> = call.get_flag_expr("include-path");
let table_mode: Option<Value> =
call.get_flag(engine_state, &mut stack, "table-mode")?;
@ -142,6 +145,7 @@ pub(crate) fn parse_commandline_args(
let log_level = extract_contents(log_level)?;
let log_target = extract_contents(log_target)?;
let execute = extract_contents(execute)?;
let include_path = extract_contents(include_path)?;
let help = call.has_flag("help");
@ -183,6 +187,7 @@ pub(crate) fn parse_commandline_args(
log_level,
log_target,
execute,
include_path,
ide_goto_def,
ide_hover,
ide_complete,
@ -220,6 +225,7 @@ pub(crate) struct NushellCliArgs {
pub(crate) log_target: Option<Spanned<String>>,
pub(crate) execute: Option<Spanned<String>>,
pub(crate) table_mode: Option<Value>,
pub(crate) include_path: Option<Spanned<String>>,
pub(crate) ide_goto_def: Option<Value>,
pub(crate) ide_hover: Option<Value>,
pub(crate) ide_complete: Option<Value>,
@ -249,6 +255,12 @@ impl Command for Nu {
"run the given commands and then enter an interactive shell",
Some('e'),
)
.named(
"include-path",
SyntaxShape::String,
"set the NU_LIB_DIRS for the given script",
Some('I'),
)
.switch("interactive", "start as an interactive shell", Some('i'))
.switch("login", "start as a login shell", Some('l'))
.named(