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(language-service): wait for tsserver to be ready when requesting auto insert .value #3914

Merged
merged 2 commits into from Mar 1, 2024

Conversation

johnsoncodehk
Copy link
Member

The call to provideAutoInsertionEdit is too eager (called 100ms after the document is changed). At this time, the tsserver may not have obtained the latest script changes, and the requested position parameter may be calculated at the wrong position.

Even if an additional version is used to check whether the tsserver script has been synchronized, it does not mean that the type checker is currently available, because the tsserver must wait for the diagnosis to be completed to synchronize the internal state. If the TS API is called in advance in the request handle, it will also cause the tsserver status to be abnormal.

It is currently difficult to find a way to reliably handle tsserver state synchronization, so this PR simply waits 250ms to bypass the problem.

await sleep(250);
if (req !== currentReq)
return;

const enabled = await context.env.getConfiguration?.<boolean>('vue.autoInsert.dotValue') ?? true;
if (!enabled)
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it make sense to check this configuration before the newly added code?

Copy link
Member Author

Choose a reason for hiding this comment

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

getConfiguration has a send request cost before Volar has cached the option, so it is best to place it after sleep.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But now the unnecessary sleep will trigger for every document change, even if one is not using this option. Seems more wasteful than getting a configuration once that gets cached later.

Copy link
Member Author

Choose a reason for hiding this comment

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

sleep is just setTimeout. Is it expensive if clearTimeout is not called in time?

@johnsoncodehk johnsoncodehk merged commit a918fcd into master Mar 1, 2024
6 checks passed
@johnsoncodehk johnsoncodehk deleted the auto-insert-dot-value-time branch March 1, 2024 15:30
so1ve pushed a commit to so1ve/language-tools that referenced this pull request Mar 4, 2024
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