microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.63k stars 28.67k forks source link

Expected `preserveFocus: false` to move focus to Test View, instead it toggles visibility of Test Results View #213759

Open chrisdias opened 3 months ago

chrisdias commented 3 months ago

Testing #213601

Caveat: Not sure if I fully understand what I'm doing here.

My expectation by setting preserveFocus to false was that focus would move to the Test View (initially) and I could start to navigate around there using the keyboard. Instead, when preserveFocus seems to only control toggling whether or not the Test Results View is shown automatically. Focus remains wherever the run was started (e.g., I invoked the command either through the command palette or a key binding from an editor, focus remained in the editor regardless of the setting).

Per instructions in the TPI, I added a new command in package.json.

{
   "command": "selfhost-test-provider.test213601",
   "title": "Test 213601",
   "category": "Testing",
   "icon": "$(merge)"
}

I updated how the 'Run in Electron' profile was created so that I could reference it:

const rie = ctrl.createRunProfile(

Then, I added a command handler to the activate function in extension.ts:

vscode.commands.registerCommand('selfhost-test-provider.test213601', async () => {
    console.log("testing 213601: true")

    const req = new vscode.TestRunRequest(
        undefined,
        undefined,
        rie,  
        false,
        /* preserveFocus= */ true
    );

    ctrl.createTestRun(req).end();
});

When running the extension and invoking the command through the command palette, toggling preserveFocus to true and false simply controlled whether or not the Test Results View was automatically opened. I did not observe any change in focus.

Thinking I may be inadvertently messing with focus by invoking the command palette, I bound the command to a key which resulted in exactly the same behavior.

If the goal of the new param is to automatically show the Test Results View, perhaps it should be named something more like showTestResults.

aiday-mar commented 3 months ago

I had the same thought