Commit Graph

460 Commits

Author SHA1 Message Date
Fabian Boehm
4d2f7b0c0d
ast: Require --help to parse more keywords as decorated statement (#10000)
This makes it so

```fish
if -e foo
    # do something
end
```

complains about `-e` not being a command instead of `end` being used
outside of an if-block.

That means both that `-e` could now be used as a command name (it
already can outside of `if`!) *and* that we get a better error!

The only way to get `if` to be a decorated statement now is to use `if
-h` or `if --help` specifically (with a literal option).

The same goes for switch, while and begin.

It would be possible, alternatively, to disallow `if -e` and point
towards using `test` instead, but the "unknown command" message should
already point towards using `test` more than pointing at the
"end" (that might be quite far away).
2023-09-19 17:34:13 +02:00
Henrik Hørlück Berg
731f06bdb9 fixup! Forward-port #9931 2023-09-15 15:10:14 +02:00
Henrik Hørlück Berg
0cc1aef725
Forward-port #9931 2023-09-15 14:58:54 +02:00
Henrik Hørlück Berg
6ee81c0f15
Crash if invariant is broken 2023-09-15 14:46:53 +02:00
Henrik Hørlück Berg
5407d0b785
Apply code review fixes 2023-09-15 14:44:58 +02:00
Henrik Hørlück Berg
d6a9ad66a7
Allow CancelChecker to be FnMut 2023-09-15 14:44:58 +02:00
Henrik Hørlück Berg
d277a50564
Combine previous attempt into this
*singing it's the best of both worlds*
2023-09-15 14:44:58 +02:00
Henrik Hørlück Berg
e0bbf3eee9
Port wilcard.{cpp,h} to Rust
- This is untested and unused, string ownership is very much subject to change
- Ports the minimally necessary parts of complete.rs as well
- This should fix an infinite loop in `create_directory` in `path.rs`, the first
  `wstat` loop only breaks if it fails with an error that's different from
  EAGAIN
2023-09-15 14:44:58 +02:00
Henrik Hørlück Berg
80d92dcc6d
Port the easy part of wildcard.{h,cpp}
- wildcard_match is now closer to the original that is linked in a comment, as
  pointer-arithmetic translates very poorly. The act of calling wildcard
  patterns wc or wildcard is kinda confusing when wc elsewhere is widechar.
2023-09-15 14:38:30 +02:00
Johannes Altmanninger
e1f5751ba0 fixup! builtin status: use program name constant again 2023-09-14 20:46:42 +02:00
Johannes Altmanninger
61d506afd0 builtin status: use program name constant again 2023-09-14 20:42:25 +02:00
Fabian Boehm
fa390334a8 Remove wcs/wcwidth ffi calls
This was ported a while back, we can just call the rust version
2023-09-05 21:57:38 +02:00
Henrik Hørlück Berg
676c3c9bc2 Re-use DEFAULT_PATH in setup_path
- No need to hard-code a different default
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
008764a2cd Make DEFAULT_PATH allow overriding system binaries
This is in regards to a comment on 290d07a833, which resulted in 46c967903d.
Those commits handled the default path when it is unset on startup.
DEFAULT_PATH is used when PATH is unset at runtime as far as I can tell.

As far as I can tell this has had the non-overidding ordering behavior since inception
(or at least 17 years ago ea998b03f2).
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
eacbd6156d Port and adopt main written in Rust
We don't change anything about compilation-setup, we just immediately jump to
Rust, making the eventual final swap to a Rust entrypoint very easy.

There are some string-usage and format-string differences that are generally
quite messy.
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
96e58dac21 Port env_init to Rust
- This does not adopt it.
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
e7f8fb04cc Add BUILD_VERSION to lib.rs
In CMake this used a `version` file in the CARGO_MANIFEST_DIR, but
relying on that is problematic due to change-detection, as if we add
`cargo-rerun-if-changed:version`, cargo would rerun every time if the file does
not exist, since cargo would expect the file to be generated by the
build-script. We could generate it, but that relies on the output of `git
describe`, whose dependencies we can only limit to anything in the
`.git`-folder, again causing unnecessary build-script runs.

Instead, this reads the `FISH_BUILD_VERSION`-env-variable at compile time
instead of the `version`-file, and falls back to calling git-describe through
the `git_version`-proc-macro. We thus do not need to deal with extraneous
build-script running.
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
360ba46660 Make ConfigPaths store as PathBuf
- These are paths, we can just store them raw.
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
25d207a8ce Make get_current_exe use impl AsRef<Path>
- It does not need to require the default to be valid UTF8
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
a92804a8a1 Port MISSING_HELP and MISSING (arg)
C++ main used getopt (no w!), which appears to internally print
error-messages. The Rust version will use `wgetopter_t`, and therefore needs to
print this itself.
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
7c2311abd7 Make methods in path not unnecessairly take &mut 2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
cf8e0ae1b5 Make ParsedSource::new pub
It will be used from main
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
3777bc941f Port history::start_private_mode to Rust 2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
c5c5043d7e Make PROGRAM_NAME safe, fix cmp
- It is currently never set, but will be set once `main` is ported
- `should_suppress_stderr_for_tests` used to be PROGRAM_NAME !=
  TESTS_PROGRAM_NAME, but the equivalent C++ code was
  `!std::wcscmp(program_name, TESTS_PROGRAM_NAME)`, and `wcsmp` returns
  zero if they are equal, thus is equivalent to `==` in Rust
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
e4df340f43 Forward CMake configs to Cargo 2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
5db08e1126 Make CARGO_MANIFEST_DIR for fish-rust equal to src 2023-09-05 11:38:59 +02:00
Johannes Altmanninger
a3311c9b09 Fix incorrect port of write_to_fd 2023-09-03 14:03:14 +02:00
yanshay
01db48a712
Added fish_sequence_key_delay_ms to set time to wait between sequence key presses (#7401) (#9926)
* added support for fish_sequence_key_delay_ms to set how long to wait between sequence key presses

* fixed cargo fmt
2023-08-30 23:12:22 +02:00
Fabian Boehm
b454b3bc40 Also allow command and in a pipeline
Similar to `time`, except that one is more common as a command.

Note that this will also allow `builtin and`, which is somewhat
useless, but then it is also useless outside of a pipeline.

Addition to #9985
2023-08-26 13:45:54 +02:00
Fabian Boehm
03e659f96d Bring back "(deleted)" hack for status fish-path
This is untested mostly because it is supremely awkward to test.

Fixes #9925
2023-08-25 22:02:55 +02:00
Fabian Boehm
482616f101 parse_util: Only reject time in a pipeline without decorator
This allows e.g. `foo | command time`, while still rejecting `foo | time`.

(this should really be done in the ast itself, but tbh most of
parse_util kinda should)

Fixes #9985
2023-08-25 19:45:15 +02:00
Fabian Boehm
03402e572d format 2023-08-25 16:28:41 +02:00
Fabian Boehm
06b89083d5 tinyexpr: Check for wcstod errors
This would otherwise unwrap() an Err and crash.
2023-08-25 16:15:52 +02:00
Henrik Hørlück Berg
05c44df1a4 Run cargo fmt with Rustfmt 1.6.0
- "1.6.0" now supports formatting let-else statements which we use liberally,
  and appears to have some fixes in regards to long-indented-lines with macros
  like `wgettext_ft!`
- This commit updates the formatting so that devs with the latest stable don't
  see random format-fixes upon running `cargo fmt`
2023-08-24 18:16:24 +02:00
Fabian Boehm
3caabdcbc9 Switch math to using Arguments
Removes some duplicated code and lets this do chunked reading.
2023-08-20 14:52:58 +02:00
ridiculousfish
46f9a8bb28 Stop using sprintf in builtin_random 2023-08-19 20:19:54 -07:00
ridiculousfish
e500250775 Minor improvement to get_depth in ast.rs 2023-08-19 20:19:38 -07:00
ridiculousfish
04299cb4c9 Remove RgbColor::description
This was unused; deriving Debug is sufficient.
2023-08-19 20:04:23 -07:00
ridiculousfish
eeecd6517d Remove FileId::dump
Instead just derive Debug. No reason for this to be custom.
2023-08-19 17:45:17 -07:00
ridiculousfish
d2f7a3507b Implement to_wstr() for ParseTokenType and ParseKeyword
This cleans up some messy call sites.
2023-08-19 17:45:10 -07:00
ridiculousfish
cc1e4b998a Remove some dead bridge code
This was obviated after the AST was ported to Rust.
2023-08-19 16:31:42 -07:00
Fabian Boehm
53a5ce52c5 Implement FLOGF formatting
Note: This *requires* an argument after the format string:

```rust
FLOGF!(debug, "foo");
```

won't compile. I think that's okay, because in that case you should
just use FLOG.

An alternative is to make it skip the sprintf.
2023-08-19 16:56:59 +02:00
Fabian Boehm
798d7427f7 Switch broken uses of FLOGF to FLOG
"FLOGF!" is supposed to treat its first argument as a format
string (but doesn't because that part isn't implemented currently).

That means running something like

```rust
FLOGF!(term_support, "curses var", var_name, "=", value);
```

That would rightly just print "curses var", ignoring the other
arguments.

By contrast, FLOG! is the literal "just join these as a string"
version.
2023-08-19 16:56:59 +02:00
Henrik Hørlück Berg
bc29b4aee1 Move edition and MSRV to workspace 2023-08-19 15:18:38 +02:00
Henrik Hørlück Berg
c23f419af1 Use the workspace from CMake
- Make CMake use the correct target-path
- Make build.rs use the correct target dir

Workspaces place it in the project root by default, the alternative to making
this change is to add a `.cargo/config.toml` file with

```toml
[build]
target-dir = "fish-rust/target"
```

Which I think is unnecessary, as we likely want to use the new location anyways.
2023-08-19 15:18:38 +02:00
Henrik Hørlück Berg
87df7b9adf Use a cargo workspace
- This allows running `cargo fmt/clippy/test/etc` from root
- Ideally the root should be the fish-rust package instead of being virtual, but
  that requires changed to CMake/Corrosion. This change should instead be
  completely compatible with our existing setup.
- This also means we will only have on `Cargo.lock` for all current and future
  crates.
2023-08-19 15:18:38 +02:00
Henrik Hørlück Berg
1fa56972b5 Fix clippy lint in widestring-suffix 2023-08-19 15:18:38 +02:00
Fabian Boehm
566123edc6
Port builtin count to rust (#9963)
* Port builtin count to rust

* Explicitly use wstring
2023-08-18 23:18:52 +02:00
Fabian Boehm
a29aa44183 functions: Fix command name
This was "function", needs to be "function*s*".

It was only an issue in the option parsing because we set cmd there
again instead of passing it. Maybe these should just be file-level constants?
2023-08-18 17:16:44 +02:00
Henrik Hørlück Berg
88da7121af Adopt appendln 2023-08-16 18:37:27 +02:00