Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

How to set $DISPLAY for debug configurations started with "console": "internalConsole" #41

Open
bersbersbers opened this issue Jan 19, 2021 · 3 comments

Comments

@bersbersbers
Copy link

bersbersbers commented Jan 19, 2021

I am using Python, and the following launch configs demonstrate my problem:

    "launch": {
        "configurations": [
            {
                "name": "P1",
                "type": "python",
                "request": "launch",
                "program": "${file}",
            },
            {
                "name": "P2",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "console": "internalConsole",
            },
        ],
    },

The code:

"""Test pyplot via X11."""
import os

print("DISPLAY =", os.getenv("DISPLAY"))

With P1, I get

DISPLAY = localhost:10.0

With P2, however, I get

DISPLAY = None

I could add an "env" entry to the debug configuration having "console": "internalConsole", but how to get the correct value?

Adding

                "env": {
                    "DISPLAY": "${env:DISPLAY}",
                }

to P2 does not work as it's empty.

@bersbersbers
Copy link
Author

bersbersbers commented Jan 21, 2021

I assume this is a bug in either vscode or vscode-python, but as it's pretty specific to DISPLAY in my case (the two envs are identical up to some 10 environment variables all related to terminal- and X11-related things), checking Remote X11 is where I started. So I was looking to see if I can find out in which way DISPLAY is set. I did not find it in the code, however. Would you mind pointing me at that part where you set it? Oh, I just now found it - no idea how I could miss the RemoteHandler before:

private updateDisplay(display: string) {
getLogger().log(`DISPLAY = ${display}`);
this.context.environmentVariableCollection.replace('DISPLAY', display);
}

@joelspadin
Copy link
Owner

Yeah. I'm using an extension API to add environment variables there. I think it only adds them to the integrated terminal though, not to VS Code's own environment.

If you're comfortable with building the extension yourself, what happens if you also add this to that function?

process.env['DISPLAY'] = display;

That should add it to VS Code's environment too, which will hopefully make ${env:DISPLAY} work.

@bersbersbers
Copy link
Author

bersbersbers commented Jan 21, 2021

Yeah. I'm using an extension API to add environment variables there. I think it only adds them to the integrated terminal though, not to VS Code's own environment.

That seems to be the case, even if they don't say it explicitly:

Gets the extension's environment variable collection for this workspace, enabling changes to be applied to terminal environment variables.

https://code.visualstudio.com/api/references/vscode-api#ExtensionContext

If you're comfortable with building the extension yourself, what happens if you also add this to that function?

process.env['DISPLAY'] = display;

That should add it to VS Code's environment too, which will hopefully make ${env:DISPLAY} work.

This seems like a good workaround. I did not build myself, but I used https://github.com/GoNZooo/vscode-environment-injector to inject DISPLAY using that method*, and ${env:DISPLAY} worked! So it seems you might add the variable in both places and I adapt my launch configs to pass on that variable.

I might still file this issue with vscode - considering environmentVariableCollection may be useful in internalconsole even though it's not strictly a terminal. (I verified that the problem also appears with Java, so it's not specific to VS Code Python. )

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants