P403n1x87 / austin-vscode

Austin extension for Visual Studio Code
MIT License
21 stars 4 forks source link

tasks.json not accepting variable replacement #35

Closed tjdcs closed 2 years ago

tjdcs commented 2 years ago

Not sure if this is a vs-code issue or an plugin issue, but my Austin task fails in vscode when I try to insert variables like ${workspaceFolder} or ${file} in args.

extension version: v0.10.8 os: macOS 12.6 (M1 Pro) vscode verson: 1.72.2 (Universal)

I have completed the necessary steps to invoke sudo instead of austin directly.

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "austin",
            "label": "Austin: Profile File",
            "command": ["sudo"],
            "args": [
                ".venv/bin/python",
                "${file}" // "someFile.py"
            ],
            "problemMatcher": []
        }
    ]
}

output:

 *  Executing task: Austin: Profile File 

Starting Profiler in /Users/tucker/Dev/colour-specio.
Running 'sudo' with args 'austin -i 100 --pipe  .venv/bin/python ${file}'.
austin process exited with code 32

 *  The terminal process failed to launch (exit code: 32). 
 *  Terminal will be reused by tasks, press any key to close it. 
P403n1x87 commented 2 years ago

@tjdcs Thanks for reporting this. I think that VS Code does not support variable replacement in tasks.json files out of the box and it would have to be implemented at the extension level. This would then be a new feature.

So that I just understand the requirement better, may I ask what are you trying to achieve here? If I understand correctly, this is perhaps an attempt to work around some current limitations of the extensions, especially when it comes to MacOS. Since Austin requires sudo on this platform, the "Profile with Austin" command doesn't work, so a potential solution is a rule in tasks.json, but currently that requires specifying an actual file path. You are then attempting to fix the first limitation with a placeholder for the file in tasks.json. Is this correct?

I can see two possible (non-mutually-exclusive) solutions here:

Would either of these solve your issue?

tjdcs commented 2 years ago

tasks.json does allow for variable substitution and this can be tested. But the first proposal, which appends sudo to the command if MacOS is detected is the most preferable. When do you think this fix will be released / published? Or is there a way to install a preview version (easily)

https://code.visualstudio.com/docs/editor/tasks#:~:text=Note%3A%20Not%20all%20properties%20will%20accept%20variable%20substitution.%20Specifically%2C%20only%20command%2C%20args%2C%20and%20options%20support%20variable%20substitution.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Test Variable Subs",
            "type": "shell",
            "command": "echo",
            "args": [
                "${workspaceFolder}",
                "${file}"
            ],
            "problemMatcher": []
        }
    ]
}
P403n1x87 commented 2 years ago

Ah interesting! It should've worked then. Perhaps the substitutions need to be "triggered" with some API? Your experiments seem to suggest that the extension is getting the raw values.

I expect a new release to be available within a couple of days. I hope that works for you.

P403n1x87 commented 2 years ago

@tjdcs Release 0.11.0 is out with the fix for MacOS.

tjdcs commented 2 years ago

Thanks. Installed. Does not resolve the issue. args needs to be updated when switching the command from austin to sudo

Alternatively, set the command parameter to sudo austin

P403n1x87 commented 2 years ago

@tjdcs may I check with you what error you're getting. The fix seems to work. I have created a simple script

import time

def foo():
    time.sleep(3)

foo()

which I run with shift + F5, and get

 *  Executing task: austin: profile /private/tmp/test.py 

Starting Profiler in undefined.
Running 'sudo' with args 'austin -i 100 --pipe  /Users/gabriele.tornetta/.pyenv/versions/3.9.13/bin/python /private/tmp/test.py'.
Profiling complete.
Screenshot 2022-10-24 at 10 03 14
tjdcs commented 2 years ago

Sorry it was another configuration error in my environment. Just checked again. This is resolved! Thank you for the enhancement / fix!!