Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task's new integrated terminals are always revealed when Python extension is active with python.terminal.activateEnvironment set to true #17508

Closed
Tschebbischeff opened this issue Sep 21, 2021 · 8 comments
Assignees
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug good first issue verified Verification succeeded

Comments

@Tschebbischeff
Copy link

Please search existing issues to avoid creating duplicates.

I found these interlinking issues on the topic:
#3852 (links to vscode/66056, which is duplicate of vscode/65179)
microsoft/vscode#65179 (references this to be an issue with vscode-python specifically => #3852)
microsoft/vscode#66056 (duplicate of vscode/65179)
However #3852 was closed and locked, without the actual problem being addressed properly in my opinion.

While the latest answer in #3852 from @DonJayamanne does seem to get rid of the issue, I fail to see how the python.terminal.activateEnvironment setting SHOULD be connected to it.

I am presuming the activation of the virtual environment reveals the terminal, however the two features seem like they should not be connected / should not interact.
Having a task run within the configured virtual environment AND not showing/revealing its terminal when running it is a completely viable use-case in my opinion, but maybe I fail to see a connection?

Note that all of this only applies if a new integrated terminal is opened for the task's output, not when a "shared" panel is ready to be re-used or if the task is using a "dedicated" panel that is still open from the last run of the task.

Hence the real issue here as far as I can tell would be why the activation of the virtual environment is bringing the task's integrated terminal "to the front" (reveal).

Environment data

  • VS Code version: 1.60.1
  • Extension version (available under the Extensions sidebar): v2021.9.1230869389
  • OS and version: Ubuntu 18.04.6 LTS, Kernel version: 4.15.0-156-generic
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.12
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv & virtualenvwrapper
  • Value of the python.languageServer setting: "Pylance"

Expected behaviour

Even with "python.terminal.activateEnvironment" set to true and the "presentation.reveal" property of a task set to "never" I expect the terminal with the task output not to come into focus when running the task.

Actual behaviour

With "python.terminal.activateEnvironment" set to true, tasks with their "presentation.reveal" property set to "never" come into focus when the virtual environment is activated.

Steps to reproduce:

  1. Activate the Python extension.

  2. Create a task, e.g. (presentation.panel has been chosen as "new" because the issue only happens, when a new integrated terminal is opened for the task)

     {
     "label": "Simple Test",
     "type": "shell",
     "command": "echo \"foo\"",
     "presentation": {
     	"reveal": "never",
     	"panel": "new"
     }
    

    }

  3. Run the task

  4. Observe how the terminal with the task's output is revealed even though its presentation.reveal property is set to "never"

Logs

No output is shown in the Output panel, output of the task is shown in an integrated terminal instead (Correct behavior).
No log messages are triggered by this in the developer console.

@karthiknadig
Copy link
Member

In the python extension we use sendText API to send the activation command to the terminal. I am suspecting some thing changes the state of presentation.reveal inside sendText. Other than that I don't see anything that extension does to change this. Transferring to VS Code for further investigation.

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Sep 21, 2021
@alexr00
Copy link
Member

alexr00 commented Sep 23, 2021

@karthiknadig can you provide a self contained repro where sendText causes a task with reveal: false to show? I tried to make my own repro of this, but I wasn't able to get it to reproduce. My steps:

  1. Added this task, where powershell.ps1 just prints some stuff and sleeps for a few seconds.
        {
            "label": "echo task",
            "type": "shell",
            "command": ".\\powershell.ps1",
            "presentation": {
                "reveal": "never"
            }
        }
  1. Add an extension with this command:
	const disposable = vscode.commands.registerCommand('extension.helloWorld', () => {
		vscode.window.terminals.forEach(terminal => {
			console.log('sending text');
			terminal.sendText('echo hello');
		});
	});
  1. Run the task and then run the command while the task is still running.

@karthiknadig
Copy link
Member

While trying to create the repro, I might have discovered the problem in the extension. Looks like in some cases we call terminal.show. @alexr00 that overrides "reveal": "never" correct?

@alexr00
Copy link
Member

alexr00 commented Sep 23, 2021

@karthiknadig correct, if you show the terminal that will always cause the terminal to show.

@karthiknadig karthiknadig transferred this issue from microsoft/vscode Sep 23, 2021
@karthiknadig karthiknadig assigned karthiknadig and unassigned alexr00 Sep 23, 2021
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 23, 2021
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug area-terminal needs PR and removed triage-needed Needs assignment to the proper sub-team labels Sep 23, 2021
@karthiknadig karthiknadig removed their assignment Sep 23, 2021
@karthiknadig
Copy link
Member

We have two activation paths, this one seems to be the culprit here:

terminal.show(options?.preserveFocus);

@luabud Is there any reason we need to show the terminal on activation? I am guessing not and this is just a remnant from how we had it from a long time ago.

@karthiknadig
Copy link
Member

@alexr00 Sorry for the trouble. I some how missed that line when looking into this issue.

@luabud
Copy link
Member

luabud commented Oct 4, 2021

@karthiknadig I don't think we need to display the terminal on activation. As long as we active the terminal when users first open it, the setting serves its purpose.

@github-actions github-actions bot removed the needs PR label Aug 9, 2022
@karrtikr karrtikr added the needs PR Ready to be worked on label Aug 9, 2022
@karrtikr
Copy link

We have a new activation mechanism #11039 which does not require executing any commands so should not have this problem, give it a try:

  • Use latest version of VS Code and Python extension
  • Add the following to User settings and reload window:
    "python.experiments.optInto": ["pythonTerminalEnvVarActivation"]

@github-actions github-actions bot removed the needs PR Ready to be worked on label Sep 12, 2023
@karrtikr karrtikr added this to the September 2023 milestone Sep 12, 2023
@karrtikr karrtikr self-assigned this Sep 12, 2023
@karrtikr karrtikr added the verified Verification succeeded label Sep 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug good first issue verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants