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

Make commands wait for applyEdit #2042

Merged
merged 1 commit into from
Jul 27, 2021

Conversation

fvclaus
Copy link
Contributor

@fvclaus fvclaus commented Jul 26, 2021

I stumbled over this trying to find out why organizeImports in combination with Prettier and formatDocument would always alternate its output. My configuration looked like this:

        "editor.codeActionsOnSave": [ 
            "source.organizeImports",
            "source.formatDocument",
        ]

import_order_alternating

The list is executed in order and the commands are awaited for completion. I must organize imports before saving to get rid of unused imports and because I cannot recreate Prettier's import order using vscode-java. (More details here: https://gitter.im/redhat-developer/vscode-java?at=60e84814f1274d5e503bf7d8)
Trying to recreate this issue with a simple extension, I found out that this occurs, when the command returns before all its asynchronous work is done.

After my changes, the behavior changes to the following:
import_order_stable

I applied the changes to all commands that use applyWorkspaceEdit. I used the code for about a week and did not find any (new) problems.

Signed-off-by: clausfr <claus.hays@partner.akdb.de>
Copy link
Collaborator

@testforstephen testforstephen left a comment

Choose a reason for hiding this comment

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

Since I don't know how to use Prettier Java extension in VS Code, I cannot reproduce the conflict issue between organizeImport and prettier.

But regarding this change, i don't see any bad effects of returning a promise in the applyEdit command. So i'd like to merge it.

@testforstephen testforstephen added this to the End July 2021 milestone Jul 27, 2021
@testforstephen testforstephen merged commit b9032f1 into redhat-developer:master Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants