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

Use CommandType in more places #12832

Merged
merged 8 commits into from
May 18, 2024
Merged

Conversation

IanManske
Copy link
Member

Description

Kind of a vague title, but this PR does two main things:

  1. Rather than overriding functions like Command::is_parser_keyword, this PR instead changes commands to override Command::command_type. The CommandType returned by Command::command_type is then used to automatically determine whether Command::is_parser_keyword and the other is_{type} functions should return true. These changes allow us to remove the CommandType::Other case and should also guarantee than only one of the is_{type} functions on Command will return true.
  2. Uses the new, reworked Command::command_type function in the scope commands and which commands.

User-Facing Changes

  • Breaking change for scope commands: multiple columns (is_builtin, is_keyword, is_plugin, etc.) have been merged into the type column.
  • Breaking change: the which command can now report plugin or keyword instead of built-in in the type column. It may also now report external instead of custom in the type column for known externs.

@IanManske IanManske added pr:breaking-change This PR implies a change affecting users and has to be noted in the release notes refactor pr:commands This PR changes our commands in some way labels May 10, 2024
@fdncred
Copy link
Collaborator

fdncred commented May 10, 2024

I don't really want to lose the granularity that we have in scope commands now. I haven't looked close enough at this PR to determine if that is happening. Do we have all these categories still, just represented in the type column?

│ 5 │ is_builtin │
│ 6 │ is_sub │
│ 7 │ is_plugin │
│ 8 │ is_custom │
│ 9 │ is_keyword │
│ 10 │ is_extern │

I'd like to be able to keep this level of detail if we can. Here's part of why I'm thinking this. I've been brainstorming a new command that is really about learning nushell. Maybe a tutor subcommand that has a kind of periodic table of commands that shows you how/where you can use them. This idea isn't fully formed yet but I was thinking of somehow grouping commands as described but with a flavor of "these commands work on tables", "these commands work on records", "these ... ints", "these ... strings", "these ... binary", etc.

So, I see a logical breakdown like these is_* bools as helpful for somehow participating in a periodic table of commands.

@IanManske
Copy link
Member Author

The is_sub column is still present, this PR doesn't touch that.

My understanding is that all the command types are, or should be, mutually exclusive. So, collapsing them all into a single column doesn't lose any granularity. E.g., instead of where is_plugin it's now where type == plugin.

@fdncred
Copy link
Collaborator

fdncred commented May 11, 2024

Just looking at the list and not the code, it seems that is_builtin, is_sub, is_keyword could be one command, maybe? i'm not sure what is_extern refers to. I'm not real familiar with how nushell assigns any of these really.

@IanManske
Copy link
Member Author

IanManske commented May 11, 2024

The current list of command types are:

  • Custom: a def declaration
  • Alias: an alias declaration
  • External: an extern declaration
  • Plugin: a plugin command
  • Keyword: a parser keyword like if, for, use, etc.
  • Builtin: all the other internal commands not covered by the above (they are not special in any way 😢)

At least, that is to my understanding, and so there doesn't seem to be much overlap.

@devyn
Copy link
Contributor

devyn commented May 11, 2024

I think this cleanup makes sense to me. There isn't a reason for those is_ methods to return true simultaneously, and much of the code just does an ugly match on all of them to figure out which one is true

@@ -18,7 +18,7 @@ impl NuHelpCompleter {
//Vec<(Signature, Vec<Example>, bool, bool)> {
let mut commands = full_commands
.iter()
.filter(|(sig, _, _, _, _)| {
Copy link
Member

Choose a reason for hiding this comment

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

Screaming at the comment above that was already out of date trying to explain the type.

Tuples considered harmful

@IanManske
Copy link
Member Author

Ok, let's give this a go.

@IanManske IanManske merged commit cc9f41e into nushell:main May 18, 2024
15 checks passed
@hustcer hustcer added this to the v0.94.0 milestone May 19, 2024
@fdncred fdncred mentioned this pull request May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:breaking-change This PR implies a change affecting users and has to be noted in the release notes pr:commands This PR changes our commands in some way refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants