Commit Graph

5212 Commits

Author SHA1 Message Date
Mahmoud Al-Qudsi
51275525c1 Speed up extract_prefix_and_unescape_yaml
On the completions and history thread, the parent function
HistoryFileContents::decode_item() is responsible for ~60% of the CPU time, and
extract_prefix_and_unescape_yaml() alone comprising 14% (of the total).

This change removes allocations in the event that the history item is either
fully or partially plain yaml with no escapes to begin with, and brings down the
execution time of this function to only 7% of the total execution time.

The bulk of the remaining time is spent in wcs2string(), which is called
unconditionally and is naturally alloc-heavy.
2024-05-15 22:42:19 -05:00
ridiculousfish
caef202551 Fix some more clippies and enable more warnings 2024-05-15 20:05:35 -07:00
Fabian Boehm
f1e19884fb Add set --no-event
This allows running `set` without triggering any event handlers.

That is useful, for example, if you want to set a variable in an event
handler for that variable - we could do it, for example, in the
fish_user_path or fish_key_bindings handlers.

This is something the `block` builtin was supposed to be for, but it
never really worked because it only allows suppressing the event for
the duration, they would fire later. See #9030.

Because it is possible to abuse this, we only have a long-option so
that people see what is up.
2024-05-14 17:31:47 +02:00
Fabian Boehm
403920e9d6 input: Remove all_mappings_cache
Replace it with a chained iterator.

This not only simplifies the code, but also removes a RefCell.
2024-05-14 16:14:02 +02:00
Johannes Altmanninger
a19ff4989a Prevent out-of-order execution following repaint
Commit a583fe723 ("commandline -f foo" to skip queue and execute immediately,
2024-04-08) fixed the execution order of some bindings but was partially
backed out in 5ba21cd29 (Send repaint requests through the input queue again,
2024-04-19) because repainting outside toplevel yields surprising results
(wrong $status etc).

Transient prompts wants to first repaint and then execute some more readline
commands, all within a single binding.  This was broken by the second commit
because that one defers the repaint until after the binding has finished.

Work around this problem by deferring input events again while a readline
event was queued. This is closest to the historical behavior.

The implementation feels hacky; we might find odd situations.
For example,

    commandline -f repaint end-of-line
    set token (commandline -t)

sets the wrong token.
Probably not a very important case. We could throw an error or make it work
by letting "commandline -t" drain the input queue.

That seems too complicated, better change repaints to not use the input queue
(and fake $status etc). Let's try to do that in future.

Closes #10492
2024-05-13 10:44:12 +02:00
ridiculousfish
d6e231af0d Fix some clippies 2024-05-12 14:55:35 -07:00
ridiculousfish
172fb22692 Clean up and correct O_SEARCH definitions
Correct the FreeBSD constant and simplify some of the cfg() logic.
2024-05-11 13:20:34 -07:00
Jonathan Krebs
4606b02d44 rustfmt 2024-05-11 11:12:29 -07:00
Jonathan Krebs
a148760963 cd: open directory with O_SEARCH or O_PATH, when the platform supports it 2024-05-11 11:12:29 -07:00
Jonathan Krebs
2ecbdb9ae7 cleanup: fds::open_dir - remove mode argument
[w]open_dir does not pass O_CREAT, so the mode argument to open is never used.
also, O_CREAT | O_DIRECTORY could not be used (portably) to create a directory.
(on POSIX does not specify what should happen, on Linux it is EINVAL.)
2024-05-11 11:12:29 -07:00
Mahmoud Al-Qudsi
35a16e3713 Rename FISH_TSAN_WORKAROUNDS and add feature to Cargo.toml
rustc 1.80 now complains about features not declared in Cargo.toml and cfg
keys/values not declared by build.rs to protect against typos or misuse (you
think you're using the right condition but you're not). See
rust-lang/cargo#10554 and rust-lang/rust#82450.

(We're not actually using TSAN under CI at this time, but I do want to re-enable
it at some point — especially if we get multithreaded execution going — using
the rust-native TSAN configuration.)

I'll be updating the `rsconf` crate and patching `build.rs` accordingly to also
handle the warnings about unknown cfg values, but tsan is a feature and not a
cfg and these can be dealt with in `Cargo.toml` directly.
2024-05-09 13:58:42 -05:00
Mahmoud Al-Qudsi
059b842d1b is_wsl(): Move .copied() earlier in the iter pipeline
This is a best practice that usually helps with auto vectorization, as llvm has
a hard time seeing through the references.
2024-05-09 13:33:50 -05:00
Mahmoud Al-Qudsi
5dcc5955fb Don't allocate a vector twice in wcs2zstring()
We were passing a slice (and not a vec) to `CString::new()`, meaning it would
allocate a new Vec internally to hold the bytes.

Also document that the resulting CString will be silently truncated at the first
interior NUL.
2024-05-09 13:19:06 -05:00
Mahmoud Al-Qudsi
883bcbad83 Remove possible panic from wperror() 2024-05-09 11:20:09 -05:00
Mahmoud Al-Qudsi
84be043f31 Clean up src/libc.rs some
Update the CVAR!() macro and use it more.
2024-05-08 22:34:10 -05:00
Mahmoud Al-Qudsi
92eee61fb5 Convert colors::Flags to a bitflags enum
We use accessors and setters for all operations, so there's no benefit to
storing the modifiers as separate boolean fields.
2024-05-07 14:03:38 -05:00
Fabian Boehm
41a0fe2b1d history: Check for cmd key earlier
This shows up hot in `perf record ./fish` style profiles.

This assumes that "- cmd" can't be escaped.
2024-05-07 20:23:32 +02:00
Mahmoud Al-Qudsi
f709795a3a Reserve vector capacity upfront in colors::named_color_names()
Only because why not.
2024-05-07 13:09:40 -05:00
Mahmoud Al-Qudsi
fd2ea3ff0f Add more tests for color::try_parse_rgb() 2024-05-07 13:00:11 -05:00
Mahmoud Al-Qudsi
5b79f267d6 Optimize color::try_parse_rgb()
The function was repeatedly calling `s.char_at(n)` which is O(1) only for UTF-32
strings (so not a problem at the moment). But it was also calling `hex_digit(n)`
twice for each `n` in the 3-digit case, causing unnecessary repeated parsing of
individual characters into their radix-16 numeric equivalents, which could be
avoided just by reusing the already calculated result.
2024-05-07 12:53:44 -05:00
Fabian Boehm
b9d44407b3 tokenizer: Stop copying the start string 2024-05-07 16:59:35 +02:00
Mahmoud Al-Qudsi
5f8f799cf7 Replace C++ doc \return with "Return"
quick_replace '\\\\return(s)? ' 'Return$1 ' src/

Filtered to only lines beginning with //
2024-05-06 14:59:36 -05:00
Mahmoud Al-Qudsi
589639a87d Replace C++-style \p with Markdown backticks
quick_replace '\\\\p ([a-zA-Z0-9_]+)' '`$1`' src/

Filtered to only lines beginning with //
2024-05-06 14:59:23 -05:00
Mahmoud Al-Qudsi
a35925b3ed Don't use $HOME under cargo test harness
We will continue to use the "normal" fish base directory detection when using
the CMake test harness which properly sets up a sandboxed $HOME for fish to use,
but when running source code tests with a bare `cargo test` we don't want to
write to the actual user's profile.

This also works around test failures when running `cargo test` under CI with a
locked-down $HOME directory (see #10474).
2024-05-06 14:31:51 -05:00
Fabian Boehm
2a121ef1aa function: Check if --argument-names gets a valid variable name
These were accepted but then ineffective because the only way these
are used is to set a variable.
2024-05-06 17:00:45 +02:00
Fabian Boehm
39b996332e functions: Fix --argument-names display
Mentioned in #10465
2024-05-06 17:00:45 +02:00
Mahmoud Al-Qudsi
2d2b75003d Fix format string presumably broken under i686
%ld expects a 32-bit param under x86, change it to %lld instead.
2024-05-04 22:57:55 -05:00
Mahmoud Al-Qudsi
476b360eb8 Remove rust test dependency on cmake output
The test_history_formats test was reading from build/tests/ which is an artifact
of the cmake test runner. The source code tests should not depend on the cmake
test harness at all, so this is changed to read from the original test source in
the ./tests/ directory instead.
2024-05-04 20:49:49 -05:00
Mahmoud Al-Qudsi
6b43a96d09 fixup! Work around i586 wcstod test failure 2024-05-04 20:29:40 -05:00
Mahmoud Al-Qudsi
4d58a31670 Work around i586 wcstod test failure
As documented in #10474, there are issues with 64-bit floating point rounding
under x86 targets without SSE2 extensions, where x87 floating point math causes
imprecise results.

Document the shortcoming and provide some version of the test that passes
regardless of architecture.
2024-05-04 20:21:56 -05:00
Mahmoud Al-Qudsi
a99a7e65e7 Fix build failures when cmake never used
FISH_BUILD_DIR (nominally, ./build) is created by cmake. If you only check out
the project via git and then run `cargo build`, this directory won't exist and
many of the tests will fail.
2024-05-04 19:47:16 -05:00
Mahmoud Al-Qudsi
72259f658f Fix format string for failing test
%ld expects a 4-byte parameter on 32-bit architectures and an 8-byte parameter
on 64-bit architectures, but we supplied are trying to supply a 64-bit parameter
that would overflow 32-bit storage.

Use %lld instead which expects a `long long` parameter, which should be 8-bytes
under both architectures.

See #10474
2024-05-04 19:40:31 -05:00
Johannes Altmanninger
4e816212a1 Check for unsupported "time &" in the proper place
This means we can detect this error also for simple blocks.

While at it do some cleanup in the area.
2024-05-03 09:37:56 +02:00
Johannes Altmanninger
a126d2aeba Revert "Remove redundant default escape delay"
I think given a local terminal running fish on a remote system, we can't
assume that an input sequence like \ea is sent all in one packet. (If we
could that would be perfect.)

Let's readd the default escape delay, to avoid a potential regression, but
make it only apply to raw escape bindings like "bind \e123". Treat sequences
like "bind escape,1,2,3" like regular sequences, so they can be bound on
all terminals.

This partially reverts commit b815319607.
2024-05-03 09:37:56 +02:00
Johannes Altmanninger
d855d1a2e6 Interpret escape as alt only if it's the escape byte
No need to take this code path when an unambiguous, prefix-free encoding is
used for the escape key.
2024-05-03 09:36:35 +02:00
Johannes Altmanninger
e1eeb3177e Silence clippy lint 2024-05-03 09:36:35 +02:00
Anurag Singh
4fa8d95b98 Move push_timer to measure command substitution timing too 2024-05-03 09:32:26 +02:00
Johannes Altmanninger
d4ecea56df Fix regression spuriously expanding abbr with cursor outside token
Given "abbr foo something", the input sequence

    foo<space><ctrl-z><space>

would re-expand the abbreviation on the second space which is surprising
because the cursor is not at or inside the command token.  This looks to be
a regression from 00432df42 (Trigger abbreviations after inserting process
separators, 2024-04-13)

Happily, 69583f303 (Allow restricting abbreviations to specific commands
(#10452), 2024-04-24) made some changes that mean the bad commit seems no
longer necessary. Not sure why it works but I'll take it.
2024-05-03 08:39:05 +02:00
Johannes Altmanninger
91b007cab7 Limit ctrl-r autofill/replace to a single command substitution
As reported on gitter, commands like "rm (...)" sometimes want a previous
command inside the parentheses. Let's try that.  If a user actually wants
to search for a command substitution they can move the cursor outside the
command substitution, or type the search string after pressing ctrl-r?
2024-05-01 20:21:18 +02:00
Fabian Boehm
f551eeadfe Revert "Remove unused import"
It's not unused

This reverts commit 69fb620073.
2024-05-01 12:58:36 +02:00
Fabian Boehm
89b74a6983 Remove a few uses of unwrap 2024-05-01 12:58:29 +02:00
Johannes Altmanninger
69fb620073 Remove unused import 2024-05-01 12:53:00 +02:00
Johannes Altmanninger
b00899179f Don't indent multi-line quoted strings; do indent inside ()
On a command with multiline quoted string like

    begin
        echo "line1
    line2"
    end

we actually indent line2 which seeems misleading because the indentation
changes the behavior when typed into a script.

This has become more prominent since commits
- a37629f86 (fish_clipboard_copy: indent multiline commands, 2024-04-13)
- 611a0572b (builtins type/functions: indent interactively-defined functions, 2024-04-12)
- 222673f33 (edit_command_buffer: send indented commandline to editor, 2024-04-12)

which add indentation to an exported commandline.

Never indent quoted strings, to make sure the rendering matches the semantics.
Note that we do need to indent the opening quote which is fine because
it's on the same line.

While at it, indent command substitutions recursively.  That feature should
also be added to fish_indent's formatting mode (which is the default).
Fortunately the formatting mode already works fine with quoted strings;
it does not indent them. Not sure how that's done and whether indentation
can use the same logic.
2024-04-30 14:12:48 +02:00
Johannes Altmanninger
2f6ed61833 parse_util_cmdsubst_extent to return an exclusive range
Given "1(23)4", this function returns an inclusive range, from the opening
to the closing parenthesis.  The subcommand is extracted by incrementing
the range start and interpreting the result as an exclusive range.

This is confusing, especially if we want to add multi-character quotes.
Change it to always return the full range (including parentheses) and provide
an easy way to access the command string.

While at it, switch to returning an enum.

This change is perhaps larger and more complex than necessary (sorry)
because it is mainly made with multi-character quotes in mind.  Let's see
if that works out.
2024-04-30 14:12:48 +02:00
Johannes Altmanninger
861feb7b46 Minor simplification in tokenizer 2024-04-30 14:00:06 +02:00
Johannes Altmanninger
29be454652 Move parse_util tests to separate file 2024-04-30 14:00:06 +02:00
Fabian Boehm
8639d7e450 Remove allow-unused-imports 2024-04-29 22:00:59 +02:00
Fabian Boehm
4d4ef7fa40 Remove backports for 1.67
This removes IsOkAnd and the is_some_and method.

I cannot actually find is_none_or in the stdlib?

I've kept the trait name to avoid changing it now and then later, maybe this should
be moved elsewhere to avoid claiming it's an stdlib thing?
2024-04-29 22:00:59 +02:00
Johannes Altmanninger
964d3fff15 Keep undo history across prompts
After abandoning a commandline (for example with ctrl-c) it's nice to be
able to restore it. There is little reason to discard the requisite undo
information, so keep it.
2024-04-29 09:20:09 +02:00
ridiculousfish
3afe0bb569 Remove LoopedRead and LoopedWrite
These were unused.
2024-04-28 11:15:48 -07:00