Commit Graph

9109 Commits

Author SHA1 Message Date
Devyn Cairns
6398f0e31e
literal ValueWithUnit (filesize, duration) 2024-07-04 00:48:23 -07:00
Devyn Cairns
c06ec8afee
fix --help, alias 2024-07-03 22:09:46 -07:00
Devyn Cairns
5c419a39e8
custom commands, fix let, fix bare $env var 2024-07-03 20:15:00 -07:00
Devyn Cairns
d33d21e1dc
row condition, fix table literal 2024-07-03 17:51:20 -07:00
Devyn Cairns
062821039a
match support 2024-07-03 17:36:26 -07:00
Devyn Cairns
3bdb864b9d
clean up unexpected 2024-07-03 15:25:15 -07:00
Devyn Cairns
1294d0f710
remove unused import 2024-07-03 14:41:36 -07:00
Devyn Cairns
ae0651127d
string interpolation: don't trust type checking, only start from strings if they're literals 2024-07-03 00:18:32 -07:00
Devyn Cairns
52ec0c3b1d
fix parser info: actually add it to the call 2024-07-03 00:17:09 -07:00
Devyn Cairns
3c33a3f4eb
try/catch with catch as an expression rather than literal block 2024-07-03 00:04:46 -07:00
Devyn Cairns
7a055563a9
try/catch (wip) 2024-07-02 20:11:11 -07:00
Devyn Cairns
b3b59c8f9c
more keyword pseudocode 2024-07-02 18:39:59 -07:00
Devyn Cairns
9b88b4eca6
while, loop keywords + fix some allocation state issues 2024-07-02 18:35:04 -07:00
Devyn Cairns
37a3b19cc5
constant test 2024-07-01 14:12:32 -07:00
Devyn Cairns
4af1b1981d
fix binary op reg allocation bug 2024-07-01 14:10:00 -07:00
Devyn Cairns
89d7b2237c
redirect test 2024-07-01 13:47:11 -07:00
Devyn Cairns
e2510d6c0d
fix redirection, more tests 2024-07-01 13:23:49 -07:00
Devyn Cairns
206d6c279d
wip eval tests 2024-07-01 04:02:11 -07:00
Devyn Cairns
dca2798d4d
support parser info 2024-07-01 03:07:23 -07:00
Devyn Cairns
67bd88535c
WIP: cleaning up errors 2024-06-28 23:19:37 -07:00
Devyn Cairns
9227e28485
const 2024-06-28 22:11:35 -07:00
Devyn Cairns
b63b0217bd
string, glob interpolation 2024-06-28 22:07:39 -07:00
Devyn Cairns
37255bef3c
implement for keyword, add iterate instruction 2024-06-28 21:03:57 -07:00
Devyn Cairns
ae21929915
add return keyword 2024-06-28 19:36:01 -07:00
Devyn Cairns
ceb34c099b
refactor compile into multiple files 2024-06-28 19:18:12 -07:00
Devyn Cairns
a6c2d39879
change the span of the if jump to the else 2024-06-27 19:58:17 -07:00
Devyn Cairns
b02d6e44fc
include the formatted instructions in view ir --json, since that's hard to generate from a plugin 2024-06-27 19:21:54 -07:00
Devyn Cairns
0d15d50023
fix deserialization of IrBlock 2024-06-27 18:09:22 -07:00
Devyn Cairns
06b7e5c30a
add view ir --json for use in external tooling 2024-06-27 17:31:59 -07:00
Devyn Cairns
9e19f15cb5
try to reduce drops a bit 2024-06-27 00:24:29 -07:00
Devyn Cairns
13e348ab57
let, mut, and assignments 2024-06-27 00:09:33 -07:00
Devyn Cairns
866d5c405f
support external calls 2024-06-26 19:47:47 -07:00
Devyn Cairns
2202118efb
range support 2024-06-26 19:15:44 -07:00
Devyn Cairns
69b2d00756
Support if/else, clear up drop/empty reg semantics 2024-06-26 18:47:08 -07:00
Devyn Cairns
fd0b99554d
Add transitive use_ir field to Stack and add --use-ir option to nu 2024-06-26 17:28:00 -07:00
Devyn Cairns
73b092bfdc
instructions: list-spread, record-spread 2024-06-26 16:56:09 -07:00
Devyn Cairns
ed59f80b35
list, record, table expression support 2024-06-26 02:10:00 -07:00
Devyn Cairns
7890b3f27a
more efficient storage for string data in ir blocks 2024-06-26 01:23:46 -07:00
Devyn Cairns
4fe74e3f8c
Merge branch 'main' into ir 2024-06-25 22:44:50 -07:00
Jack Wright
c5a00ca3f1
update lock via cargo check to fix ci (#13233) 2024-06-25 19:14:15 -07:00
Ian Manske
5a486029db
Add typed path forms (#13115)
# Description
This PR adds new types to `nu-path` to enforce path invariants. Namely,
this PR adds:
- `Path` and `PathBuf`. These types are different from, but analogous to
`std::path::Path` and `std::path::PathBuf`.
- `RelativePath` and `RelativePathBuf`. These types must be/contain
strictly relative paths.
- `AbsolutePath` and `AbsolutePathBuf`. These types must be/contain
strictly absolute paths.
- `CanonicalPath` and `CanonicalPathBuf`. These types must be/contain
canonical paths.

Operations are prohibited as necessary to ensure that the invariants of
each type are upheld (needs double-checking).

Only paths that are absolute (or canonical) can be easily used as /
converted to `std::path::Path`s. This is to help force us to account for
the emulated current working directory instead of accidentally using the
current directory of the Nushell process (i.e.,
`std::env::current_dir`). Related to #12975 and #12976.

Note that this PR uses several declarative macros, as the file / this PR
would otherwise be 5000 lines long.

# User-Facing Changes
No major changes yet, just adds types to `nu-path` to be used in the
future.

# After Submitting
Actually use the new path types in all our crates where it makes sense,
removing usages of `std::path` types.
2024-06-25 18:33:57 -07:00
Wind
def36865ef
Enable reloading changes to a submodule (#13170)
# Description

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

Currently if user run `use voice.nu`, and file is unchanged, then run
`use voice.nu` again. nushell will use the module directly, even if
submodule inside `voice.nu` is changed.

After discussed with @kubouch, I think it's ok to re-parse the module
file when:
1. It exports sub modules which are defined by a file
2. It uses other modules which are defined by a file

## About the change:
To achieve the behavior, we need to add 2 attributes to `Module`:
1. `imported_modules`: it tracks the other modules is imported by the
givem `module`, e.g: `use foo.nu`
2. `file`: the path of a module, if a module is defined by a file, it
will be `Some(path)`, or else it will be `None`.

After the change:

    use voice.nu always read the file and parse it.
    use voice will still use the module which is saved in EngineState.

# User-Facing Changes

use `xxx.nu` will read the file and parse it if it exports submodules or
uses submodules

# Tests + Formatting

Done

---------

Co-authored-by: Jakub Žádník <kubouch@gmail.com>
2024-06-25 18:33:37 -07:00
Ian Manske
55ee476306
Define keywords (#13213)
# Description
Some commands in `nu-cmd-lang` are not classified as keywords even
though they should be.

# User-Facing Changes
In the output of `which`, `scope commands`, and `help commands`, some
commands will now have a `type` of `keyword` instead of `built-in`.
2024-06-25 18:32:54 -07:00
Darren Schroeder
f241110005
implement autoloading (#13217)
# Description

This PR implements script or module autoloading. It does this by finding
the `$nu.vendor-autoload-dir`, lists the contents and sorts them by file
name. These files are evaluated in that order.

To see what's going on, you can use `--log-level warn`
```
❯ cargo r -- --log-level warn
    Finished dev [unoptimized + debuginfo] target(s) in 0.58s
     Running `target\debug\nu.exe --log-level warn`
2024-06-24 09:23:20.494 PM [WARN ] nu::config_files: set_config_path() cwd: "C:\\Users\\fdncred\\source\\repos\\nushell", default_config: config.nu, key: config-path, config_file_specified: None
2024-06-24 09:23:20.495 PM [WARN ] nu::config_files: set_config_path() cwd: "C:\\Users\\fdncred\\source\\repos\\nushell", default_config: env.nu, key: env-path, config_file_specified: None
2024-06-24 09:23:20.629 PM [WARN ] nu::config_files: setup_config() config_file_specified: None, env_file_specified: None, login: false
2024-06-24 09:23:20.660 PM [WARN ] nu::config_files: read_config_file() config_file_specified: None, is_env_config: true
Hello, from env.nu
2024-06-24 09:23:20.679 PM [WARN ] nu::config_files: read_config_file() config_file_specified: None, is_env_config: false
Hello, from config.nu
Hello, from defs.nu
Activating Microsoft Visual Studio environment.
2024-06-24 09:23:21.398 PM [WARN ] nu::config_files: read_vendor_autoload_files() src\config_files.rs:234:9
2024-06-24 09:23:21.399 PM [WARN ] nu::config_files: read_vendor_autoload_files: C:\ProgramData\nushell\vendor\autoload
2024-06-24 09:23:21.399 PM [WARN ] nu::config_files: AutoLoading: "C:\\ProgramData\\nushell\\vendor\\autoload\\01_get-weather.nu"
2024-06-24 09:23:21.675 PM [WARN ] nu::config_files: AutoLoading: "C:\\ProgramData\\nushell\\vendor\\autoload\\02_temp.nu"
2024-06-24 09:23:21.817 PM [WARN ] nu_cli::repl: Terminal doesn't support use_kitty_protocol config
```

# 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-06-25 18:31:54 -07:00
Jack Wright
0dd35cddcd
Bumping version to 0.95.1 (#13231)
Marks development for hotfix
2024-06-25 18:26:07 -07:00
Jakub Žádník
f93c6680bd
Bump to 0.95.0 (#13221)
<!--
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.
-->

# 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-06-25 21:29:47 +03:00
Devyn Cairns
43e349a274
Mitigate the poor interaction between ndots expansion and non-path strings (#13218)
# Description

@hustcer reported that slashes were disappearing from external args
since #13089:

```
$> ossutil ls oss://abc/b/c
Error: invalid cloud url: "oss:/abc/b/c", please make sure the url starts with: "oss://"

$> ossutil ls 'oss://abc/b/c'
Error: oss: service returned error: StatusCode=403, ErrorCode=UserDisable, ErrorMessage="UserDisable", RequestId=66791EDEFE87B73537120838, Ec=0003-00000801, Bucket=abc, Object=
```

I narrowed this down to the ndots handling, since that does path parsing
and path reconstruction in every case. I decided to change that so that
it only activates if the string contains at least `...`, since that
would be the minimum trigger for ndots, and also to not activate it if
the string contains `://`, since it's probably undesirable for a URL.

Kind of a hack, but I'm not really sure how else we decide whether
someone wants ndots or not.

# User-Facing Changes
- bare strings not containing ndots are not modified
- bare strings containing `://` are not modified

# Tests + Formatting
Added tests to prevent regression.
2024-06-24 16:39:01 -07:00
Bruce Weirdan
4509944988
Fix usage parsing for commands defined in CRLF (windows) files (#13212)
Fixes nushell/nushell#13207

# Description
This fixes the parsing of command usage when that command comes from a
file with CRLF line endings.

See nushell/nushell#13207 for more details.

# User-Facing Changes
Users on Windows will get correct autocompletion for `std` commands.
2024-06-23 18:43:05 -05:00
Devyn Cairns
0459b74613 knocking off some TODOs, closures work now 2024-06-22 16:18:30 -07:00
Piepmatz
9b7f899410
Allow missing fields in derived FromValue::from_value calls (#13206)
# Description
In #13031 I added the derive macros for `FromValue` and `IntoValue`. In
that implementation, in particular for structs with named fields, it was
not possible to omit fields while loading them from a value, when the
field is an `Option`. This PR adds extra handling for this behavior, so
if a field is an `Option` and that field is missing in the `Value`, then
the field becomes `None`. This behavior is also tested in
`nu_protocol::value::test_derive::missing_options`.

# User-Facing Changes
When using structs for options or similar, users can now just emit
fields in the record and the derive `from_value` method will be able to
understand this, if the struct has an `Option` type for that field.

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting
A showcase for this feature would be great, I tried to use the current
derive macro in a plugin of mine for a config but without this addition,
they are annoying to use. So, when this is done, I would add an example
for such plugin configs that may be loaded via `FromValue`.
2024-06-22 13:31:09 -07:00