Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add status current-commandline #9296

Merged
merged 4 commits into from
Oct 26, 2022
Merged

Conversation

mqudsi
Copy link
Contributor

@mqudsi mqudsi commented Oct 22, 2022

src/parser.h Outdated

/// Set a parser status variable
void set_status_var(parser_status_var_t var, wcstring val) {
ASSERT_IS_MAIN_THREAD();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ridiculousfish do you want me to remove this assert?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah

@faho
Copy link
Member

faho commented Oct 22, 2022

For context: status current-command was introduced in 3.0, released in December 2018 (#813), which is also when $_ was declared deprecated.

I am not against removing $_ - it's a terrible name. However, it is still used - for example a bunch of oh-my-fish title functions do (for the record oh-my-fish still claims compatibility with fish 2.2.0, which I don't believe is helpful, but it is what it is).

And given that we might want to have 3.6.0 go out sooner rather than later, because we have already found an issue with the imminent new macOS version (53cb3a9), I would not want to have this in the current cycle.

status current-commandline on its own I wouldn't have an issue with. I would like some tests.

@faho faho added this to the fish-future milestone Oct 22, 2022
@mqudsi
Copy link
Contributor Author

mqudsi commented Oct 22, 2022

status current-command doesn’t currently have any tests because it doesn’t work (the same) in a non-interactive setting (though expect-based tests {sh,w}ould work?)

I also don’t like the current current-command behavior; it isn’t the current command but the head of the current command line which (maybe) has nothing to do with current command. I tried writing tests for it but didn’t like codifying behavior I don’t like, lol.

IMHO we should ship this and fix current-command together, having it return the actual command? Eg true 1 && foo where foo is function foo; status current-command; end would be nice to return foo and not true while status current-commandline would return the whole thing (as it does already in this PR).

Most status current-command usages are in bindings or completions where the behavior wouldn’t change except in good ways I think, but typed out at the interactive prompt its behavior would change. There’s probably no one doing that outside of contrived demonstrations.

@faho
Copy link
Member

faho commented Oct 22, 2022

status current-command doesn’t currently have any tests because it doesn’t work (the same) in a non-interactive setting (though expect-based tests {sh,w}ould work?)

I'm asking for tests for your new command, to be clear. I realize that sometimes we do things that are awkward to test, and I don't mean to require 100% tests for everything, but in this case it seems possible to do a pexpect test, and I would appreciate that.

It would also help explain the differences in behavior between status current-command and status current-commandline.

IMHO we should ship this and fix current-command together

I don't really have an opinion on current-command (i.e. the old one) at the moment.

I find it a bit awkward to change things together like this - it introduces a new command and changes how internals work and removes a deprecated variable. But if that's what's necessary, then sure.

But if the removal of $_ can't be removed from this and then committed separately later I would not want it for 3.6.0.

@mqudsi
Copy link
Contributor Author

mqudsi commented Oct 22, 2022

$_ can be added to this easily, I’ll do it later today if I get the chance.

@mqudsi mqudsi force-pushed the parser_status_vars branch from cbdc1fe to 2bef0d6 Compare October 23, 2022 03:03
@mqudsi
Copy link
Contributor Author

mqudsi commented Oct 23, 2022

Re-added $_ and added a pexpect test. I guess we can just change status current-cmd later/separately.

Copy link
Member

@ridiculousfish ridiculousfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

@@ -239,6 +239,12 @@ struct eval_res_t {
: status(status), break_expand(break_expand), was_empty(was_empty), no_status(no_status) {}
};

enum class parser_status_var_t : uint8_t {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we expect to have a lot more of these variables, I think we can do without this enum. In every call site we know which status variable we're accessing so we don't benefit from having these be indexable.

Also (as your changes illustrate) any time we want to set current_command we probably also want to set current_commandline. We can structure these so we're less likely to forget.

I suggest just making a struct:

struct status_vars_t {
    wcstring command;
    wcstring commandline;
};

and then you can set and get that struct. We don't even really need a setter or getter, just put it in library_data_t.

other than that this looks good to me

There should be no functional changes in this commit.

The global variable `$_` set in the parser variables by `reader.cpp` and
read by the `status` builtin was deprecated in fish 2.0 but kept around
internally because there's no good way to store/share/forward parser
variables.

A new enum is added that identifies the status variable and they are
stored in a private array in the parser. There is no need for
synchronization because they are only set during job init and never
thereafter. This is currently asserted via ASSERT_IS_MAIN_THREAD() but
that assert can be dropped in the interest of making the parser possible
to clone and use from worker threads.

The old `$_` global variable is still kept for backwards compatibility,
though it will be dropped in a future release.
Makes it possible to retrieve the currently executing command line as
opposed to the currently executing command (`status current-command`).

Closes fish-shell#8905.
Instead of using an enum + array, just use a struct and drop the getter and
setter methods from `parser_t`.
@mqudsi mqudsi force-pushed the parser_status_vars branch from 27c8bfc to 7133285 Compare October 26, 2022 17:15
@mqudsi mqudsi merged commit 7133285 into fish-shell:master Oct 26, 2022
@mqudsi mqudsi deleted the parser_status_vars branch October 28, 2022 19:06
@faho faho modified the milestones: fish-future, fish 3.6.0 Nov 2, 2022
@faho faho changed the title Parser status vars Add status current-commandline Nov 2, 2022
@thomcc
Copy link
Contributor

thomcc commented Jan 12, 2023

Totally random thing I coincidentally happened to noticed when playing around with the 3.6.0 changes: status's completions doesn't include current-commandline, so perhaps it got missed in this PR? Sorry if this is already fixed elsewhere (and for the extremely lazy way I'm reporting this issue).

@mqudsi
Copy link
Contributor Author

mqudsi commented Jan 14, 2023

Hey nice to bump into you here, @thomcc. You're right, the completions for this were overlooked. I'll add them and if we do a 3.6.1 we can backport the fix.

EDIT added in 256713b and backported in f5ebe28.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants