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

fix: flawed timing issue when opening editors #1649

Merged
merged 2 commits into from
Nov 11, 2022
Merged

fix: flawed timing issue when opening editors #1649

merged 2 commits into from
Nov 11, 2022

Conversation

kittaakos
Copy link
Contributor

@kittaakos kittaakos commented Nov 7, 2022

Motivation

This PR is to fix the flawed timing issue when opening editors.

Change description

Other information

For the testing, please use the 1612-sketches.zip archive. (However, you're allowed to use your own setup.)

1612-sketches.zip:

.
├── invalid-sketches
│   ├── Bar
│   │   └── xxx.ino
│   └── foo
│       └── Foo.ino
└── valid-sketches
    └── Errors1234567
        ├── CTab.c
        ├── CppTab.cpp
        ├── Errors1234567.ino
        ├── HTab.h
        ├── InoTab.ino
        └── src
            └── HFile.h

6 directories, 8 files

Expected behavior:

  • The fallback sketch editor is already opened in IDE2 when the modal dialog prompts the move (this is important to preserve the 1.x behavior in IDE2)
  • The error message is toasted when the IDE2 prompts with the modal dialog.

If one of these 👆 is not working due to a slower or different env OS, please let me know, and I will adjust the timings.

Closes #1612

Reviewer checklist

  • PR addresses a single concern.
  • The PR has no duplicates (please search among the Pull Requests before creating one)
  • PR title and description are properly filled.
  • Docs have been added / updated (for bug fixes / features)

@kittaakos kittaakos added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Nov 7, 2022
@kittaakos kittaakos marked this pull request as ready for review November 8, 2022 13:10
@kittaakos kittaakos force-pushed the #1612 branch 3 times, most recently from 210513c to bc78f4e Compare November 10, 2022 10:35
const deferred = new Deferred<EditorWidget>();
const deferred = new Deferred<EditorWidget>();
if (!widget) {
// If the editor or is not defined, assume one on create event
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment. @kittaakos could you please elaborate on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for asking!

We should improve it. I am open to any proposals. Your recent recommendations for clarifying code comments were on the spot 👍

When ensureOpened is called, the editor can be in two different primary states:

  • It's not opened. The editor widget and the backing monaco editor instance do not exist, and the editor widget is not yet registered to the editorManager. The widget is undefined.
  • It's opened
    • the editor widget is the top editor. The editor has the focus (the cursor blinks in it); it's the activeEditor.
    • the editor widget is the top editor, but the focus is on a different widget, or the context menu is active in the editor; it's the currentEditor.
    • the editor widget is not on top. The tab with the filename is visible.

When the widget is undefined, the framework will instantiate it when calling editorManager.open. After the editor widget creation, editorManager.onCreated gets an event. IDE2 must handle this case differently, listen to this event, and ensure that the editor is attached to the shell and visible on the screen. Then resolve the promise.

If the widget is already defined, it's opened; hence, there is no need to wait for any visibility state changes. This case does not need to wait for any events.

Please help to improve the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the comments. Please re-check them. Thank you!

new URI(uri),
options ?? {
mode: 'reveal',
preview: false,
counter: 0,
}
)
.then((editorWidget) => {
// if the widget was already opened we assume it was already already visible and attached to the DOM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if the widget was already opened we assume it was already already visible and attached to the DOM
// if the widget was already opened we assume it was already visible and attached to the DOM

Copy link
Contributor

@AlbyIanna AlbyIanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything works as described and I couldn't find any regression with #1563.

Code is also good for me.

Akos Kitta added 2 commits November 10, 2022 16:45
From now on, the editor widget open promise resolution does not rely on
internal Theia events but solely on @phosphor's `isAttached`/`isVisible`
properties.
The editor widget promise resolves with the next task after a navigation
frame so the browser can render the widget.

Closes #1612

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
Do not try to parse the original `NotFound` error message, but look for
a sketch somewhere in the requested path.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified this fixes the problem of the exceptionally long first load time for multi-file sketches reported at #1612.

I also checked for regressions in handling of opening sketches with invalid format on both Windows and Linux.

Thanks Akos!

@kittaakos kittaakos merged commit d24a391 into main Nov 11, 2022
@kittaakos kittaakos deleted the #1612 branch November 11, 2022 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

First time load of project with many files very slow with "the editor has not shown up in time" errors
3 participants