bernhard-42 / vscode-ocp-cad-viewer

A viewer for OCP based Code-CAD (CadQuery, build123d) integrated into VS Code
Apache License 2.0
78 stars 9 forks source link

Work in progress: passing viewer port to python via command substitution in launch.json #38

Open Dmytry opened 7 months ago

Dmytry commented 7 months ago

Launch.json used:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "args": ["--port", "${command:ocpCadViewer.port}"],
            "env": {"ocp_port": "${command:ocpCadViewer.port}"},
            "console": "integratedTerminal",
            "justMyCode": false
        }
    ]
}

Seems to work, the command is launched with --port 3939 as expected. May need some checks in case the viewer isn't running yet, and maybe even auto-starting the viewer when ocpCadViewer.port command is called.

Dmytry commented 7 months ago

Tested it some, works via environment variables, got 2 windows each with its own view without a problem. Probably would be good to have a button to auto add a launch configuration with the "env" line from above, but usable as it is now.

bernhard-42 commented 7 months ago

Not sure I understand how --port can then be easily used with ín the client in set_port. I think the environment variable approach is the easier one and would even work without launch.json, isn't it?

Dmytry commented 7 months ago

I think the environment variable still needs launch.json, that's where I set it from, the "env": {"ocp_port": "${command:ocpCadViewer.port}" line.

Not sure if there's any other good way to set it. I think it's usable as it is, the user would have to modify their launch.json . Later I may try to find how to add an option to create launch.json via the menu.