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 OnAutoInsert more reliable and add integration tests #7230

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

dibarbet
Copy link
Member

@dibarbet dibarbet commented Jun 13, 2024

Adds an integration test and fixes a race I discovered while writing the test.

@dibarbet dibarbet requested a review from a team as a code owner June 13, 2024 02:45
// We explicitly register against the server's didChange notification (instead of the VSCode workspace API)
// as we want to ensure that the server has processed the change before we request edits from auto insert.
// The VSCode workspace API will sometimes call this before the LSP client can send the change, leading to auto insert not working.
languageClient.getFeature('textDocument/didChange').onNotificationSent(async (event) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

I discovered this when I was writing the integration tests (and I have had very occasional reports of it not working in the wild).

Essentially, it was possible for our handler of vscode.workspace.onDidChangeTextDocument to make a request to the LSP server before the LSP client handled the change notification and made a didChange request.

This resulted in an autoinsert being requested before the server knew about the text change (verified this ordering in the logs).

I modified this to instead get triggered after the client sends the didChange event to the server, ensuring the server gets that first. I also had to update the implementation as now all the types were LSP types and not vscode types.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also confirmed on the vscode side that languageClient.getFeature('textDocument/didChange').onNotificationSent is the right way to go.

@dibarbet dibarbet requested a review from JoeRobich June 13, 2024 17:35
@dibarbet dibarbet merged commit 5ea997b into dotnet:main Jun 13, 2024
13 checks passed
@dibarbet dibarbet deleted the on_auto_insert_tests branch June 13, 2024 22:35
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.

3 participants