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

Avoid overriding the start function of Client #2163

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Jun 11, 2024

Motivation

It turns out that the sendRequest function always calls the start function of the client. So everything we put in the overriding function will be called multiple times just during the initialization of the extension.

While we currently only set the formatter and the server version in the overriding function, which are fine when getting called multiple times, it sets a dangerous precedent. For example, if we put another sendRequest call in it, then it'd create an infinite loop.

Implementation

Add a updateStatesFromInitializationResult function to Client that should be called manually by a Workspace after it called Client#start.

Automated Tests

Manual Tests

@st0012 st0012 added bugfix This PR will fix an existing bug vscode This pull request should be included in the VS Code extension's release notes labels Jun 11, 2024
@st0012 st0012 requested a review from a team as a code owner June 11, 2024 19:17
@st0012 st0012 requested review from andyw8 and vinistock June 11, 2024 19:17
@vinistock
Copy link
Member

I'm not sure this PR is handling the underlying issue. We don't want the client to be started by anything other than the Workspace. Can we instead try to guarantee that the dependency tree is not accidentally trying to start the client?

@st0012
Copy link
Member Author

st0012 commented Jun 12, 2024

Given that other APIs like sendNotification or sendProgress also force starts the client, it seems to be an expected behaviour. If we look at the implementation of client.start, it uses state check to avoid repeated starts anyway.
So I don't think having client.start called outside of workspace is a problem.

Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

If we look at the implementation of client.start

Oh, you found the promise I was trying to find in the code. Perfect, yeah if it's guaranteed to not fire multiple promises, then it should be fine 👍

vscode/src/client.ts Outdated Show resolved Hide resolved
@st0012 st0012 force-pushed the remove-client-start-override branch from 36d17dc to f4b451d Compare June 12, 2024 18:39
@st0012 st0012 enabled auto-merge (squash) June 12, 2024 18:39
It turns out that the sendRequest function always calls the start
function of the client. So everything we put in the overriding function
will be called multiple times just during the initialization of the
extension.

While we currently only set the formatter and the server version in the
overriding function, which are fine when getting called multiple times,
it sets a dangerous precedent. For example, if we put another sendRequest
call in it, then it'd create an infinite loop.

Reference: https://github.com/microsoft/vscode-languageserver-node/blob/1ce790dd341a38da1fbf902cddc16ce456149de0/client/src/common/client.ts#L718
@st0012 st0012 force-pushed the remove-client-start-override branch from f4b451d to 7fdc0fb Compare June 12, 2024 19:05
@st0012 st0012 disabled auto-merge June 12, 2024 20:11
@st0012 st0012 merged commit ff280d7 into main Jun 12, 2024
32 checks passed
@st0012 st0012 deleted the remove-client-start-override branch June 12, 2024 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR will fix an existing bug vscode This pull request should be included in the VS Code extension's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants