Skip to content

debug window is unexpectedly considered a "text editor" #45188

Closed

Description

@DanTup

There are some events and properties related to text editors:

  • window.activeTextEditor
  • window.onDidChangeActiveTextEditor

These sound perfect for something I'm doing - rendering an explorer tree with an outline of the current document. The docs describe the active editor as "The active editor is the one that currently has focus or, when none has focus, the one that has changed input most recently".

However, they fire for things I wouldn't consider "text editors". When I click the debug window the event fires and the activeTextEditor is updated to something with a document that has the URI debug:input.

This makes it difficult to track the last actual document the user interacted with (which is what the description of window.activeTextEditor suggests it does). While we could skip over changes from non-documents it then would be difficult to track when the last document we're tracking was closed (since it could be closed without firing another window.activeTextEditor.

I don't know if this is a bug, but if it's not, I think there shoud be a way to track what the user would consider a text document.

Activity

  1. DanTup commented on Mar 7, 2018

    @DanTup
    ContributorAuthor

    Looks like this has been discussed before:

    #16478

    The suggestion is to use vscode.window.activeTextEditor.viewColumn to decide whether the event is for a real document or not. I think this is a bad fix, as window.activeTextEditor won't give you what you want.

  2. DanTup commented on Mar 7, 2018

    @DanTup
    ContributorAuthor

    The workaround seems flawed. If you click in the debug window and then click File -> Close Editor then you don't get notification of that editor going away.

    As such, #16478 is still somewhat reproducible in TypeScript even after Matt Bierner (@mjbvz)'s fix in
    379da6b.

    1. Open a single typescript file
    2. Observe version number on status bar
    3. Click into debug window
    4. Observe version number still on status bar
    5. File -> Close Editor
    6. TypeScript version is still on status bar, but there is no active TypeScript file

    If this isn't fixed in the API, extension authors are all going have to put nasty hacks in to handle these cases :(

  3. mjbvz commented on Mar 7, 2018

    @mjbvz
    Contributor

    Johannes Rieken (@jrieken) This may be a good case for the proposed generic editor APIs (such as onDidChangeActiveEditor) to handle. Debug console could have its own distinct type

  4. changed the title [-]debug window is unexpected considered a "text editor"[/-] [+]debug window is unexpectedly considered a "text editor"[/+] on Mar 7, 2018
  5. jrieken commented on Mar 8, 2018

    @jrieken
    Contributor

    closing as dupe of #16478 and flagging 'as-designed' because we currently cannot change these things, esp the debug console wants to be an editor for supporting vim and language smarts, e.g. IntelliSense in the debug console.

  6. DanTup commented on Mar 8, 2018

    @DanTup
    ContributorAuthor

    Johannes Rieken (@jrieken) Understood, but there's still a bug that the ts extension can't easily fix. Should I raise a case for the ts extension to add a workaround or is there a future feature that will address this? Although the ts bug is minor (it's just status text) I'm using the same functionality for a contributed tree and having stale content there is far worse, it feels really broken.

  7. jrieken commented on Mar 8, 2018

    @jrieken
    Contributor
  8. DanTup commented on Mar 8, 2018

    @DanTup
    ContributorAuthor

    Matt Bierner (@mjbvz) Feel free to rename this if your intention is to fix in the ts extension, but lmk if you find a reliable fix (ideally that works globally, not just for the one instance I managed to find with a quick test) since I desperately need it too! ;(

  9. mjbvz commented on Mar 8, 2018

    @mjbvz
    Contributor

    Johannes Rieken (@jrieken) I think the point is that we need a new API or an API change. Extensions can't solve this problem without maintaining their own model of the editor UI

    Danny Tuppeny (@DanTup) You'll probably need to look into a workaround on your side as I don't see myself getting around to the TS-specific issue in the near term. The TS problem is very low impact and it self corrects as soon as you go back to an editor

  10. DanTup commented on Mar 8, 2018

    @DanTup
    ContributorAuthor

    Matt Bierner (@mjbvz) Understood, thanks! Our feature is blocked by quite a few issues in Code (listed here) so it might be a while before we can ship this anyway, so I'll leave finding a workaround till later in the hope a better solution comes along.

  11. DanTup commented on Apr 7, 2018

    @DanTup
    ContributorAuthor

    I saw this in the release notes; is it a fix for this issue?

    Simple editors are not passed to extensions

    Inputs that use the editor like the debug REPL input are no longer passed to extensions as editors. This means that both the onDidChangeActiveTextEditor will not trigger when user focuses the debug REPL, and that the onDidChangeTextDocument will also not fire. The reason behind this change is that the REPL input uses the editor as an implementation detail and extension should not be notified of this since it is not a "real editor".

  12. jrieken commented on Apr 9, 2018

    @jrieken
    Contributor

    Yes

  13. DanTup commented on Apr 10, 2018

    @DanTup
    ContributorAuthor

    Excellent, thank you! 👍

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions