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 handling of non-text editors #842

Merged
merged 4 commits into from Mar 11, 2020
Merged

Conversation

tobous
Copy link
Member

@tobous tobous commented Feb 21, 2020

[FIX][I] #711 Add null checks for logic opening editors

Adjusts the logic opening editors and using the obtained editor objects
to correctly handle null return values.

Adds missing Nullable annotations to the corresponding methods.

Adjusts the corresponding methods javadocs to better reflect the
possible return values in different cases.

Partial fix for #711.

[FIX][I] Only save modified documents

Adjusts the logic to only save documents whose content has been
modified.

Adds the logic to check whether a document or virtual file is seen as
modified to the DocumentAPI.

This was introduced to avoid save operations on resources that can not
be represented by a document (e.g. binary files). Such cases are now
filtered out as such files will always be seen as unmodified by the API,
creating a better handling of such cases.

[FIX][I] Only set up user editor state for moved text files

Adjusts the logic handling the user editor state of moved resources to
only act if the resource is currently open in a text editor.

This change ensures that only the state of text editors is shared with
other Saros instances.

[FIX][I] #711 Ignore non-text editors for editor state

Adjusts the logic sharing the local editor state to ignore the opening
of non-text editors.

Adjusts the logic sharing the local editor state to ignore the closing
of non-text editors.

Moves the closing logic to the before listener to allow us to access the
editor before it is actually closed. This is needed to check the editor
type.

With this change, non-text editors are completely ignored by Saros/I.
This was done to match the Eclipse handling of such non-text editors.

Partial fix for #711.

@tobous tobous added Type: Bug Issue that describes an unintended behavior of Saros Aspect: Consistency Issue with Saros' consistency handling Aspect: User Experience Issue that describes a problem with the usability/user experience of Saros Area: IntelliJ Issue affecting Saros for IntelliJ (Saros/I) State: Fixed Issue has been resolved labels Feb 21, 2020
@tobous tobous added this to the Saros/I Release 0.3.0 milestone Feb 21, 2020
@tobous tobous self-assigned this Feb 21, 2020
@tobous tobous added this to In progress in Saros/I via automation Feb 21, 2020
@tobous
Copy link
Member Author

tobous commented Feb 21, 2020

The user editor state handling is still not consistent. I still have to adjust the handling of file creation, deletion, and move activities.

@tobous tobous force-pushed the pr/intellij/fix_non-text_editor branch from fdea0cd to 01acd18 Compare February 24, 2020 18:13
@tobous
Copy link
Member Author

tobous commented Feb 24, 2020

Updated PR to fix handling of closing non-text editors and moved non-text resources.

@tobous tobous force-pushed the pr/intellij/fix_non-text_editor branch from 01acd18 to 6377d51 Compare February 24, 2020 18:19

if (file == null || !file.exists()) {
LOG.warn("Failed to save document for " + path + " - could not get a valid VirtualFile");
if (document != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better to check if the document is null here and then start to retrieve it ? Currently the save logic is present twice.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is how it was done with the old implementation. I thought that this way was easier to read this way as there are two distinct logical paths through the code. The first part from l.195 to l.202 deals with the case that the document is known to the editor pool and the rest deals with the case that the document has to be requested.

But I can change it again if you prefer. That would then lead to the "has unsaved changes" check being run twice if the document can not be obtained from the editor pool.

This is due to the check in l.212 of whether the file has unsaved changes being used to filter out resources that can't be represented by a document and for which the getDocument(...) call in l.216 would therefore always return null.

Another approach would be to accept such cases and reduce the log level to debug in l.219.

localEditorHandler.activateEditor(project, event.getNewFile());
FileEditor newEditor = event.getNewEditor();

if (newEditor == null || newEditor instanceof TextEditor) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Have not read the API but what is the context when newEditor is null ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Then no editor is selected (i.e. no editor is currently open). This information should also be transferred to other participants. This could lead to a situation where an unnecessary "no editors open" activity is send to the other participants if only non-text editors are open and the last of such editors is closed. But that should not be an issue.

@tobous tobous force-pushed the pr/intellij/fix_non-text_editor branch from 6377d51 to 7a720a4 Compare March 4, 2020 11:21
@saros-infrastructure
Copy link

Codacy Here is an overview of what got changed by this pull request:

Complexity increasing per file
==============================
- intellij/src/saros/intellij/editor/LocalEditorManipulator.java  1
- intellij/src/saros/intellij/editor/EditorManager.java  1
- intellij/src/saros/intellij/eventhandler/editor/editorstate/ViewportAdjustmentExecutor.java  1
- intellij/src/saros/intellij/editor/LocalEditorHandler.java  2
- intellij/src/saros/intellij/eventhandler/editor/editorstate/EditorStatusChangeActivityDispatcher.java  2
         

See the complete overview on Codacy

@tobous
Copy link
Member Author

tobous commented Mar 11, 2020

@srossbach Do you still have any issues with this PR?

srossbach
srossbach previously approved these changes Mar 11, 2020
Saros/I automation moved this from In progress to Reviewer approved Mar 11, 2020
Adjusts the logic opening editors and using the obtained editor objects
to correctly handle null return values.

Adds missing Nullable annotations to the corresponding methods.

Adjusts the corresponding methods javadocs to better reflect the
possible return values in different cases.

Partial fix for #711.
Adjusts the logic to only save documents whose content has been
modified.

Adds the logic to check whether a document or virtual file is seen as
modified to the DocumentAPI.

This was introduced to avoid save operations on resources that can not
be represented by a document (e.g. binary files). Such cases are now
filtered out as such files will always be seen as unmodified by the API,
creating a better handling of such cases.
Adjusts the logic handling the user editor state of moved resources to
only act if the resource is currently open in a text editor.

This change ensures that only the state of text editors is shared with
other Saros instances.
Adjusts the logic sharing the local editor state to ignore the opening
of non-text editors.

Adjusts the logic sharing the local editor state to ignore the closing
of non-text editors.

Moves the closing logic to the before listener to allow us to access the
editor before it is actually closed. This is needed to check the editor
type.

With this change, non-text editors are completely ignored by Saros/I.
This was done to match the Eclipse handling of such non-text editors.

Partial fix for #711.
@tobous tobous force-pushed the pr/intellij/fix_non-text_editor branch from 7a720a4 to c68ef9e Compare March 11, 2020 13:09
Saros/I automation moved this from Reviewer approved to Needs review Mar 11, 2020
@tobous tobous merged commit 1bdaf0a into master Mar 11, 2020
Saros/I automation moved this from Needs review to Done Mar 11, 2020
@tobous tobous deleted the pr/intellij/fix_non-text_editor branch March 11, 2020 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: IntelliJ Issue affecting Saros for IntelliJ (Saros/I) Aspect: Consistency Issue with Saros' consistency handling Aspect: User Experience Issue that describes a problem with the usability/user experience of Saros State: Fixed Issue has been resolved Type: Bug Issue that describes an unintended behavior of Saros
Projects
Development

Successfully merging this pull request may close these issues.

Opening a non-text-editor for shared resources leads to user-visible error
3 participants