Commit graph

9809 commits

Author SHA1 Message Date
zc he
0b71eb201c
fix(lsp): PWD env_var (#14805)
<!--
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 fixes an issue introduced by #14770 , as shown in
https://github.com/nushell/nushell/pull/14802#issuecomment-2585270161

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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.
-->
2025-01-11 08:03:53 -06:00
Darren Schroeder
707ab1df6a
bump to rust version 1.82 (#14795)
# Description

The PR follows our standard of bumping the rust compiler when a new one
is released.

/cc @ayax79 @sholderbach

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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.
-->
2025-01-11 07:14:55 -06:00
zc he
c811d86dbd
feat(lsp): inlay hints of variable types and command params (#14802)
<!--
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 adds inlay hints of variable types and parameter names to
lsp-server
<img width="547" alt="image"
src="https://github.com/user-attachments/assets/07a0dd84-5ecc-47df-a8a7-732631715662"
/>

Some design choices I made:
* for composite types like `record<foo: <record ...>>`, only a short
name displayed. Full signature already available through `hover`
* only parameter names of user defined commands are returned, feels too
much distraction if enabled for all builtins
* some information are lost in flattened expressions, so I implemented
my AST traversing functions, which may seem unnecessary, but I can't
find alternatives from the existing code.
* another minor change: added a line separator to current hover markdown
message.

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

Users who think this feature annoying now have to manually turn it off
(or config the lsp client capabilities).

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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.
-->
2025-01-11 07:13:55 -06:00
Justin Ma
902e6d7a27
Do not trigger release WF on nightly tags (#14803)
<!--
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.
-->

Don't trigger release for nightly tags, more context could be found
here: https://github.com/nushell/nightly/issues/35
2025-01-11 07:00:28 -06:00
zc he
827e31191d
fix: unknown span for special variables $in/$it (#14789)
<!--
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 addresses the issue of inconsistent spans of special variables
of `$in/$in`, as discussed in
https://github.com/nushell/nushell/pull/14770#discussion_r1908729364.

Instead of making the `declaration_span` to be Option, which will cause
too many changes that we may want to avoid, this PR set the spans to be
`unknown`.


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

No

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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.
-->
2025-01-11 06:53:08 -06:00
Piepmatz
b9b3101bd9
Let table only check for use_ansi_coloring config value (#14798)
<!--
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 the `std::io::stdout().is_terminal()` check in `table`
again. To ensure that in the future this doesn't happen again, I added a
comment and a test.

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

Resets the behavior of `table` to #14647 again, after #14415 included it
again.

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->

Added a new test to check for these color outputs.

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# 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.
-->
2025-01-10 19:24:16 -06:00
Piepmatz
8e8a60a432
Add "whereis" and "get-command" to which search terms (#14797)
<!--
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.
-->

Today i saw in the general discord channel someone ask what is the
nushell equivalent of `whereis` or `get-command`. I wanted to tell the
user to use our great search via F1 but then I realized that typing in
`whereis` or `get-command` wouldn't really find you something. So I
added these two search terms.

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

None.

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->

I don't think that really needs testing here :D

# 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.
-->
2025-01-10 17:55:41 -06:00
Douglas
72d50cf8b7
Convert Path to list in main and preserve case (#14764)
# Description

Fixes multiple issues related to `ENV_CONVERSION` and
path-conversion-to-list.

* #14681 removed some calls to `convert_env_values()`, but we found that
this caused `nu -n` to no longer convert the path properly.
* `ENV_CONVERSIONS` have apparently never preserved case, meaning a
conversion with a key of `foo` would not update `$env.FOO` but rather
create a new environment variable with a different case.
* There was a partial code-path that attempted to solve this for `PATH`,
but it only worked for `PATH` and `Path`.
* `convert_env_values()`, which handled `ENV_CONVERSIONS` was called in
multiple places in the startup depending on flags.

This PR:

* Refactors the startup to handle the conversion in `main()` rather than
in each potential startup path
* Updates `get_env_var_insensitive()` functions added in #14390 to
return the name of the environment variable with its original case. This
allows code that updates environment variables to preserve the case.
* Makes use of the updated function in `ENV_CONVERSIONS` to preserve the
case of any updated environment variables. The `ENV_CONVERSION` key
itself is still case **insensitive**.
* Makes use of the updated function to preserve the case of the `PATH`
environment variable (normally handled separately, regardless of whether
or not there was an `ENV_CONVERSION` for it).

## Before

`env_convert_values` was run:

* Before the user `env.nu` ran, which included `nu -c <commandstring>`
and `nu <script.nu>`
* Before the REPL loaded, which included `nu -n`

## After

`env_convert_values` always runs once in `main()` before any config file
is processed or the REPL is started

# User-Facing Changes

Bug fixes

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

Added additional tests to prevent future regression.

# After Submitting

There is additional cleanup that should probably be done in
`convert_env_values()`. This function previously handled
`ENV_CONVERSIONS`, but there is no longer any need for this since
`convert_env_vars()` runs whenever `$env.ENV_CONVERSIONS` changes now.

This means that the only relevant task in the old `convert_env_values()`
is to convert the `PATH` to a list, and ensure that it is a list of
strings. It's still calling the `from_string` conversion on every
variable (just once) even though there are no `ENV_CONVERSIONS` at this
point.

Leaving that to another PR though, while we get the core issue fixed
with this one.
2025-01-10 10:18:44 -06:00
132ikl
3a1601de8e
Add flag to debug profile to output duration field as Value::Duration (#14749)
<!--
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 adds a flag to `debug profile` to output the duration field as
Value::Duration. Without the flag, the behavior is same as before: a
column named `duration_ms` which is `Value::Float`. With the flag, there
is instead a column named just `duration` which is `Value::Duration`.
Additionally, this PR changes the time tracking to use nanoseconds
instead of float seconds, so it can be output as either milliseconds or
`Duration` (which uses nanoseconds internally). I don't think overflow
is a concern here, because the maximum amount of time a `Duration` can
store is over 292 years, and if a Nushell instruction takes longer than
that to run then I think we might have bigger issues.

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

* Adds a flag `--duration-values` to `debug profile` which the
`duration_ms` field in `debug profile` to a `duration` field which uses
proper `duration` values.

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# 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.
-->
N/A
2025-01-09 17:09:16 -06:00
zc he
3f8dd1b705
feat(lsp): document_symbols and workspace_symbols (#14770)
<!--
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 adds symbols related features to lsp
<img width="940" alt="image"
src="https://github.com/user-attachments/assets/aeaed338-133c-430a-b966-58a9bc445211"
/>

Notice that symbols of type variable may got filtered by client side
plugins

<img width="906" alt="image"
src="https://github.com/user-attachments/assets/e031b3dc-443a-486f-8a35-4415c07196d0"
/>


# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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.
-->
2025-01-09 07:19:32 -06:00
dependabot[bot]
f360489f1e
Bump tempfile from 3.14.0 to 3.15.0 (#14777)
Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.14.0 to
3.15.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md">tempfile's
changelog</a>.</em></p>
<blockquote>
<h2>3.15.0</h2>
<p>Re-seed the per-thread RNG from system randomness when we repeatedly
fail to create temporary files (<a
href="https://redirect.github.com/Stebalien/tempfile/issues/314">#314</a>).
This resolves a potential DoS vector (<a
href="https://redirect.github.com/Stebalien/tempfile/issues/178">#178</a>)
while avoiding <code>getrandom</code> in the common case where it's
necessary. The feature is optional but enabled by default via the
<code>getrandom</code> feature.</p>
<p>For libc-free builds, you'll either need to disable this feature or
opt-in to a different <a
href="https://github.com/rust-random/getrandom?tab=readme-ov-file#opt-in-backends"><code>getrandom</code>
backend</a>.</p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="e7a40e3731"><code>e7a40e3</code></a>
Release v3.15.0</li>
<li><a
href="ea45f476d7"><code>ea45f47</code></a>
feat: re-seed from system randomness on collision (<a
href="https://redirect.github.com/Stebalien/tempfile/issues/314">#314</a>)</li>
<li><a
href="16209da6e6"><code>16209da</code></a>
Fix link to ticket in changelog (<a
href="https://redirect.github.com/Stebalien/tempfile/issues/310">#310</a>)</li>
<li><a
href="ae22b273a1"><code>ae22b27</code></a>
docs: add owasp link on insecure temporary files (<a
href="https://redirect.github.com/Stebalien/tempfile/issues/309">#309</a>)</li>
<li>See full diff in <a
href="https://github.com/Stebalien/tempfile/compare/v3.14.0...v3.15.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=tempfile&package-manager=cargo&previous-version=3.14.0&new-version=3.15.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-01-09 13:51:08 +01:00
Bahex
79f19f2fc7
Enable conditional source and use patterns by allowing null as a no-op module (#14773)
Related:
- #14329
- #13872
- #8214

# Description & User-Facing Changes

This PR allows enables the following uses, which are all no-op.
```nushell
source null
source-env null
use null
overlay use null
```

The motivation for this change is conditional sourcing of files. For
example, with this change `login.nu` may be deprecated and replaced with
the following code in `config.nu`
```nushell
const login_module = if $nu.is-login { "login.nu" } else { null }
source $login_module
```

# Tests + Formatting
I'm hoping for CI to pass 😄

# After Submitting
Add a part about the conditional sourcing pattern to the website.
2025-01-09 06:37:27 -06:00
132ikl
5cf6dea997
Remove file accidentally re-introduced by merge (#14785)
<!--
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.
-->

Re-removes the tests for `split_by`, which was removed in #14726 and
accidentally re-introduced by #14741

cc @fdncred 

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

N/A

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->

N/A

# 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.
-->
N/A
2025-01-08 17:24:31 -06:00
132ikl
214714e0ab
Add run-time type checking for command pipeline input (#14741)
<!--
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 adds type checking of all command input types at run-time.
Generally, these errors should be caught by the parser, but sometimes we
can't know the type of a value at parse-time. The simplest example is
using the `echo` command, which has an output type of `any`, so
prefixing a literal with `echo` will bypass parse-time type checking.

Before this PR, each command has to individually check its input types.
This can result in scenarios where the input/output types don't match
the actual command behavior. This can cause valid usage with an
non-`any` type to become a parse-time error if a command is missing that
type in its pipeline input/output (`drop nth` and `history import` do
this before this PR). Alternatively, a command may not list a type in
its input/output types, but doesn't actually reject that type in its
code, which can have unintended side effects (`get` does this on an
empty pipeline input, and `sort` used to before #13154).

After this PR, the type of the pipeline input is checked to ensure it
matches one of the input types listed in the proceeding command's
input/output types. While each of the issues in the "before this PR"
section could be addressed with each command individually, this PR
solves this issue for _all_ commands.

**This will likely cause some breakage**, as some commands have
incorrect input/output types, and should be adjusted. Also, some scripts
may have erroneous usage of commands. In writing this PR, I discovered
that `toolkit.nu` was passing `null` values to `str join`, which doesn't
accept nothing types (if folks think it should, we can adjust it in this
PR or in a different PR). I found some issues in the standard library
and its tests. I also found that carapace's vendor script had an
incorrect chaining of `get -i`:

```nushell
let expanded_alias = (scope aliases | where name == $spans.0 | get -i 0 | get -i expansion)
```

Before this PR, if the `get -i 0` ever actually did evaluate to `null`,
the second `get` invocation would error since `get` doesn't operate on
`null` values. After this PR, this is immediately a run-time error,
alerting the user to the problematic code. As a side note, we'll need to
PR this fix (`get -i 0 | get -i expansion` -> `get -i 0.expansion`) to
carapace.

A notable exception to the type checking is commands with input type of
`nothing -> <type>`. In this case, any input type is allowed. This
allows piping values into the command without an error being thrown. For
example, `123 | echo $in` would be an error without this exception.
Additionally, custom types bypass type checking (I believe this also
happens during parsing, but not certain)

I added a `is_subtype` method to `Value` and `PipelineData`. It
functions slightly differently than `get_type().is_subtype()`, as noted
in the doccomments. Notably, it respects structural typing of lists and
tables. For example, the type of a value `[{a: 123} {a: 456, b: 789}]`
is a subtype of `table<a: int>`, whereas the type returned by
`Value::get_type` is a `list<any>`. Similarly, `PipelineData` has some
special handling for `ListStream`s and `ByteStream`s. The latter was
needed for this PR to work properly with external commands.

Here's some examples.

Before:
```nu
1..2 | drop nth 1
Error: nu::parser::input_type_mismatch

  × Command does not support range input.
   ╭─[entry #9:1:8]
 1 │ 1..2 | drop nth 1
   ·        ────┬───
   ·            ╰── command doesn't support range input
   ╰────

echo 1..2 | drop nth 1
# => ╭───┬───╮
# => │ 0 │ 1 │
# => ╰───┴───╯
```

After this PR, I've adjusted `drop nth`'s input/output types to accept
range input.

Before this PR, zip accepted any value despite not being listed in its
input/output types. This caused different behavior depending on if you
triggered a parse error or not:
```nushell
1 | zip [2]
# => Error: nu::parser::input_type_mismatch
# => 
# =>   × Command does not support int input.
# =>    ╭─[entry #3:1:5]
# =>  1 │ 1 | zip [2]
# =>    ·     ─┬─
# =>    ·      ╰── command doesn't support int input
# =>    ╰────
echo 1 | zip [2]
# => ╭───┬───────────╮
# => │ 0 │ ╭───┬───╮ │
# => │   │ │ 0 │ 1 │ │
# => │   │ │ 1 │ 2 │ │
# => │   │ ╰───┴───╯ │
# => ╰───┴───────────╯
```

After this PR, it works the same in both cases. For cases like this, if
we do decide we want `zip` or other commands to accept any input value,
then we should explicitly add that to the input types.
```nushell
1 | zip [2]
# => Error: nu::parser::input_type_mismatch
# => 
# =>   × Command does not support int input.
# =>    ╭─[entry #3:1:5]
# =>  1 │ 1 | zip [2]
# =>    ·     ─┬─
# =>    ·      ╰── command doesn't support int input
# =>    ╰────
echo 1 | zip [2]
# => Error: nu:🐚:only_supports_this_input_type
# => 
# =>   × Input type not supported.
# =>    ╭─[entry #14:2:6]
# =>  2 │ echo 1 | zip [2]
# =>    ·      ┬   ─┬─
# =>    ·      │    ╰── only list<any> and range input data is supported
# =>    ·      ╰── input type: int
# =>    ╰────
```

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

**Breaking change**: The type of a command's input is now checked
against the input/output types of that command at run-time. While these
errors should mostly be caught at parse-time, in cases where they can't
be detected at parse-time they will be caught at run-time instead. This
applies to both internal commands and custom commands.

Example function and corresponding parse-time error (same before and
after PR):
```nushell
def foo []: int -> nothing {
  print $"my cool int is ($in)"
}

1 | foo
# => my cool int is 1

"evil string" | foo
# => Error: nu::parser::input_type_mismatch
# => 
# =>   × Command does not support string input.
# =>    ╭─[entry #16:1:17]
# =>  1 │ "evil string" | foo
# =>    ·                 ─┬─
# =>    ·                  ╰── command doesn't support string input
# =>    ╰────
# => 
```

Before:
```nu
echo "evil string" | foo
# => my cool int is evil string
```

After:
```nu
echo "evil string" | foo
# => Error: nu:🐚:only_supports_this_input_type
# => 
# =>   × Input type not supported.
# =>    ╭─[entry #17:1:6]
# =>  1 │ echo "evil string" | foo
# =>    ·      ──────┬──────   ─┬─
# =>    ·            │          ╰── only int input data is supported
# =>    ·            ╰── input type: string
# =>    ╰────
```

Known affected internal commands which erroneously accepted any type:
* `str join`
* `zip`
* `reduce`

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`


# 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.
-->
* Play whack-a-mole with the commands and scripts this will inevitably
break
2025-01-08 23:09:47 +01:00
Stefan Holderbach
d894c8befe
Bump typos workflow to 1.29.4 (#14782)
Fix garbage name to snakecase

Supersedes #14779
2025-01-08 15:11:47 +01:00
dependabot[bot]
cc4d4acc6b
Bump git2 from 0.19.0 to 0.20.0 (#14776) 2025-01-08 13:53:02 +00:00
Piepmatz
dc52a6fec5
Handle permission denied error at nu_engine::glob_from (#14679)
<!--
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.
-->

#14528 mentioned that trying to `open` a file in a directory where you
don't have read access results in a "file not found" error. I
investigated the error and could find the root issue in the
`nu_engine::glob_from` function. It uses `std::path::Path::canonicalize`
some layers down and that may return an `std::io::Error`. All these
errors were handled as "directory not found" which will be translated to
"file not found" in the `open` command. To fix this, I handled the
`PermssionDenied` error kind of the io error and passed that down. Now
trying to `open` a file from a directory with no permissions returns a
"permission denied" error.

Before/After:

![image](https://github.com/user-attachments/assets/168cea24-36a6-4c66-98c9-f7ccfa2ea826)

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

That error is fixed, so correct 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

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

fixes #14528
2025-01-07 15:44:55 -06:00
Bahex
16e174be7e
fix nuon conversions of range values (#14687)
# Description
Currently the step size of range values are discarded when converting to
nuon. This PR fixes that and makes `to nuon | from nuon` round trips
work.

# User-Facing Changes
`to nuon` conversion of `range` values now include the step size

# Tests + Formatting
Added some additional tests to cover inclusive/exclusive integer/float
and step size cases.
2025-01-07 21:29:39 +01:00
Chetan
8e41a308cd
fix(explore): handle zero-size cursor in binary viewer (#14592)
# Description
Fix cursor panic when handling size zero in binary viewer. Previously,
the cursor would panic
with arithmetic overflow when handling size 0. This PR fixes this by
using `saturating_sub`
to safely handle the edge case of size 0.

Fixes #14589

# User-Facing Changes
- Fixed panic when viewing very small binary inputs in the explore
command (when using `0x[f] | explore`)

# Tests + Formatting
Added tests to verify:
- Cursor handling of size 0
- Safe movement operations with size 0
- Edge case handling with size 1

 Verified all checks pass:
- `cargo fmt --all -- --check`
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used`
- `cargo test --package nu-explore --lib cursor`
2025-01-07 12:10:25 -06:00
Yash Thakur
787f292ca7
Custom completions: Inherit case_sensitive option from $env.config (#14738)
# Description

Currently, if a custom completer returns a record containing an
`options` field, but these options don't specify `case_sensitive`,
`case_sensitive` will be true. This PR instead makes the default value
whatever the user specified in `$env.config.completions.case_sensitive`.

The match algorithm option already does this. `positional` is also
inherited from the global config, although user's can't actually specify
that one themselves in `$env.config` (I'm planning on getting rid of
`positional` in a separate PR).

# User-Facing Changes

For those making custom completions, if they need matching to be done
case-sensitively and:
- their completer returns a record rather than a list,
- and the record contains an `options` field,
- and the `options` field is a record,
- and the record doesn't contain a `case_sensitive` option,

then they will need to specify `case_sensitive: true` in their custom
completer's options. Otherwise, if the user sets
`$env.config.completions.case_sensitive = false`, their custom completer
will also use case-insensitive matching.

Others shouldn't have to make any changes.

# Tests + Formatting

Updated tests to check if `case_sensitive`. Basically rewrote them,
actually. I figured it'd be better to make a single helper function that
takes completer options and completion suggestions and generates a
completer from that rather than having multiple fixtures providing
different completers.

# After Submitting

Probably needs to be noted in the release notes, but I don't think the
[docs](https://www.nushell.sh/book/custom_completions.html#options-for-custom-completions)
need to be updated.
2025-01-07 11:52:31 -06:00
Darren Schroeder
dad956b2ee
more closure serialization (#14698)
# Description

This PR introduces a switch `--serialize` that allows serializing of
types that cannot be deserialized. Right now it only serializes closures
as strings in `to toml`, `to json`, `to nuon`, `to text`, some indirect
`to html` and `to yaml`.

A lot of the changes are just weaving the engine_state through calling
functions and the rest is just repetitive way of getting the closure
block span and grabbing the span's text.

In places where it has to report `<Closure 123>` I changed it to
`closure_123`. It always seemed like the `<>` were not very nushell-y.
This is still a breaking change.

I think this could also help with systematic translation of old config
to new config file.


# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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.
-->
2025-01-07 11:51:22 -06:00
Darren Schroeder
1f477c8eb1
fix stor reset when there are foreign keys (#14772)
# Description

This PR fixes a problem with `stor reset`. That problem was that it
called drop_all_tables which just iterated through the tables and
dropped them one by one. This works as long as there are no foreign keys
or if the tables are dropped in the "right" order. It doesn't work in
most cases since you have to know what order to drop tables in. So, this
PR turns off foreign key constraints, then drops all the tables, then
turns the foreign key constraints back on, which seems to work well...
so far. :)

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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.
-->
2025-01-07 10:28:26 -06:00
Skyler Hawthorne
6260fa9f07
expand custom values on table display (#14760)
# Description

Presently, when custom values are displayed in a table, the entire
object is stringified. e.g., a custom value that encodes a DNS message
gets displayed as:

```
❯ : dns query --timeout 30sec dead10ck.dev
╭───┬─────────────────────────────────────────────────────────────────────╮
│ 0 │ {header: {id: 58404, message_type: RESPONSE, op_code: QUERY,        │
│   │ authoritative: false, truncated: false, recursion_desired: true,    │
│   │ recursion_available: true, authentic_data: true, response_code: No  │
│   │ Error, query_count: 1, answer_count: 2, name_server_count: 0,       │
│   │ additional_count: 1}, question: {name: dead10ck.dev., type: AAAA,   │
│   │ class: IN}, answer: [{name: dead10ck.dev., type: AAAA, class: IN,   │
│   │ ttl: 1hr, rdata: 2600:1f18:6af3:9f05:f526:3a1a:611:6b22, proof:     │
│   │ indeterminate}, {name: dead10ck.dev., type: RRSIG, class: IN, ttl:  │
│   │ 1hr, rdata: AAAA ECDSAP256SHA256 2 3600 1736139412 1736128612 54894 │
│   │  dead10ck.dev. HIkACE70hxznmFTJhOZSmm42KpLC6a+qHchszMyhYjqtG6eP6bzc │
│   │ +XYYjC+UKMaf56SlwBwnpF1tetmrDwyUHw==, proof: indeterminate}],       │
│   │ authority: [], additional: [], edns: {rcode_high: 0, version: 0,    │
│   │ flags: {dnssec_ok: true}, max_payload: 1.2 KiB, opts: {}}, size:    │
│   │ 177 B}                                                              │
```

With this change, expansion to a native nushell value happens earlier so
that they get displayed as any other value does.

```
❯ : ./target/debug/nu -c 'dns query --timeout 30sec dead10ck.dev | table --
expand'
╭───┬────────────────────────────────────┬──────────────────────────┬─────╮
│ # │               header               │         question         │ ... │
├───┼────────────────────────────────────┼──────────────────────────┼─────┤
│ 0 │ ╭─────────────────────┬──────────╮ │ ╭───────┬──────────────╮ │ ... │
│   │ │ id                  │ 37707    │ │ │ name  │ dead10ck.dev │ │     │
│   │ │ message_type        │ RESPONSE │ │ │       │ .            │ │     │
│   │ │ op_code             │ QUERY    │ │ │ type  │ AAAA         │ │     │
│   │ │ authoritative       │ false    │ │ │ class │ IN           │ │     │
│   │ │ truncated           │ false    │ │ ╰───────┴──────────────╯ │     │
│   │ │ recursion_desired   │ true     │ │                          │     │
│   │ │ recursion_available │ true     │ │                          │     │
│   │ │ authentic_data      │ true     │ │                          │     │
│   │ │ response_code       │ No Error │ │                          │     │
│   │ │ query_count         │ 1        │ │                          │     │
│   │ │ answer_count        │ 2        │ │                          │     │
│   │ │ name_server_count   │ 0        │ │                          │     │
│   │ │ additional_count    │ 1        │ │                          │     │
│   │ ╰─────────────────────┴──────────╯ │                          │     │
```

# User-Facing Changes

Custom values are displayed as their native Nushell value.

# Tests + Formatting

Manual
2025-01-06 18:09:55 -06:00
132ikl
88f44701a9
Add doccomments to find functions in EngineState and StateWorkingSet (#14750)
# Description
Adds some doccomments to some of the methods in `engine_state.rs` and
`state_working_set.rs`. Also grouped together some of the `find` methods
in `engine_state.rs`, but didn't do so in `state_working_set.rs` since
they seem to already be grouped according to decl/overlay/module.

Follow-up to #14490. 

# User-Facing Changes
None

# Tests + Formatting
N/A

# After Submitting
N/A
2025-01-07 07:49:13 +08:00
Wind
9ed944312f
auto cd should not canonicalize symbolic path (#14708)
# Description
Fixes: #13158

To fix the issue for auto-cd feature, just need to use
`EngineState::cwd` instead of `nu_engine::env::current_dir_str`

# User-Facing Changes
## Before
```shell
> cd ~
> ln -s /tmp test_link; cd test_link
> ..
> $env.PWD
/
```

## After
```shell
> cd ~
> ln -s /tmp test_link; cd test_link
> ..
> $env.PWD  # it should output home directory.
```

# Tests + Formatting
Update a test under `auto_cd_symlink`
2025-01-07 07:39:03 +08:00
Douglas
6eb14522b6
Remove deprecated commands (#14726)
# Description

Remove commands which were deprecated in 0.101:

* `split-by` (#14019)
* `date to-record` and `date to-table` (#14319)

# User-Facing Changes

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

TODO: `grep` (`ag`) doc repo for any usage of these commands
2025-01-07 07:37:51 +08:00
Chen1Plus
ac12b02437
fix wrong error msg of save command on windows (#14699)
fixes #14664 

# Description

Now,

```nu
"aaa" | save -f ..
```

returns correct error message on windows.

Note that the fix introduces a TOCTOU problem, which only effects the
error message. It won't break any workload.

# User-Facing Changes

The fix won't break any workload.

# Tests + Formatting

I have run tests **only on windows**.

# After Submitting

The fix doesn't need to change documentation.
2025-01-07 07:36:42 +08:00
132ikl
9ed2ca792f
Fix extra newline on empty lists when $env.config.table.show_empty is… (#14766)
<!--
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.
-->

I just noticed that #14758 adds an extra newline when
`$env.config.table.show_empty = false`. This PR makes sure the
placeholder text is non-empty before adding the newline.

Before #14758:
```nushell
$env.config.table.show_empty = false
print ([]) text
# => text
echo []
```

Before PR:
```nushell
$env.config.table.show_empty = false
print ([]) text
# =>
# => text
echo []
# => 
```

After PR:
```nushell
$env.config.table.show_empty = false
print ([]) text
# => text
echo []
```


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

None, fix to #14758 which has not been included in a release

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# 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.
-->
N/A
2025-01-06 15:34:09 -06:00
Bahex
ebabca575c
small, backwards compatible enhancements to std (#14763)
# Description
Small, backwards compatible enhancements to the standard library.

# User-Facing Changes

- changed `iter find`, `iter find-index`: Only consume the input stream
up to the first match.
- added `log set-level`: a small convenience command for setting the log
level
- added `$null_device`: `null-device` as a const variable, would allow
conditional sourcing if #13872 is fixed

# Tests + Formatting

- 🟢 toolkit fmt
- 🟢 toolkit clippy
- 🟢 toolkit test
- 🟢 toolkit test stdlib

# After Submitting
N/A
2025-01-06 11:30:07 -06:00
132ikl
b60f91f722
Don't expand ndots if prefixed with ./ (#14755)
<!--
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
Prevents ndots from being expanded if they are prefixed with `./`, as
the agreed resolution to #13303. Only applies to externals, mirroring
the fix from #13218.

I did
[attempt](https://github.com/132ikl/nushell/tree/internal-ndots-attempt)
to apply the fix for internal commands as well, but it seems like the
path is expanded too aggressively and I haven't investigated it further
yet. `./...` gets normalized into `<pwd>/./...`, which gets normalized
into `<pwd>/...` before being handed to `expand_ndots`, and at that
point it just looks like a normal n-dots so we can't tell we shouldn't
expand.

(Fixes #13303)

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

* N-dots are no longer expanded to external command calls when prefixed
with `./`.

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->



Added tests to prevent regression.

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

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

N/A
2025-01-05 17:07:34 -05:00
132ikl
2b4c54d383
Add newline to empty list output (#14758)
<!--
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.
-->

Adds a newline to the empty list output. Fixes #14748.

This does not affect the `[empty list]` text output in the REPL, just
the `print` output (to be honest, I'm not certain why, but I'm guessing
the REPL was adding an extra newline somewhere to compensate). The
`bytes.push('\n')` replicates the code from the below
`convert_table_to_output` function, which is bypassed for empty lists.

Before:
```nushell
[]
# => ╭────────────╮
# => │ empty list │
# => ╰────────────╯
print ([]) text
# => ╭────────────╮
# => │ empty list │
# => ╰────────────╯text
```

After:
```nushell
[]
# => ╭────────────╮
# => │ empty list │
# => ╰────────────╯
print ([]) text
# => ╭────────────╮
# => │ empty list │
# => ╰────────────╯
# => text
```

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

* Fixes "empty list" placeholder text output when using the `print`
command

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# 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.
-->
N/A
2025-01-05 16:01:05 -06:00
132ikl
ed1381adc4
Change PipelineData::into_value to use internal Value's span before passed in span (#14757)
<!--
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.
-->

Changes the `Value` variant match arm of `PipelineData::into_value` to
use the internal `Value`'s span instead of the span passed in by the
user. This aligns more closely with the `ListStream` and `ByteStream`
match arms, which already use their internal span, and allows errors to
provide better diagnostics since the span information doesn't get lost
when `into_value` is called. At the suggestion of @cptpiepmatz, if the
`Value` has `Span::unknown` for some reason, then we replace the
`Value`'s span with the passed in span.

Before:

```nushell
{} | get foo bar
# => Error: nu:🐚:column_not_found
# => 
# =>   × Cannot find column 'foo'
# =>    ╭─[entry #43:2:6]
# =>  2 │ {} | get foo bar
# =>    ·      ─┬─ ─┬─
# =>    ·       │   ╰── cannot find column 'foo'
# =>    ·       ╰── value originates here
# =>    ╰────
```

After:

```nushell
{} | get foo bar
# => Error: nu:🐚:column_not_found
# => 
# =>   × Cannot find column 'foo'
# =>    ╭─[entry #2:2:1]
# =>  2 │ {} | get foo bar
# =>    · ─┬       ─┬─
# =>    ·  │        ╰── cannot find column 'foo'
# =>    ·  ╰── value originates here
# =>    ╰────
```

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

* Some errors may have more accurate info about where the value
originates from

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# 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.
-->
N/A
2025-01-05 15:33:58 -06:00
132ikl
1b7fabd1fd
Fix config reset to use scaffold config files (#14756)
In #14249, `config reset` wasn't updated to use the scaffold config files, so running `config reset` would accidentally reset the user's config to the internal defaults. This PR updates it to use the
scaffold files.
2025-01-05 16:18:19 -05:00
Bark
87a562e24b
Fix root directory traversal issue (#14747)
fixes : #13729 

During dot expansion, the "parent" was added even if it was after the
root (`/../../`).
Added additional check that skips appending elements to the path
representation if the parent folder is the root folder.
2025-01-05 07:13:19 -06:00
zc he
b5ff46db6a
feat(lsp): use lsp-textdocument to handle utf16 position (#14742)
<!--
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 replaces `ropey` with `lsp-textdocument` for easier utf16
position handling.
As a side effect, if fixes the following crashing bug:

1. create a `foo.nu` file with errors in it
2. in `bar.nu`, add code `use foo.nu *`

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

* <s>Diagnostics are now triggered only with document open/save, that's
my personal preference. Changing back to previous behavior is easy if
you guys have other concerns.</s>
* UTF-8 position encoding is not supported by lsp-textdocument, but
that's not an issue, since the previous utf-8 ropey implementation is
buggy when used in real scenarios in a text editor.

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->

No new tests added, removed some utf-8 related ones.

# 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.
-->
2025-01-05 07:11:17 -06:00
132ikl
8b086d3613
Make get const (#14751)
<!--
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.
-->

Makes `get` const

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

`get` is now a const command.

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# 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.
-->
N/A
2025-01-04 16:41:03 -05:00
Douglas
d702c4605a
Increment SHLVL before run_repl() (#14732)
# Description

A follow-on to #14727:

* Instead of using `is-interactive` as the trigger for incrementing
`SHLVL`, this change puts the increment logic just before `run_repl()`
is called.
* Tests are changed to use `-e`
* Moves the `confirm_stdin_is_terminal()` call immediately **after** the
`prerun_cmd` (which executes `--execute (-e) <commandstring>`. The fact
that it was **before** that call seems to be a bug, since the error
message says *"or provide arguments to invoke a script"* even if
`--execute` was used. This change enables REPL testing using `--execute
(-e)`.
* Added a test to ensure `-c` does *not* increment SHLVL.

# User-Facing Changes

`$env.SHLVL` runs before the REPL is started, rather than when
`is-interactive`

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2025-01-03 15:16:57 -06:00
Douglas
6325bc5e54
Add comment on nu_repl usage (#14734)
# Description

I just spent way too long trying to get `nu --testbin nu_repl
<commands>` working. That's one argument that must be called as `nu
--testbin=nu_repl <commands>` due to its implementation. This PR simply
adds a comment in `main()` noting that, hoping it will save someone else
some time in the future ;-)

# User-Facing Changes

None

# Tests + Formatting

N/A

# After Submitting

N/A
2025-01-03 12:38:46 -06:00
Piepmatz
25d90fa603
Use Value::coerce_bool in into bool (#14731)
<!--
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.
-->
I realized that the `into bool` command somehow implements a conversion
into a boolean value which was very similar to my implementation of
~`Value::as_env_bool`~ `Value::coerce_bool`. To streamline that behavior
a bit, I replaced most of the implementation of `into bool` with my
~`Value::as_env_bool`~ `Value::coerce_bool` method.

Also I added a new flag called `--relaxed` which lets the command behave
more closely to the ~`Value::as_env_bool`~ `Value::coerce_bool` method
as it allows null values and is more loose to strings. ~Which now begs
the question, should I rename `Value::as_env_bool` just to
`Value::coerce_bool` which would fit the `Value::coerce_str` method
name?~ (Renamed that.)

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

The `into bool` command behaves the same but with `--relaxed` you can
also throw a `null` or some more strings at it which makes it more
ergonomic for env conversions.

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->

I added some more tests to see that the strict handling works and added
some more examples to the command to showcase the `--relaxed` flag which
also gets tested.

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

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

@Bahex mentioned in #14704 that it broke the zoxide script, this PR
should help to fix the issue.
2025-01-03 08:11:34 -06:00
Douglas
86f7f53f85
Run SHLVL tests sequentially (#14727)
Tests for #14707 are causing hangs which are preventing `toolkit test`
from completing on some systems. This appears to be due to the use of
`-i` to force interactive mode, which is required in order to update the
`SHLVL`. Both tests are likely attempting to acquire the terminal at the
same time, and one is hanging as a result.

This is a temporary fix which runs both of these tests sequentially.
It's temporary because we need to find a solution which doesn't use
`-i`, since any other future `-it` test will cause the same situation
again.
2025-01-02 23:22:04 -05:00
Douglas
461eb43d9d
Add user autoload directory (#14669)
# Description

Adds a user-level (non-vendor) autoload directory:

```
($nu.default-config-dir)/autoload
```

Currently this is the only directory. We can consider adding others if
needed.

Related: As a separate PR, I'm going to try to restore the ability to
set `$env.NU_AUTOLOAD_DIRS` during startup.

# User-Facing Changes

Files in `$nu.default-config-dir/autoload` will be autoload at startup.
These files will be loaded after any vendor autoloads, so that a user
can override the vendor settings.

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

TODO; add a `$nu.user-autoload-dirs` constant.

Doc updates
2025-01-02 16:10:05 -06:00
Jack Wright
df3892f323
Provide the ability to split strings in columns via polars str-split (#14723)
# Description
Provides the ability to split string columns. This will change the
column type to list<str>.

```nushell
> ❯ : [[a]; ["one,two,three"]] | polars into-df | polars select (polars col a | polars str-split ",") | polars collect
╭───┬───────────────╮
│ # │       a       │
├───┼───────────────┤
│ 0 │ ╭───┬───────╮ │
│   │ │ 0 │ one   │ │
│   │ │ 1 │ two   │ │
│   │ │ 2 │ three │ │
│   │ ╰───┴───────╯ │
╰───┴───────────────╯

> ❯ : [[a]; ["one,two,three"]] | polars into-df | polars select (polars col a | polars str-split ",") | polars schema
╭───┬───────────╮
│ a │ list<str> │
╰───┴───────────╯
```



# User-Facing Changes
- Introduces new command `polars str-split`
2025-01-02 15:03:24 -06:00
Douglas
0d3f76ddef
Remove no-longer-needed convert_env_values calls (#14681)
# Description

Takes advantage of #14591 to remove the now-necessary calls to
`convert_env_values()` that I added in #14249. The function is now just
called once to convert `PATH`.

Also removed the Windows-build-time checks for `ensure_path`, since
previous case-insensitivity fixes make this unnecessary as well.

# User-Facing Changes

None - #14591 now handles conversion 'on-demand'.

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2025-01-02 12:05:02 -06:00
tsukimizake
816b9a6953
stop the prompt from removing the last newline (#14590)
<!--
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.
-->
I tried to setup a multiline prompt like this.
<img width="175" alt="スクリーンショット 2024-12-15 17 45 06"
src="https://github.com/user-attachments/assets/8d00a203-b341-45ce-8427-b4d5a9d3d7c3"
/>

But when I set PROMT_COMMAND like this, 

```nu
$env.PROMPT_COMMAND = {|| $"(ansi reset)(ansi magenta)(date now | format date "%Y-%m-%dT%H:%M:%S%z")\n(pwd)\n" } 
```

The result is like this, due to dropping `\n` and `\r` on
`prompt_update.rs`.
<img width="185" alt="スクリーンショット 2024-12-15 17 54 21"
src="https://github.com/user-attachments/assets/5ead998e-6f87-479f-b2de-e267f0cc3acd"
/>

Currently, adding two newlines can detour the drop.
I think this drop newline makes little sense, so I removed it on this
PR.
If you don't like it, feel free to close it.

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

Trailing newline of PROMPT_COMMAND is not dropped anymore.

# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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
> ```
-->

This is a subtle change just on prompt string, so I think particular
test is not so necessary.

# 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.
-->
As far as I read
https://www.nushell.sh/book/coloring_and_theming.html#prompt-configuration-and-coloring
, the behavior seems undocumented.
2025-01-02 09:48:35 -06:00
Yash Thakur
80788636ee
Make utouch the new touch (#14721)
# Description

This PR removes the old `touch` command in favor of the uutils/coreutils
implementation of `touch`, which we integrated in 0.101 (#11817).

It turns out that in `utouch`, the `--no-deref`/`-s` wasn't working, and
the issue had gone undetected because I accidentally made the test for
that use `touch` rather than `utouch`. This has been fixed now.

# User-Facing Changes

Our old `touch` command didn't have anything that the new uutils-based
command doesn't, and the uutils-based command actually has a little more
functionality. So nothing using `touch` should break.

Scripts using `utouch` will have to use `touch` now, but given that
`utouch` has been around for less than 2 months, I assume people haven't
really been using it.

# Tests + Formatting

The utouch tests seem to have everything from the old touch tests, so I
deleted the old touch tests.

# After Submitting

This will need to be mentioned in the release notes.
2025-01-02 06:26:46 -06:00
Henry Jetmundsen
c46ca36bcd
Add glob support to utouch (issue #13623) (#14674)
# Description
These changes resolve #13623 where globs are not handled by `utouch`. 

# User-Facing Changes
- Glob patterns passed to `utouch` will be resolved to all individual
files that match the pattern. For example, running `utouch *.txt` in a
directory that already has `file1.txt` and `file2.txt` is the same thing
as running `utouch file1.txt file2.txt`. All flags such as `-a`, `-m`
and `-c` will be respected.
- If a glob pattern is provided to `utouch` and doesn't match any files,
a file will be created with the literal name of the glob pattern. This
only applies to Linux/MacOS because Windows forbids creating file names
with restricted characters (see [naming a file
docs](https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file))

---------

Co-authored-by: Henry Jetmundsen <hjetmundsen@atlassian.com>
2025-01-01 20:38:15 -05:00
Yash Thakur
62bd6fe08b
Create nu_glob::is_glob function (#14717)
# Description

Adds an `is_glob` function to the nu-glob crate that takes a string
pattern and returns whether or not it's a glob that would be expanded by
nu-glob. Right now, this just means checking if it contains `*`, `?`, or
`[`.

Previously, this same code was duplicated in the following places:
- `ls`: Determining whether to read a folder's contents or expand a glob
- `run_external.rs` in nu-command: Arguments to externals only have
n-dots and tilde expansion applied if they weren't globs
- `glob_from` in nu-engine:
  - `glob_from` can get the prefix in a simpler way for non-globs
- If the canonical path for a non-glob path contains glob
metacharacters, it needs to be escaped
- `completion_common.rs` in nu-cli: File/folder completions containing
glob metacharacters need to be wrapped in quotes

All of these locations can use `nu_glob::is_glob` now instead of rolling
their own checks. This does mean that nu-cli now has a dependency on
nu-glob.

# User-Facing Changes

Users of nu-glob will now be able to check if a given pattern is a glob
expanded by nu-glob.

For users of Nushell, completion suggestions for files containing `]`
will no longer be wrapped in quotes if they contain no other glob
metacharacters. This is because unmatched `]`s are ignored by nu-glob,
but we used to consider such file completions contaminated anyway.

# Tests + Formatting

This is a very basic function, so I just added some doctests.

# After Submitting

This is meant to be used in
https://github.com/nushell/nushell/pull/14674.
2025-01-01 19:04:17 -05:00
Darren Schroeder
f69b22f00b
replace regex crate with fancy_regex (#14646)
# Description

We removed the regex crate long ago but there were a few instances where
we could not remove it because fancy-regex did not have a split/splitn,
and maybe other functions. Those functions now exist in the latest
fancy-regex crate so we can now remove it.
 
# 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` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` 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.
-->
2025-01-01 17:37:50 -06:00
Maxim Zhiburt
c6523eb8d9
[WIP] Try to fix tabled panic (#14710)
cc: @fdncred
2025-01-01 08:09:23 -06:00
Douglas
76afa74320
open: Assign content_type metadata for filetypes not handled with a from converter (#14670)
# Description

Filetypes which are converted during `open` should not have (and have
not had) a `content_type` metadata field. However, filetypes which
aren't converted now behave the same as with `--raw` and assign the
appropriate `content_type`.

## Before

```nushell
open toolkit.nu | metadata
# => ╭────────┬────────────────────────────────────────────╮
# => │ source │ /home/ntd/src/ntd-forks/nushell/toolkit.nu │
# => ╰────────┴────────────────────────────────────────────

open --raw toolkit.nu | metadata
# => ╭──────────────┬────────────────────────────────────────────╮
# => │ source       │ /home/ntd/src/ntd-forks/nushell/toolkit.nu │
# => │ content_type │ application/x-nuscript                     │
# => ╰──────────────┴────────────────────────────────────────────╯

open script.py | metadata
# => ╭────────┬─────────────────────────────╮
# => │ source │ /home/ntd/testing/script.py │
# => ╰────────┴─────────────────────────────╯

open Cargo.toml | metadata
# => ╭────────┬────────────────────────────────────────────╮
# => │ source │ /home/ntd/src/ntd-forks/nushell/Cargo.toml │
# => ╰────────┴────────────────────────────────────────────╯
```

## After

```nushell
# Not converted, so adds content_type
open toolkit.nu | metadata
# => ╭──────────────┬────────────────────────────────────────────╮
# => │ source       │ /home/ntd/src/ntd-forks/nushell/toolkit.nu │
# => │ content_type │ application/x-nuscript                     │
# => ╰──────────────┴────────────────────────────────────────────╯

# Not converted, so adds content_type
open --raw toolkit.nu | metadata
# => ╭──────────────┬────────────────────────────────────────────╮
# => │ source       │ /home/ntd/src/ntd-forks/nushell/toolkit.nu │
# => │ content_type │ application/x-nuscript                     │
# => ╰──────────────┴────────────────────────────────────────────╯

# Not converted, so adds content_type
open script.py | metadata
# => ╭──────────────┬─────────────────────────────╮
# => │ source       │ /home/ntd/testing/script.py │
# => │ content_type │ text/plain                  │
# => ╰──────────────┴─────────────────────────────

# Converted, so does not add content_type (no change)
open Cargo.toml | metadata
# => ╭────────┬────────────────────────────────────────────╮
# => │ source │ /home/ntd/src/ntd-forks/nushell/Cargo.toml │
# => ╰────────┴────────────────────────────────────────────╯
```

# User-Facing Changes

`open <file>` assigns the appropriate content type when the filetype is
not converted via a `from <format>`.

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A
2025-01-01 03:05:43 +01:00