Skip to content

view span & view files commands#7989

Merged
fdncred merged 4 commits intonushell:mainfrom
fdncred:view_commands
Feb 9, 2023
Merged

view span & view files commands#7989
fdncred merged 4 commits intonushell:mainfrom
fdncred:view_commands

Conversation

@fdncred
Copy link
Copy Markdown
Contributor

@fdncred fdncred commented Feb 6, 2023

Description

This PR does the following:

  1. Adds a new command called view span - which shows what is at the location of the span parameters
  2. Adds a new command called view - which just lists all the view commands.
  3. Renames view-source to view source.
  4. Adds a new command called view files - which shows you what files are loaded into nushell's EngineState memory.
  5. Added a Category::Debug and put these commands (and others) into it. (inspect needs to be added to it, but it's not landed yet)

Spans are important to nushell. One of their uses is to show where errors are. For instance, in this example, the leader lines pointing to parts of the command line are able to point to 10, /, and "bob" because each of those items have a span.

> 10 / "bob"
Error: nu::parser::unsupported_operation (link)

  × Types mismatched for operation.
   ╭─[entry #8:1:1]
 1 │ 10 / "bob"
   · ─┬ ┬ ──┬──
   ·  │ │   ╰── string
   ·  │ ╰── doesn't support these values.
   ·  ╰── int
   ╰────
  help: Change int or string to be the right types and try again.

Examples

view span

Example:

> $env.config | get keybindings | first | debug -r
... bunch of stuff
                    span: Span {
                        start: 68065,
                        end: 68090,
                    },
                },
            ],
            span: Span {
                start: 68050,
                end: 68101,
            },
        },
    ],
    span: Span {
        start: 67927,
        end: 68108,
    },
}

To view the last span:

> view span 67927 68108 
{
        name: clear_everything
        modifier: control
        keycode: char_l
        mode: emacs
        event: [
            { send: clearscrollback }
        ]
    }

To view the 2nd to last span:

view span 68065 68090
{ send: clearscrollback }

To view the 3rd to last span:

view span 68050 68101
[
            { send: clearscrollback }
        ]

view files

> view files  
╭────┬───────────────────────────────────────────────────────┬────────┬────────┬───────╮
│  # │                       filename                        │ start  │  end   │ size  │
├────┼───────────────────────────────────────────────────────┼────────┼────────┼───────┤
│  0 │ source                                                │      0 │      2 │     2 │
│  1 │ Host Environment Variables                            │      2 │   6034 │  6032 │
│  2 │ C:\Users\a_username\AppData\Roaming\nushell\plugin.nu │   6034 │  31236 │ 25202 │
│  3 │ C:\Users\a_username\AppData\Roaming\nushell\env.nu    │  31236 │  44961 │ 13725 │
│  4 │ C:\Users\a_username\AppData\Roaming\nushell\config.nu │  44961 │  76134 │ 31173 │
│  5 │ defs.nu                                               │  76134 │  91944 │ 15810 │
│  6 │ prompt\oh-my.nu                                       │  91944 │ 111523 │ 19579 │
│  7 │ weather\get-weather.nu                                │ 111523 │ 125556 │ 14033 │
│  8 │ .zoxide.nu                                            │ 125556 │ 127504 │  1948 │
│  9 │ source                                                │ 127504 │ 127561 │    57 │
│ 10 │ entry #1                                              │ 127561 │ 127585 │    24 │
│ 11 │ entry #2                                              │ 127585 │ 127595 │    10 │
╰────┴───────────────────────────────────────────────────────┴────────┴────────┴───────╯

entry #x will be each command you type in the repl (i think). so, it may be good to filter those out sometimes.

> view files | where filename !~ entry
╭───┬───────────────────────────────────────────────────────┬────────┬────────┬───────╮
│ # │                       filename                        │ start  │  end   │ size  │
├───┼───────────────────────────────────────────────────────┼────────┼────────┼───────┤
│ 0 │ source                                                │      0 │      2 │     2 │
│ 1 │ Host Environment Variables                            │      2 │   6034 │  6032 │
│ 2 │ C:\Users\a_username\AppData\Roaming\nushell\plugin.nu │   6034 │  31236 │ 25202 │
│ 3 │ C:\Users\a_username\AppData\Roaming\nushell\env.nu    │  31236 │  44961 │ 13725 │
│ 4 │ C:\Users\a_username\AppData\Roaming\nushell\config.nu │  44961 │  76134 │ 31173 │
│ 5 │ defs.nu                                               │  76134 │  91944 │ 15810 │
│ 6 │ prompt\oh-my.nu                                       │  91944 │ 111523 │ 19579 │
│ 7 │ weather\get-weather.nu                                │ 111523 │ 125556 │ 14033 │
│ 8 │ .zoxide.nu                                            │ 125556 │ 127504 │  1948 │
│ 9 │ source                                                │ 127504 │ 127561 │    57 │
╰───┴───────────────────────────────────────────────────────┴────────┴────────┴───────╯

User-Facing Changes

I renamed view-source to view source just to make a group of commands. No functionality has changed in view source.

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 -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace to check that all tests pass

After Submitting

If your PR had any user-facing changes, update the documentation after the PR is merged, if necessary. This will help us keep the docs up to date.

@fdncred fdncred added the notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes label Feb 6, 2023
@fdncred fdncred marked this pull request as ready for review February 6, 2023 16:18
@sholderbach
Copy link
Copy Markdown
Member

Love your push for debugging tools!

@fdncred fdncred changed the title view span command view span & view files commands Feb 6, 2023
@kubouch
Copy link
Copy Markdown
Contributor

kubouch commented Feb 8, 2023

It would be great if it could accept a span as a record, similar to what you get from the metadata command.

@fdncred fdncred merged commit 023e244 into nushell:main Feb 9, 2023
@fdncred fdncred deleted the view_commands branch February 9, 2023 17:35
@fdncred
Copy link
Copy Markdown
Contributor Author

fdncred commented Feb 9, 2023

Let's go with this for now. We can adjust as needed. I'm also thinking now that metadata should be a debug command too maybe?

@kubouch
Copy link
Copy Markdown
Contributor

kubouch commented Feb 9, 2023

Yeah, good idea. I was saying it because my profile command will also output span records that you could pipe into view span instead of including the full source in the profile which takes a ton of space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants