sransara / speedscope-in-vscode

VSCode extension for viewing Speedscope flamegraphs
https://marketplace.visualstudio.com/items?itemName=sransara.speedscope-in-vscode
MIT License
13 stars 0 forks source link

Please provide a way to specify the file to open #1

Closed Altyrost closed 3 months ago

Altyrost commented 3 months ago

Please provide a way to open a "fixed" file in speedscope, instead of having to right-click -> open with.

For example, in settings.json:

{
  "speedscope-in-vscode.file": "${workspaceFolder}/build/profiling/speedscope.txt"
}

and a new command: speedscope-in-vscode.openFile

sransara commented 3 months ago

There's a speedscope-in-vscode.openSpeedscope command already available: https://github.com/sransara/speedscope-in-vscode/blob/031267e5b36c03a4ab5b58b5eb63246d13e0e5e2/src/commands.ts#L11 and it already accepts a file URI argument.

Can you combine that with an extension like multi-command to create a custom command that opens your specific file? Or if you just want to bind to a key, that should be possible without an extension.

I'm hesitating your specific request because it seems rather niche to support that specific behavior.

Altyrost commented 3 months ago

I haven't been able to pass an URI to the said command.

        {
            "label": "Open with Speedscope",
            "command": "${command:speedscope-in-vscode.openSpeedscope}",
            "args": [
                "/path/to/speedscope.txt"
            ]
        }

Returns:

Invalid argument 'resource' when running 'vscode.openWith', received: [
    "${command:speedscope-in-vscode.openSpeedscope}",
    "/path/to/workspaceFolder"
] 

If I could do that I wouldn't need anything else indeed.

sransara commented 3 months ago

Just published a new version with potential fix. Can you try with the new 0.1.2 version?

sransara commented 3 months ago

Tried myself, still getting your error. I'll investigate further.

sransara commented 3 months ago

VSCode is just being silly. We need to pass a single argument like this (not as an array):

  {
    "key": "ctrl+shift+alt+s",
    "command": "speedscope-in-vscode.openSpeedscope",
    "args": "/some/path/profiles/haskell/404.prof"
  }

Please let me know if that works.

Altyrost commented 3 months ago

It does work with the keybinding.json, but not with the tasks.json.

Altyrost commented 3 months ago

After doing a bit of debugging, it appears that it's just not possible to directly pass an argument to a vscode command through a task. Here's a work around:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Open In Speedscope",
      "command": "echo ${input:ActuallyOpenInSpeedscope} > /dev/null 2>&1",
      "problemMatcher": []
    }
  ],
  "inputs": [
    {

      "id": "ActuallyOpenInSpeedscope",
      "type": "command",
      "command": "speedscope-in-vscode.openSpeedscope",
      "args": "/path/to/sample.json"
    }
  ]
}

There's a big limitation still: the path needs to be absolute. Relative path or paths with variables doesn't seems to work (aka ${workspaceFolder}/sample.json). This means any extra tooling I'll create can't be generic.

Creating a settings seems like a good way to make all those problems go away.

sransara commented 3 months ago

Thank you for debugging.

I was also checking and see that task.json lets us call commands but no support for calling commands with arguments.

Even with a settings.json, variables like ${workspaceFolder} aren't supported: https://github.com/microsoft/vscode/issues/2809

Relative paths not working is a bug in the extension. (The possibility of multi-root work-spaces complicates relative paths). Let me fix that.

sransara commented 3 months ago

Created a PR to support relative paths: https://github.com/sransara/speedscope-in-vscode/pull/4

Hopefully that gives enough for you to work with. I tested with something like the following from your above example:

{

      "id": "ActuallyOpenInSpeedscope",
      "type": "command",
      "command": "speedscope-in-vscode.openSpeedscope",
      "args": "./haskell/simple.prof"
    }

I'm still not convinced to create a special setting to open a file.

Altyrost commented 3 months ago

Relative path now works. The "file not found" message also works.

I should now be able to better integrate speedscope-in-vscode in my process.

Thank you for your time.

sransara commented 3 months ago

Glad to hear that.