Commit graph

9716 commits

Author SHA1 Message Date
Zhenping Zhao
25a2a7a0f9 Adjust import condition fo is_env_var_for_drive. 2024-12-16 07:19:43 -08:00
Zhenping Zhao
709b3afd93 Remove refex dependency 2024-12-16 07:06:16 -08:00
Zhenping Zhao
a58d80e57f Refactor as not using collect() 2024-12-16 06:59:45 -08:00
Zhenping Zhao
7fe3cca342 Refactor as immutable and not using regex. 2024-12-16 06:46:58 -08:00
Zhenping Zhao
e1b81081a2 Refactor result as immutable; test import adjustment 2024-12-15 20:01:34 -08:00
Zhenping Zhao
e09a1ce874 Rollback retain_result_set_pwd() and fetch_result() design, too complex to implemente and use, over design? Alter to add_env_var_with_result() to directly get result. 2024-12-15 18:45:05 -08:00
Zhenping Zhao
1057e648b0 Fix set_pwd() return Result logic. 2024-12-15 15:33:33 -08:00
Zhenping Zhao
569929983c Try detect incompatible path format 2024-12-15 15:17:32 -08:00
Zhenping Zhao
b1de37302a Remove redundant .to_string(), refactor tests to reduce duplicate code segment. 2024-12-15 14:52:01 -08:00
Zhenping Zhao
1e8d6aa5c4 report_shell_error import adjustment, set_pwd() return value adjust. 2024-12-15 14:38:06 -08:00
Zhenping Zhao
3e17077679 if cfg\!(windows) { ... } else { ... } not very compatible, rollback to #[cfg(windows)] ... #[cfg(not(windows))] ... 2024-12-15 14:22:53 -08:00
Zhenping Zhao
4497b698ee Follow review comments, refactor set_pwd() to return Result<(), ShellError>, add 2 helpers: retain_result_set_pwd(), fetch_result(), add extend_automatic_env_vars() for adding PWD-per-drive env_vars to automatically managed env vars, and refactor several duplicate automatic env var collections to sole provider. 2024-12-15 13:29:08 -08:00
Zhenping Zhao
795230f36b Follow review comments, and adjust expectation on test results for windows. Hide env_vars for PWD-per-drive from being collected by auto completion. 2024-12-13 13:39:31 -08:00
Zhenping Zhao
ed848615ac Cargo fmt 2024-12-12 09:29:46 -08:00
Zhenping Zhao
3e973ed304 Adjust test expects 2024-12-12 08:55:25 -08:00
Zhenping Zhao
7cdc3281a5 Adjust test expects 2024-12-12 08:23:56 -08:00
Zhenping Zhao
8c59cbf913 Refactor to create EnvMaintainer trait for interact with Stack/EngineState. 'ls' now PWD-per-drive ready. 2024-12-12 05:25:54 -08:00
Zhenping Zhao
2b9f6e64a1 Refactor to create EnvMaintainer trait for interact with Stack/EngineState. 'ls' now PWD-per-drive ready. 2024-12-12 05:24:22 -08:00
Zhenping Zhao
de83d1afef Cargo fmt 2024-12-11 11:48:07 -08:00
Zhenping Zhao
c3b6e9f709 Revert cd.rs, it does not need to be modified to use PWD-per-drive, as most file system commands. 2024-12-11 11:17:11 -08:00
Zhenping Zhao
37469f015c Refine variable name. 2024-12-10 02:00:06 -08:00
Zhao Zhenping
cad5d827bf Restore accidentally changed visiblity of sequence mod 2024-12-09 14:53:41 -08:00
Zhao Zhenping
7303d28681 Refine test case names, is_dir() ensures ends with '\' 2024-12-09 14:30:48 -08:00
Zhao Zhenping
ea1b0d93ed Cargo fmt --all 2024-12-09 14:09:30 -08:00
Zhao Zhenping
1aded9f248 Loosen only root path of non exists drive 2024-12-09 14:05:04 -08:00
Zhao Zhenping
48bad903c4 Prevent Clippy within tests on Ubuntu 2024-12-09 13:44:18 -08:00
Zhao Zhenping
de3e4ebf12 Cargo fmt 2024-12-09 13:27:46 -08:00
Zhao Zhenping
e5dee192b8 Should include Cargo.lock 2024-12-09 13:16:57 -08:00
Zhao Zhenping
338fa8400f Remove extra mods 2024-12-09 12:13:35 -08:00
PegasusPlusUS
f8e01d8401
Merge branch 'nushell:main' into continue-PWD-per-drive 2024-12-09 04:14:49 -08:00
Zhenping Zhao
eb0509634f Remove bash_strip_extra_quotes() and cmd_remove_all_double_quotes() 2024-12-09 02:15:21 -08:00
Zhenping Zhao
1b77830a39 Refactor need_expand and extract_drive_letter 2024-12-09 01:50:35 -08:00
Zhenping Zhao
f09b4948cb mod define adjustment 2024-12-08 22:44:45 -08:00
Zhenping Zhao
d81d0e1dde Rename mod as pwd_per_drive, cargo clippy 2024-12-08 22:28:07 -08:00
Zhenping Zhao
1edb0e7a8a Refactor done 2024-12-08 22:12:52 -08:00
Zhenping Zhao
ba9d44274a Continue refactoring 2024-12-08 17:45:48 -08:00
Zhenping Zhao
b0aeab9c99 Refactor to clear role of code segments 2024-12-08 17:12:06 -08:00
Zhenping Zhao
32ba2e0cc4 Linux unused import warning 2024-12-08 13:38:05 -08:00
PegasusPlusUS
b7928ccadd Format 2024-12-08 07:16:59 -08:00
PegasusPlusUS
61594d9b16 macOS 2024-12-08 07:15:56 -08:00
Darren Schroeder
685dc78739
update to reedline 9eb3c2d (#14541)
# Description

This PR updates nushell to the latest commit of reedline that fixes some
rendering issues on window resize.

# 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.
-->
2024-12-08 08:43:36 -06:00
PegasusPlusUS
9078c182e8
Merge branch 'nushell:main' into continue-PWD-per-drive-quote 2024-12-08 06:23:06 -08:00
Zhenping Zhao
68bde8d3e5 PWD-per-drive v2, basic implementation, auto_cd/cd OK, overlay, set-env freely. Wait review and other file system commands pending. 2024-12-08 06:17:58 -08:00
Jess
9daa5f9177
Fix silent failure of parsing input output types (#14510)
- This PR should fix/close:
  - #11266
  - #12893 
  - #13736 
  - #13748
  - #14170
- It doesn't fix #13736 though unfortunately. The issue there is at a
different level to this fix (I think probably in the lexing somewhere,
which I haven't touched).

# The Problem

The linked issues have many examples of the problem and the related
confusion it causes, but I'll give some more examples here for
illustration. It boils down to the following:

This doesn't type check (good):
```nu
def foo []: string -> int { false }
```

This does (bad):
```nu
def foo [] : string -> int { false }
```

Because the parser is completely ignoring all the characters. This also
compiles in 0.100.0:
```nu
def blue [] Da ba Dee da Ba da { false }
```

And this also means commands which have a completely fine type, but an
extra space before `:`, lose that type information and end up as `any ->
any`, e.g.
```nu
def foo [] : int -> int {$in + 3}
```
```bash
$ foo --help
Input/output types:
  ╭───┬───────┬────────╮
  │ # │ input │ output │
  ├───┼───────┼────────┤
  │ 0 │ any   │ any    │
  ╰───┴───────┴────────╯
```

# The Fix

Special thank you to @texastoland whose draft PR (#12358) I referenced
heavily while making this fix.

That PR seeks to fix the invalid parsing by disallowing whitespace
between `[]` and `:` in declarations, e.g. `def foo [] : int -> any {}`

This PR instead allows the whitespace while properly parsing the type
signature. I think this is the better choice for a few reasons:
- The parsing is still straightforward and the information is all there
anyway,
- It's more consistent with type annotations in other places, e.g. `do
{|nums : list<int>| $nums | describe} [ 1 2 3 ]` from the [Type
Signatures doc
page](https://www.nushell.sh/lang-guide/chapters/types/type_signatures.html)
- It's more consistent with the new nu parser, which allows `let x :
bool = false` (current nu doesn't, but this PR doesn't change that)
- It will be less disruptive and should only break code where the types
are actually wrong (if your types were correct, but you had a space
before the `:`, those declarations will still compile and now have more
type information vs. throwing an error in all cases and requiring spaces
to be deleted)
- It's the more intuitive syntax for most functional programmers like
myself (haskell/lean/coq/agda and many more either allow or require
whitespace for type annotations)

I don't use Rust a lot, so I tried to keep most things the same and the
rest I wrote as if it was Haskell (if you squint a bit). Code
review/suggestions very welcome. I added all the tests I could think of
and `toolkit check pr` gives it the all-clear.

# User-Facing Changes

This PR meets part of the goal of #13849, but doesn't do anything about
parsing signatures twice and doesn't do much to improve error messages,
it just enforces the existing errors and error messages.

This will no doubt be a breaking change, mostly because the code is
already broken and users don't realise yet (one of my personal scripts
stopped compiling after this fix because I thought `def foo [] -> string
{}` was valid syntax). It shouldn't break any type-correct code though.
2024-12-07 09:55:15 -06:00
Bahex
69fbfb939f
lsp and --ide-check fix for path self related diagnostics (#14538)
# Description

fixes
[this](https://github.com/nushell/nushell/pull/14303#issuecomment-2525100480)
where lsp and ide integration would produce the following error

---

```sh
nu --ide-check 100 "/path/to/env.nu"
```
with
```nu
const const_env = path self
```
would lead to
```
Error: nu:🐚:file_not_found

  × File not found
   ╭─[/path/to/env.nu:1:19]
 1 │ const const_env = path self
   ·                   ────┬────
   ·                       ╰── Couldn't find current file
   ╰────
```

# Tests + Formatting
- 🟢 `cargo fmt --all`
- 🟢 `cargo clippy --workspace`
2024-12-07 09:46:52 -06:00
Piepmatz
f0ecaabd7d
Expose "to html" command (#14536)
<!--
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.
-->
In this PR I exposed the struct `ToHtml` that comes from `nu-cmd-extra`.
I know this command isn't in a best state and should be changed in some
way in the future but having the struct exposed makes transforming data
to html way more simple for external tools as the `PipelineData` can
easily be placed in the `ToHtml::run` method.

# 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 did `fmt` and `check` but not `test`, shouldn't break any tests
regardless.

# 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.
-->
For the demo page or my jupyter kernel would this make my life easiert.
2024-12-07 07:28:14 -06:00
Darren Schroeder
c16f49cf19
add coreutils to search terms 2024-12-07 07:20:46 -06:00
Maxim Uvarov
9411458689
rewrite error message to not use the word function (#14533)
# Description

After [the discussion on
discord](https://discord.com/channels/601130461678272522/601130461678272524/1314600410882904125)
I propose to rephrase the error message to avoid using the word
`function`.

From `Return used outside of function` to `Return used outside of custom
command or closure`


![image](https://github.com/user-attachments/assets/d14331c8-e381-4b04-8709-bd6064e0791e)



# User-Facing Changes

None

# Tests + Formatting

toolkit.nu fmt is good
2024-12-06 18:09:11 -06:00
Bahex
8771872d86
Add path self command for getting absolute paths to files at parse time (#14303)
Alternative solution to:
- #12195 

The other approach:
- #14305

# Description
Adds ~`path const`~ `path self`, a parse-time only command for getting
the absolute path of the source file containing it, or any file relative
to the source file.

- Useful for any script or module that makes use of non nuscript files.
- Removes the need for `$env.CURRENT_FILE` and `$env.FILE_PWD`.
- Can be used in modules, sourced files or scripts.

# Examples

```nushell
# ~/.config/nushell/scripts/foo.nu
const paths = {
    self: (path self),
    dir: (path self .),
    sibling: (path self sibling),
    parent_dir: (path self ..),
    cousin: (path self ../cousin),
}

export def main [] {
    $paths
}
```

```nushell
> use foo.nu
> foo
╭────────────┬────────────────────────────────────────────╮
│ self       │ /home/user/.config/nushell/scripts/foo.nu  │
│ dir        │ /home/user/.config/nushell/scripts         │
│ sibling    │ /home/user/.config/nushell/scripts/sibling │
│ parent_dir │ /home/user/.config/nushell                 │
│ cousin     │ /home/user/.config/nushell/cousin          │
╰────────────┴────────────────────────────────────────────╯
```


Trying to run in a non-const context
```nushell
> path self
Error:   × this command can only run during parse-time
   ╭─[entry #1:1:1]
 1 │ path self 
   · ─────┬────
   ·      ╰── can't run after parse-time
   ╰────
  help: try assigning this command's output to a const variable
```

Trying to run in the REPL i.e. not in a file
```nushell
> const foo = path self
Error:   × Error: nu:🐚:file_not_found
  │ 
  │   × File not found
  │    ╭─[entry #3:1:13]
  │  1 │ const foo = path self
  │    ·             ─────┬────
  │    ·                  ╰── Couldn't find current file
  │    ╰────
  │ 
   ╭─[entry #3:1:13]
 1 │ const foo = path self
   ·             ─────┬────
   ·                  ╰── Encountered error during parse-time evaluation
   ╰────
```

# Comparison with #14305
## Pros
- Self contained implementation, does not require changes in the parser.
- More concise usage, especially with parent directories.

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2024-12-06 08:19:08 -06:00
Alex Kattathra Johnson
cda9ae1e42
Shorten --max-time in tests and use a more stable error check (#14494)
- fixes flakey tests from solving #14241

# Description
This is a preliminary fix for the flaky tests and also
shortened the `--max-time` in the tests.

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



---------

Signed-off-by: Alex Kattathra Johnson <alex.kattathra.johnson@gmail.com>
2024-12-06 13:03:13 +01:00