Commit Graph

1133 Commits

Author SHA1 Message Date
WindSoilder
f6033ac5af
Module: support defining const and use const variables inside of function (#9773)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
<!--
Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.

Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.
-->
Relative: #8248 

After this pr, user can define const variable inside a module.

![image](https://github.com/nushell/nushell/assets/22256154/e3e03e56-c4b5-4144-a944-d1b20bec1cbd)

And user can export const variables, the following screenshot shows how
it works (it follows
https://github.com/nushell/nushell/issues/8248#issuecomment-1637442612):

![image](https://github.com/nushell/nushell/assets/22256154/b2c14760-3f27-41cc-af77-af70a4367f2a)

## About the change
1. To make module support const, we need to change `parse_module_block`
to support `const` keyword.
2. To suport export `const`, we need to make module tracking variables,
so we add `variables` attribute to `Module`
3. During eval, the const variable may not exists in `stack`, because we
don't eval `const` when we define a module, so we need to find variables
which are already registered in `engine_state`

## One more thing to note about the const value.
Consider the following code
```
module foo { const b = 3; export def bar [] { $b } }
use foo bar
const b = 4;
bar
```
The result will be 3 (which is defined in module) rather than 4. I think
it's expected behavior.

It's something like [dynamic
binding](https://www.gnu.org/software/emacs/manual/html_node/elisp/Dynamic-Binding-Tips.html)
vs [lexical
binding](https://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html)
in lisp like language, and lexical binding should be right behavior
which generates more predicable result, and it doesn't introduce really
subtle bugs in nushell code.

What if user want dynamic-binding?(For example: the example code returns
`4`)
There is no way to do this, user should consider passing the value as
argument to custom command rather than const.

## TODO
- [X] adding tests for the feature.
- [X] support export const out of module to use.

# 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` 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.
-->
2023-08-01 07:09:52 +08:00
Ian Manske
583ef8674e
Replace &Span with Span since Span is Copy (#9770)
# Description
`Span` is `Copy`, so we probably should not be passing references of
`Span` around. This PR replaces all instances of `&Span` with `Span`,
copying spans where necessary.

# User-Facing Changes
This alters some public functions to take `Span` instead of `&Span` as
input. Namely, `EngineState::get_span_contents`,
`nu_protocol::extract_value`, a bunch of the math commands, and
`Gstat::gstat`.
2023-07-31 21:47:46 +02:00
Han Junghyuk
ba0f069c31
Turn bare URLs into cliclable links (#9854)
This PR adds angle brackets to URLs, making them clickable when reading
documentation.
2023-07-30 22:50:25 +02:00
Darren Schroeder
955de76116
bump to dev version 0.83.2 (#9866)
# Description

This PR bumps the development version of nushell to version 0.83.2.
2023-07-30 22:16:57 +02:00
Stefan Holderbach
b2e191f836
Remove Signature.vectorizes_over_list entirely (#9777)
# Description
With the current typechecking logic this property has no effect.
It was only used in the example testing, and provided some indication of
this vectorizing property.
With #9742 all commands that previously declared it have explicit list
signatures. If we want to get it back in the future we can reconstruct
it from the signature.

Simplifies the example testing a bit.

# User-Facing Changes
Causes a breaking change for plugins that previously declared it. While
this causes a compile fail, this was already broken by our more
stringent type checking.
This will be a good reminder for plugin authors to update their
signature as well to reflect the more stringent type checking.
2023-07-26 23:34:43 +02:00
Darren Schroeder
88a890c11f
bump to dev version 0.83.1 (#9811)
# Description

This bumps nushell to the dev version of 0.83.1 and updates the default
config files with the proper version.

# User-Facing Changes
# Tests + Formatting
# After Submitting
2023-07-26 19:02:13 +02:00
JT
a33b5fe6ce
bump to 0.83 (#9802)
# Description

Bump 0.83

# 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` 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.
-->
2023-07-26 07:36:36 +12:00
Stefan Holderbach
2dcd1c5dbe
Abort type determination for List early (#9779)
# Description
If we reach the conclusion that the fields of a list are of `Type::Any`
there is no need to continue as the type will remain `Type::Any`

This should improve runtimes of `Value.get_type()` for lists with mixed
types.

# User-Facing Changes
None, a speedup in some cases.

# Tests + Formatting
Relies on existing tests
2023-07-24 07:15:53 +02:00
Ian Manske
7e1b922ea7
Add functions for each Value case (#9736)
# Description
This PR ensures functions exist to extract and create each and every
`Value` case. It also renames `Value::boolean` to `Value::bool` to match
`Value::test_bool`, `Value::as_bool`, and `Value::Bool`. Similarly,
`Value::as_integer` was renamed to `Value::as_int` to be consistent with
`Value::int`, `Value::test_int`, and `Value::Int`. These two renames can
be undone if necessary.

# User-Facing Changes
No user facing changes, but two public functions were renamed which may
affect downstream dependents.
2023-07-21 08:20:33 -05:00
Darren Schroeder
0b1e368cea
update history_isolation to false (#9763)
# Description

This PR follows #9762 and sets the rust component to match

# 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` 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.
-->
2023-07-21 06:58:32 -05:00
Antoine Stevan
345c00aa1e
sync default config / env with default behaviour without any configuration (#9676)
related PRs and issues
- supersedes https://github.com/nushell/nushell/pull/9633
- should close https://github.com/nushell/nushell/issues/9630

# Description
this PR updates the `default_config.nu` config file and the `config.rs`
module in `nu_protocol` so that the default behaviour of Nushell,
without any config, and the one with `default_config.nu` and
`default_env.nu` are the same.

## changelog
- 3e2bfc9bb: copy the structure of `default_config.nu` inside the
implementation of `Default` in the `config.rs` module for easier check
of the default values
- e25e5ccd6: sync all the *simple* config fields, i.e. the
non-structured ones
- ae7e8111c: set the `display_output` hook to always run `table`
- a09a1c564: leave only the default menus => i've removed
`commands_menu`, `vars_menu` and `commands_with_description`

## todo
- [x] ~~check the defaults in `$env.config.explore`~~ done in 173bdbba5
and b9622084c
- [x] ~~check the defaults in `$env.config.color_config`~~ done in
c411d781d => the theme is now `{}` by default so that it's the same as
the default one with `--no-config`
- [x] ~~check the defaults `$env.config.keybindings`~~ done in 715a69797
- already available with the selected mode: `completion_previous`,
`next_page`, `undo_or_previous_page`, `yank`, `unix-line-discard` and
`kill-line`, e.g. in *vi* mode, `unlix-line-discard` is done in NORMAL
mode with either `d0` from the end of the line or `dd` from anywhere in
the line and `kill-line` is done in NORMAL mode with `shift + d`. these
bindings are available by default in *emacs* mode as well.
- previously with removed custom menus: `commands_menu`, `vars_menu` and
`commands_with_description`
- [x] ~~check `$env.config.datetime_format`~~ done in 0ced6b8ec => as
there is no *human* format for datetimes, i've commented out both
`$env.config.datetime_format` fields
- [x] ~~fix `default_env.nu`~~ done in 67c215011

# User-Facing Changes
this should not change anything, just make sure the default behaviour of
Nushell and the `default_config.nu` are in sync.

# Tests + Formatting
# After Submitting
2023-07-18 11:22:00 -05:00
Stefan Holderbach
656f707a0b
Clean up tests containing unnecessary cwd: tokens (#9692)
# Description
The working directory doesn't have to be set for those tests (or would
be the default anyways). When appropriate also remove calls to the
`pipeline()` function. In most places kept the diff minimal and only
removed the superfluous part to not pollute the blame view. With simpler
tests also simplified things to make them more readable overall (this
included removal of the raw string literal).

Work for #8670
2023-07-17 18:43:51 +02:00
dependabot[bot]
48271d8c3e
Bump miette from 5.9.0 to 5.10.0 (#9713) 2023-07-17 06:25:04 +00:00
dependabot[bot]
60bb984e6e
Bump strum_macros from 0.24.3 to 0.25.1 (#9714) 2023-07-17 06:23:17 +00:00
mike
5bfec20244
add match guards (#9621)
## description

this pr adds [match
guards](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards)
to match patterns
```nushell
match $x {
   _ if $x starts-with 'nu' => {},
   $x => {}
}
```

these work pretty much like rust's match guards, with few limitations:

1. multiple matches using the `|` are not (yet?) supported
 
```nushell
match $num {
    0 | _ if (is-odd $num) => {},
    _ => {}
}
```

2. blocks cannot be used as guards, (yet?)

```nushell
match $num {
    $x if { $x ** $x == inf } => {},
     _ => {}
}
```

## checklist
- [x] syntax
- [x] syntax highlighting[^1]
- [x] semantics
- [x] tests
- [x] clean up

[^1]: defered for another pr
2023-07-16 12:25:12 +12:00
Jakub Žádník
ba766de5d1
Refactor path commands (#9687) 2023-07-15 00:04:22 +03:00
JT
786ba3bf91
Input output checking (#9680)
# Description

This PR tights input/output type-checking a bit more. There are a lot of
commands that don't have correct input/output types, so part of the
effort is updating them.

This PR now contains updates to commands that had wrong input/output
signatures. It doesn't add examples for these new signatures, but that
can be follow-up work.

# User-Facing Changes

BREAKING CHANGE BREAKING CHANGE

This work enforces many more checks on pipeline type correctness than
previous nushell versions. This strictness may uncover incompatibilities
in existing scripts or shortcomings in the type information for internal
commands.

# 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` 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.
-->
2023-07-14 15:20:35 +12:00
Jakub Žádník
e66139e6bb
Fix broken constants in scopes (#9679) 2023-07-14 00:02:05 +03:00
JT
30904bd095
Remove broken compile-time overload system (#9677)
# Description

This PR removes the compile-time overload system. Unfortunately, this
system never worked correctly because in a gradual type system where
types can be `Any`, you don't have enough information to correctly
resolve function calls with overloads. These resolutions must be done at
runtime, if they're supported.

That said, there's a bit of work that needs to go into resolving
input/output types (here overloads do not execute separate commands, but
the same command and each overload explains how each output type
corresponds to input types).

This PR also removes the type scope, which would give incorrect answers
in cases where multiple subexpressions were used in a pipeline.

# User-Facing Changes

Finishes removing compile-time overloads. These were only used in a few
places in the code base, but it's possible it may impact user code. I'll
mark this as breaking change so we can review.

# 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` 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.
-->
2023-07-14 07:05:03 +12:00
Stefan Holderbach
7c9edbd9ee
Bump deps to transitively use hashbrown 0.14 (#9668)
# Description
Update `lru` to `0.11`: `cargo build` will now not need `hashbrown 0.13`
Update `dashmap`: upgrades `hashbrown` for dev-dependency

-1 dependency in the `cargo install` path
2023-07-12 17:55:51 +02:00
Stefan Holderbach
bd0032898f
Apply nightly clippy lints (#9654)
# Description
- A new one is the removal of unnecessary `#` in raw strings without `"`
inside.
-
https://rust-lang.github.io/rust-clippy/master/index.html#/needless_raw_string_hashes
- The automatically applied removal of `.into_iter()` touched several
places where #9648 will change to the use of the record API. If
necessary I can remove them @IanManske to avoid churn with this PR.
- Manually applied `.try_fold` in two places
- Removed a dead `if`
- Manual: Combat rightward-drift with early return
2023-07-12 00:00:31 +02:00
dependabot[bot]
cf36f052c4
Bump strum from 0.24.1 to 0.25.0 (#9639) 2023-07-10 11:35:23 +00:00
Stefan Holderbach
a3702e1eb7
Bump indexmap to 2.0 (#9643)
# Description
Apart from `polars` (only used with `--features dataframe`) and the
dev-dependencies our deps use `indexmap 2.0`.
Thus the default or `extra` `cargo build` will reduce deps.
This also will help deduplicating `hashbrown` and `ahash`.

For #8060

- Bump `indexmap` to 2.0
- Remove unneeded `serde` feature from `indexmap`

# User-Facing Changes
None
2023-07-10 10:30:01 +02:00
mike
8e38596bc9
allow tables to have annotations (#9613)
# Description

follow up to #8529 and #8914

this works very similarly to record annotations, only difference being
that

```sh
table<name: string>
      ^^^^  ^^^^^^
      |     | 
      |     represents the type of the items in that column
      |
      represents the column name
```
more info on the syntax can be found
[here](https://github.com/nushell/nushell/pull/8914#issue-1672113520)

# User-Facing Changes

**[BREAKING CHANGE]**
this change adds a field to `SyntaxShape::Table` so any plugins that
used it will have to update and include the field. though if you are
unsure of the type the table expects, `SyntaxShape::Table(vec![])` will
suffice
2023-07-07 11:06:09 +02:00
mike
544c46e0e4
improve subtyping (#9614)
# Description

the current subtyping rule needs you to define the record entries in the
same order as declared in the annotation. this pr improves that

now
```nushell
{ name: 'Him', age: 12 } 

# ,

{ age: 100, name: 'It' }

# and

{ name: 'Red', age: 69, height: "5-8" }

# will all match

record<name: string, age: int>

# previously only the first one would match
```

however, something like

```nushell
{ name: 'Her' } # will not


# and

{ name: 'Car', wheels: 5 }
```

EDIT: applied JT's suggestion
2023-07-06 10:25:39 +02:00
Stefan Holderbach
881c3495c1
Exclude deprecated commands from completions (#9612)
# Description
We previously simply searched all commands in the working set. As our
deprecated/removed subcommands are documented by stub commands that
don't do anything apart from providing a message, they were still
included.
With this change we check the `Signature.category` to not be
`Category::Deprecated`.

## Note on performance
Making this change will exercise `Command.signature()` more
frequently! As the rust-implemented commands include their builders here
this probably will cause a number of extra allocations. There is
actually no valid reason why the commands should construct a new
`Signature` for each call to `Command.signature()`.
This will introduce some overhead to generate the completions for
commands.
# User-Facing Changes
Example: `str <TAB>`


![grafik](https://github.com/nushell/nushell/assets/15833959/4d5ec5fe-aa93-45af-aa60-3854a20fcb04)
2023-07-05 23:13:16 +02:00
JT
88b22a9248
fix a few clippy issues (#9578)
# Description

A couple clippy fixes

# 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 -A clippy::result_large_err` 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.
-->
2023-07-01 19:52:04 +12:00
JT
4af24363c2
remove let-env, focus on mutating $env (#9574)
# Description

For years, Nushell has used `let-env` to set a single environment
variable. As our work on scoping continued, we refined what it meant for
a variable to be in scope using `let` but never updated how `let-env`
would work. Instead, `let-env` confusingly created mutations to the
command's copy of `$env`.

So, to help fix the mental model and point people to the right way of
thinking about what changing the environment means, this PR removes
`let-env` to encourage people to think of it as updating the command's
environment variable via mutation.

Before:

```
let-env FOO = "BAR"
```

Now:

```
$env.FOO = "BAR"
```

It's also a good reminder that the environment owned by the command is
in the `$env` variable rather than global like it is in other shells.

# User-Facing Changes

BREAKING CHANGE BREAKING CHANGE

This completely removes `let-env FOO = "BAR"` so that we can focus on
`$env.FOO = "BAR"`.

# 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 -A clippy::result_large_err` 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 / Before Submitting
integration scripts to update:
- ✔️
[starship](https://github.com/starship/starship/blob/master/src/init/starship.nu)
- ✔️
[virtualenv](https://github.com/pypa/virtualenv/blob/main/src/virtualenv/activation/nushell/activate.nu)
- ✔️
[atuin](https://github.com/ellie/atuin/blob/main/atuin/src/shell/atuin.nu)
(PR: https://github.com/ellie/atuin/pull/1080)
- 
[zoxide](https://github.com/ajeetdsouza/zoxide/blob/main/templates/nushell.txt)
(PR: https://github.com/ajeetdsouza/zoxide/pull/587)
- ✔️
[oh-my-posh](https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/src/shell/scripts/omp.nu)
(pr: https://github.com/JanDeDobbeleer/oh-my-posh/pull/4011)
2023-07-01 07:57:51 +12:00
JT
9068093081
Improve type hovers (#9515)
# Description

This PR does a few things to help improve type hovers and, in the
process, fixes a few outstanding issues in the type system. Here's a
list of the changes:

* `for` now will try to infer the type of the iteration variable based
on the expression it's given. This fixes things like `for x in [1, 2, 3]
{ }` where `x` now properly gets the int type.
* Removed old input/output type fields from the signature, focuses on
the vec of signatures. Updated a bunch of dataframe commands that hadn't
moved over. This helps tie things together a bit better
* Fixed inference of types from subexpressions to use the last
expression in the block
* Fixed handling of explicit types in `let` and `mut` calls, so we now
respect that as the authoritative type

I also tried to add `def` input/output type inference, but unfortunately
we only know the predecl types universally, which means we won't have
enough information to properly know what the types of the custom
commands are.

# User-Facing Changes

Script typechecking will get tighter in some cases
Hovers should be more accurate in some cases that previously resorted to
any.

# 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 -A clippy::result_large_err` 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.
-->

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-06-29 05:19:48 +12:00
Stefan Holderbach
088e6dffbe
Bump to 0.82.1 dev version (#9543)
# Description
Marks development or hotfix
2023-06-27 21:33:53 +02:00
Stefan Holderbach
ecdb023e2f
Bump version for 0.82.0 release (#9530)
# Checklist

- `nu-ansi-term` remains the same
- [x] `reedline` is released and updated
- [x] release scripts are updated for `nu-cmd-base`
- [x] info blog post is online
- [ ] release notes are ready
2023-06-27 19:11:46 +02:00
Taylor C. Richberger
08449e174c
Format negative datetimes with rfc3339 (#9501) (#9502)
- fixes #9501 

# Description

`chrono::Datetime::to_rfc2822()` panics when it would format a negative
year. 3339 does not. This makes negative-year datetimes inconsistent
compared to positive ones, but it's better than a panic.
2023-06-25 13:53:17 -05:00
Stefan Holderbach
971f9ae0f0
Skip strum in regular nu-protocol build (#9445)
# Description
`derive(EnumIter)` is only required to run completeness tests.
Thus make the derive conditional on test and move `strum` and
`strum_macros` to the dev dependencies.

## Is it worth it?

Removing this derive does not change the binary size (checked via `cargo
bloat --crates` from `cargo-bloat`).
Compile time change is below a second so hard to judge based on a single
run of `cargo clean --profile dev; cargo build --timings`
Unsure if this negatively impacts how incremental compilation can
recompile when you switch between `cargo build`/`run` and `cargo test`
in your local workflow.

To get rid of `strum`/`strum_macros` as a proc macro crate we would need
to also remove it from `reedline`.
Further more a crate in the `polars` dependency tree uses `strum`
(curently not as relevant for the 1.0 build).
2023-06-25 20:28:37 +02:00
JT
33535c514e
Better error message if env var is used as var (#9522)
# Description

This PR improves the error message if an environment variable (that's
visible before the parser begins) is used in the form of `$PATH` instead
of `$env.PATH`.

Before:

```
Error: nu::parser::variable_not_found

  × Variable not found.
   ╭─[entry #31:1:1]
 1 │ echo $PATH
   ·      ──┬──
   ·        ╰── variable not found.
   ╰────
```

After:

```
Error: nu::parser::env_var_not_var

  × Use $env.PATH instead of $PATH.
   ╭─[entry #1:1:1]
 1 │ echo $PATH
   ·      ──┬──
   ·        ╰── use $env.PATH instead of $PATH
   ╰────
```

# User-Facing Changes

Just the improvement to the error message

# 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 -A clippy::result_large_err` 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.
-->
2023-06-26 05:59:56 +12:00
WMR
0c888486c9
Add custom datetime format through strftime strings (#9500)
- improves usability of datetime's in displayed text
- 
# Description
Creates a config point for specifying long / short date time formats.
Defaults to humanized as we have today.

Provides for adding strftime formats into config.nu such as:
```nu
  datetime_format: {
    normal: "%Y-%m-%d %H:%M:%S"
    table: "%Y-%m-%d"
  }
```

Example:
```bash
> $env.config.datetime_format                                                                                                                         
┏━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ normal ┃ %a, %d %b %Y %H:%M:%S %z ┃
┃ table  ┃ %m/%d/%y %I:%M:%S%p      ┃
┗━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━┛
> let a = (date now)                                                                                                                                  
> echo $a                                                                                                                                             
Thu, 22 Jun 2023 10:21:23 -0700
> echo [$a]                                                                                                                                           
┏━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ 0 ┃ 06/22/23 10:21:23AM ┃
┗━━━┻━━━━━━━━━━━━━━━━━━━━━┛
```

# User-Facing Changes
Any place converting a datetime to a user displayed value should be
impacted.

# Tests + Formatting

- `cargo fmt --all -- --check` Done
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` Done
- `cargo test --workspace` Done 
- `cargo run -- crates/nu-std/tests/run.nu` Not done - doesn't seem to
work

```bash
> use toolkit.nu  # or use an `env_change` hook to activate it automatically
> toolkit check pr
``` - Done

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
2023-06-23 15:05:04 -05:00
Darren Schroeder
cbb9f8efe4
clean up config by removing legacy options (#9496)
# Description

This PR cleans up the deprecated legacy config options that were
deprecated in nushell version 0.72.0. These are the config points that
were in the root of the config but also duplicated in the nested
structures. For instance `use_ls_colors` was in the root of the config
and also in the `ls.use_ls_colors` nested structure. This was originally
done to preserve backwards compatibility when nested structures were
introduced in the config file.

Here's a list of the legacy config points that were removed.

- `use_ls_colors` - previously replaced with `ls.use_ls_colors`
- `rm_always_trash` - previously replaced with `rm.always_trash`
- `history_file_format` - previously replaced with `history.file_format`
- `sync_history_on_enter` - previously replaced with
`history.sync_on_enter`
- `max_history_size` - previously replaced with `history.max_size`
- `quick_completions` - previously replaced with `completions.quick`
- `partial_completions` - previously replaced with `completions.partial`
- `max_external_completion_results` - previously replaced with
`completions.external.max_results`
- `completion_algorithm` - previously replaced with
`completions.algorithm`
- `case_sensitive_completions` - previously replaced with
`completions.case_sensitive`
- `enable_external_completion` - previously replaced with
`completions.external.enable`
- `external_completer` - previously replaced with
`completions.external.completer`
- `table_mode` - previously replaced with `table.mode`
- `table_index_mode` - previously replaced with `table.index_mode`
- `table_trim` - previously replaced with `table.trim`
- `show_clickable_links_in_ls` - previously replaced with
`ls.clickable_links`
- `cd_with_abbreviations` - previously replaced with `cd.abbreviations`
- `filesize_metric` - previously replaced with `filesize.metric`
- `filesize_format` - previously replaced with `filesize.format`
- `cursor_shape_vi_insert` - previously replaced with
`cursor_shape.vi_insert`
- `cursor_shape_vi_normal` - previously replaced with
`cursor_shape.vi_normal`
- `cursor_shape_emacs` - previously replaced with `cursor_shape.emacs`

Removes log_level from the config since it doesn't do anything any
longer. We moved log-level to a nushell parameter some time ago.

Renames history_isolation to isolation in the config.nu for consistency.

Fixes a couple bugs where values weren't being set in the "//
Reconstruct" sections (history_isolation, table_show_empty).

Reorganized/Moved things around a tiny bit and added a few comments.

# User-Facing Changes

history.histor_isolation is now history.isolation.
If anyone is still using the legacy config points, deprecated since
0.72.0 2022-11-29, their config will break.

# 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 -A clippy::result_large_err` 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.
-->
2023-06-23 06:17:10 -05:00
Stefan Holderbach
1be4eaeae3
Revert #8395 "Treat empty pipelines as pass-through" (#9472)
In my view we should revert nushell/nushell#8395 for now

## Potentially inconsistent application of semantic change
#8395 (1d5e7b441b) was loosening the type
coercion rules significantly, to let missing data / void returns that
were either expressed by `PipelineData::Empty` or the `Value::nothing`
be accept by specifically those commands/operations that made use of
`PipelineData::into_iter_strict()`. This could apply the new rules
inconsistently.

## Turning explicit failures into silent continuations
Furthermore the effect of this breaking change to the missing data
semantics could make previous errors into silent failures.
This could either just reduce the effectiveness of teaching error
messages in interactive use:

### Contrived example before
```bash
> cd . | where blah
Error: nu:🐚:only_supports_this_input_type

  × Input type not supported.
   ╭─[entry #13:1:1]
 1 │ cd . | where blah
   ·        ──┬──┬
   ·          │  ╰── input type: null
   ·          ╰── only list, binary, raw data or range input data is supported
   ╰────
```
### ...after, with #8395
```bash
> cd . | where blah
╭────────────╮
│ empty list │
╰────────────╯
```

In rare cases people could already try to rely on catching an error of a
downstream command to actually deal with the missing data, so it would
be a breaking change for their existing code.

## Problem with `PipelineData::into_iter_strict()`

Maybe this makes `_strict` a bit of a misnomer for this particular
iterator construction.
Further we did not actively test the `PipelineData::empty` branch before

![grafik](https://github.com/nushell/nushell/assets/15833959/c377bf1d-d47c-4c25-a342-9a348539f242)

## Parsimonious solution exists

For the motivating issue https://github.com/nushell/nushell/issues/8393
there already exists a fix that makes `ls` more consistent with the type
system by returning an empty `Value::List`
https://github.com/nushell/nushell/pull/8439
2023-06-20 20:27:18 +12:00
JT
1d5e7b441b
Treat empty pipelines as pass-through (#8395)
# Description

This allows empty pipelines to pass their emptiness through a filter.
This helps fix issues like trying to run a filter on an `ls` in an empty
directory. It also feels a bit more reasonable that a filter filters
what is *there* but doesn't require something to be there.

fixes #8393

# User-Facing Changes

No breaking changes (that I know of). Should allow filtering to be a
little less surprising with emptiness.

# 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

# 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.

---------

Co-authored-by: amtoine <stevan.antoine@gmail.com>
2023-06-18 11:40:18 +02:00
Michael Albers
c12b211075
Fix missing file names from rm errors (#9120)
# Description
Fixes a small bug with `rm` where names of files which couldn't be
deleted due to error were not printed.

Fixes https://github.com/nushell/nushell/issues/9004

# User-Facing Changes
Slightly different error message than previously. Nothing significant,
though.

The new error message looks like this
```
~/Projects/rust/nushell> rm /proc/1/mem                                                                                                                                                            05/06/2023 01:13:23 PM
Error: nu:🐚:remove_not_possible

  × Remove not possible
   ╭─[entry #3:1:1]
 1 │ rm /proc/1/mem
   ·    ─────┬─────
   ·         ╰── Could not delete /proc/1/mem: Operation not permitted (os error 1)
   ╰────

```

or when using a glob (only showing a single entry for brevity)

```
Error: nu:🐚:remove_not_possible

  × Remove not possible
   ╭─[entry #2:1:1]
 1 │ rm --recursive --force --verbose /proc/1/*
   ·                                  ────┬────
   ·                                      ╰── Could not delete /proc/1/comm: Operation not permitted (os error 1)
   ╰────
```

# Tests + Formatting
No new unit tests were added for this change as it is pretty difficult
to test this particular case. However, manual testing was run with the
following commands

```
rm /proc/1/mem
rm --recursive --force --verbose /proc/1/*
```

# After Submitting
N/A
2023-06-18 10:00:12 +02:00
JT
6c730def4b
revert: move to ahash (#9464)
This PR reverts https://github.com/nushell/nushell/pull/9391

We try not to revert PRs like this, though after discussion with the
Nushell team, we decided to revert this one.

The main reason is that Nushell, as a codebase, isn't ready for these
kinds of optimisations. It's in the part of the development cycle where
our main focus should be on improving the algorithms inside of Nushell
itself. Once we have matured our algorithms, then we can look for
opportunities to switch out technologies we're using for alternate
forms.

Much of Nushell still has lots of opportunities for tuning the codebase,
paying down technical debt, and making the codebase generally cleaner
and more robust. This should be the focus. Performance improvements
should flow out of that work.

Said another, optimisation that isn't part of tuning the codebase is
premature at this stage. We need to focus on doing the hard work of
making the engine, parser, etc better.

# User-Facing Changes

Reverts the HashMap -> ahash change.

cc @FilipAndersson245
2023-06-18 15:27:57 +12:00
Brian London
d00a040da9
Plugin api docs (#9452)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
<!--
Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.

Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.
-->

Added comments to support API docs for the `nu-plugin` crate. Removed a
few items that I'd expect should only be used internally to Nushell from
the documentation and reduced the visibility of some items that did not
need to be public.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
There should be no user facing impact.

# 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 -A clippy::result_large_err` 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
> ```
-->

Standard tests run. Additionally numerous doctests were added to the
`nu-plugin` crate.

# 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.
-->

No changes to the website necessary.
2023-06-16 16:25:40 +02:00
Han Junghyuk
b14bdd865f
Remove ZB and ZiB from file size type (#9427)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
<!--
Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.

Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.
-->
This PR removes ZB and ZiB from file size type, as they 
were showing incorrect values due to an integer overflow.

Fixes: #9337
# 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 -A clippy::result_large_err` 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.
-->
2023-06-14 10:53:32 -05:00
Steven Xu
be53ecbbaa
refactor: merge repl_buffer_state, repl_cursor_pos into one mutex (#9031)
# Description
Merge `repl_buffer_state`, `repl_cursor_pos` into one mutex.

# User-Facing Changes

# Tests + Formatting

# After Submitting
2023-06-10 17:38:11 -05:00
Filip Andersson
1433f4a520
Changes HashMap to use aHash instead, giving a performance boost. (#9391)
# Description

see https://github.com/nushell/nushell/issues/9390
using `ahash` instead of the default hasher. this will not affect
compile time as we where already building `ahash`.


# 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 -A clippy::result_large_err` 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.
-->
2023-06-10 11:41:58 -05:00
Stefan Holderbach
d15859dd86
Bump to 0.81.1 as development version (#9379)
# Description
Primarily used as a marker on issues and if necessary as a patch release
version.
2023-06-07 15:06:42 +02:00
JT
63cb01e83b
bump to 0.81 (#9374)
# Description
<!--
Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.

Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.
-->

# 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 -A clippy::result_large_err` 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.
-->
2023-06-07 10:08:11 +12:00
Jakub Žádník
82e6873702
Fix config creation during printing (#9353) 2023-06-04 22:04:28 +03:00
WindSoilder
bfe7133e7c
make insert, update, upsert support lazy records (#9323)
# Description
Fixes: #9165
It's because `sys` returns a lazy record, and `insert`, `update`,
`upsert` can't operate on lazy record yet.

# User-Facing 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 -A clippy::result_large_err` 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.
-->
2023-05-31 06:27:55 -05:00
Maxim Zhiburt
7f758d3e51
Merge stack before printing (#9304)
Could you @fdncred try it?

close?: #9264

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2023-05-29 19:03:00 -05:00
Darren Schroeder
5f92fd20e9
update most dependencies except where deeper code changes are needed (#9296)
# Description

This PR updates most dependencies and tries to get in sync with
reedline.

# 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 -A clippy::result_large_err` 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.
-->
2023-05-26 10:32:48 -05:00