Skip to content

active editor not always correct... #49125

Closed

Description

From time to time the integration tests fail and that's because the active editor isn't the editor that just got opened. That actually a problem not a flawed test... Below a trace I could extract with the following extension snippet

  • apply this patch to add logging patch.txt
  • have the extension snippet below, bind the command to a keybindg
  • execute the command and notice that it breaks after one iteration
      vscode.window.onDidChangeActiveTextEditor(e => {
        console.log('ACTIVE editor -> ' + (e ? e.document.fileName : '<none>'));
    })


    vscode.commands.registerCommand('extension.sayHello', async () => {
        console.log('START')

        const [docA, docB] = await Promise.all([
            vscode.workspace.openTextDocument('/Users/jrieken/Code/_samples/virtual/out/extension.js'),
            vscode.workspace.openTextDocument('/Users/jrieken/Code/_samples/virtual/out/extension.js.map')
        ]);

        let c = 3;
        while (c > 0) {
            console.log('NEW ROUND');
            console.log('want', docA.fileName, c);
            let editorA = await vscode.window.showTextDocument(docA, vscode.ViewColumn.One);
            if (vscode.window.activeTextEditor !== editorA) {
                console.log('editorA BAD', editorA.document.fileName, c);
                break;
            }
            console.log('want', docB.fileName, c);
            let editorB = await vscode.window.showTextDocument(docB, vscode.ViewColumn.Two);
            if (vscode.window.activeTextEditor !== editorB) {
                console.log('editorB BAD', editorB.document.fileName, c);
                break;
            }
            c -= 1;
        }
    });
[Extension Host] NEW ROUND (at /Users/jrieken/Code/_samples/virtual/out/extension.js:49:21)
console.js:100 [Extension Host] want /Users/jrieken/Code/_samples/virtual/out/extension.js 2 (at /Users/jrieken/Code/_samples/virtual/out/extension.js:50:21)
console.js:100 [Extension Host] editorA BAD /Users/jrieken/Code/_samples/virtual/out/extension.js 2 (at /Users/jrieken/Code/_samples/virtual/out/extension.js:53:25)
mainThreadDocumentsAndEditors.js:168     at MainThreadDocumentAndEditorStateComputer._updateState (file:///Users/jrieken/Code/vscode/out/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.js:168:25)
    at file:///Users/jrieken/Code/vscode/out/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.js:142:113
    at Emitter.fire (file:///Users/jrieken/Code/vscode/out/vs/base/common/event.js:103:38)
console.js:100 [Extension Host] ACTIVE editor -> /Users/jrieken/Code/_samples/virtual/out/extension.js (at vscode.window.onDidChangeActiveTextEditor.e (/Users/jrieken/Code/_samples/virtual/out/extension.js:39:17))

Activity

  1. added
    bug
    on May 3, 2018
  2. jrieken commented on May 4, 2018

    @jrieken
    ContributorAuthor

    Removing tests should be reverted once this is fixed: efb4358

  3. jrieken commented on May 4, 2018

    @jrieken
    ContributorAuthor

    Benjamin Pasero (@bpasero) alexandrudima Not sure how this should work. I see that focus isn't called from the workbench when opening a document that is already open. Still, while the editor takes focus there is no event emitted.

  4. bpasero commented on May 7, 2018

    @bpasero
    Contributor

    There is something fishy going on, I also sometimes see 2 blinking cursors in the editor area when running the sample. I extracted #49330 to look into this and see if the workbench is doing something weird.

  5. aeschli commented on Jun 1, 2018

    @aeschli
    Contributor

    verified by running the code above without seeing any BAD

  6. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

apibugverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions