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

getTokenInformationAtPosition API causes too much traffic and blocks the renderer process #99356

Open
alexdima opened this issue Jun 4, 2020 · 23 comments
Assignees
Labels
api bug Issue identified by VS Code Team member as probable bug tokenization Text tokenization under-discussion Issue is under discussion for relevance, priority, approach
Milestone

Comments

@alexdima
Copy link
Member

alexdima commented Jun 4, 2020

  • Install GitHub Pull Request Nightly BuildPreview
  • Open the following file:
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
// #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555 #91555
function hello() {
    //
}
function hello2() {
}
function hello3() {
}

Try to work in the file and observe how the window is not really responsive.
Add a console log statement here --

async $tokensAtPosition(resource: UriComponents, position: IPosition): Promise<undefined | { type: StandardTokenType, range: IRange }> {

Observe how after each keystroke there are thousands of requests going from the extension host to the renderer process.

Kapture 2020-06-04 at 12 43 07

@jrieken
Copy link
Member

jrieken commented Jun 4, 2020

Using the file above with 2261 links, saved as abc.ts, I see the following durations:

These are totals of 2261 individual calls to $tokensAtPosition so I'd say it isn't blocking but also not ideal. I am guessing that you'll see a freeze when console-logging every call.

Things that we can do in May

  • remove the API or not use the API from the link provider (easy)
  • limit issue link detection to the first N occurrences (easy)
  • debounce and batch requests and reduce total number of roundtrips (not easy, not hard)

@jrieken jrieken added this to the May 2020 milestone Jun 4, 2020
@jrieken jrieken added api tokenization Text tokenization under-discussion Issue is under discussion for relevance, priority, approach labels Jun 4, 2020
@alexr00
Copy link
Member

alexr00 commented Jun 4, 2020

I like the "limit issue link detection to the first N occurrences", where N is 20. It seems unlikely that folks will have more than 20 issue references in a file, and they can still get to a link via the hover if they want.

@alexdima
Copy link
Member Author

alexdima commented Jun 4, 2020

  1. The link computing code suffers from the problem I foresaw here, which is one of the reasons I find this approach not good. It invites extension authors to make this mistake. Even with that problem clearly highlighted just a few days before the code was written, the mistake was made here in this link computer. The state after the await is not checked against the state before the await. The contract of language providers (including link providers) is that a link provider should return the links of the document at the version when the request was made.
  2. IMHO having a solution where a keystroke results in 20 renderer requests is still not good. To make matters worse, I have noticed that the awaits are done in series and not in parallel, so for the web ui, assuming a latency of 30ms, the link computer will return in 600ms because it will wait 20 times for each round-trip.
  3. This approach to fix false positives in link detection still has trouble with commented out CSS. One suggestion that I made earlier was to get the issue count from a repository and eliminate large numbers, e.g.:
    image

@jrieken
Copy link
Member

jrieken commented Jun 4, 2020

@alexr00 The API itself will check the version before and after the roundtrip, so all it should take is collecting all requests and firing them at once.

@dbaeumer dbaeumer modified the milestones: May 2020, June 2020 Jun 5, 2020
alexr00 added a commit to microsoft/vscode-pull-request-github that referenced this issue Jun 5, 2020
@jrieken jrieken removed this from the June 2020 milestone Jun 15, 2020
@alexr00 alexr00 added the feature-request Request for new features or functionality label Nov 9, 2020
@alexdima
Copy link
Member Author

alexdima commented Dec 3, 2020

Sorry @alexr00 I don't believe this is a feature request? Can you please reassess the issue type?

@alexr00 alexr00 added bug Issue identified by VS Code Team member as probable bug and removed feature-request Request for new features or functionality labels Dec 4, 2020
@alexr00 alexr00 removed this from the Backlog Candidates milestone Dec 4, 2020
@alexr00
Copy link
Member

alexr00 commented Dec 4, 2020

Sorry about that. I have no recollection of making this a feature-request.

@jrieken
Copy link
Member

jrieken commented Oct 22, 2021

@alexr00 I am planning on removing this proposal and we need to find an alternative for your use-case. Assuming it is still needed. Most extensions that need token information load vscode-textmate but your case might be simpler and you can do some pragmatic detection of comments (which I believe is needed here) which us expose the language configurations

@jrieken jrieken added this to the October 2021 milestone Oct 22, 2021
@alexr00
Copy link
Member

alexr00 commented Oct 26, 2021

Thanks for the heads up. The code is still in GitHub Pull Requests and Issues, but it isn't called. I will remove it.

Actually, this is very much still used. Will there be a new mechanism for this before the removal?

@alexr00
Copy link
Member

alexr00 commented Oct 26, 2021

GHPRI uses this API to make sure we don't show completion suggestions for issue numbers and users outside of comments, which is essential for the issue and user completion feature. It becomes too noisy when completions are offered outside of comments.

@jrieken
Copy link
Member

jrieken commented Oct 26, 2021

Will there be a new mechanism for this before the removal?

Sorry, but you will have to invent your own mechanism, like re-use vscode-textmate or do some pragmatic detection of comments

@jrieken jrieken modified the milestones: October 2021, November 2021 Oct 26, 2021
@alexr00
Copy link
Member

alexr00 commented Nov 1, 2021

@jrieken I should be able to add a reasonable guess about whether there is a comment using the language configuration as you suggested. Would you consider API to expose the language configuration?

@jrieken
Copy link
Member

jrieken commented Nov 1, 2021

There was #109919 for getting the language configuration. It seems that faded away, maybe @alexdima wants to reconsider.

@alexdima
Copy link
Member Author

alexdima commented Nov 2, 2021

Sure, we can add getLanguageConfiguration() to the API. But it probably would need to be async and use the ILanguageConfigurationService on the UI side. PR welcome!

@jrieken
Copy link
Member

jrieken commented Nov 2, 2021

But it probably would need to be async and use the ILanguageConfigurationService on the UI side

idk - but given the past discussions I would say that it should by sync, e.g be pushing new language configurations by the ILanguageConfigurationService#onDidChange-event. This would than be similar to how vscode.languages.getLanguages 1 is implemented.

1 The API for getLanguages is actually bogus because it is declared async but implemented sync, e.g without renderer-roundtrips.

@alexdima
Copy link
Member Author

alexdima commented Nov 3, 2021

We load language configuration files on demand, when tokenization encounters a language or when a file with the language is opened. The problem with a sync implementation for getLanguageConfiguration is that we'd need to:

  1. read all language configuration files and send their contents to the extension host before activating extensions. (I don't want to do this, as it would cause a perf hit on startup, we ship around 80 languages so we'd need to read 80 files on startup).
  2. (or) use sync fs to read the language configuration from the extension host if a call comes in for a language for which the configuration was not yet loaded by the renderer process (cannot be done because the extension could be on a different filesystem and sync fs would not work, e.g. when the language configuration contributing extension is installed locally and the API calling extension is running remotely).

@jrieken
Copy link
Member

jrieken commented Nov 4, 2021

Cann't we do it incrementally and send an update/event whenever new language config is encountered? We do something similar with word definitions here

@alexdima
Copy link
Member Author

alexdima commented Nov 4, 2021

👍 Yes, word definitions are pushed as they are encountered, but the word definitions are only used internally when calling a specific method TextDocument.getWordRangeAtPosition. Once a language is opened the first time via a text document, the word definition will follow quickly after the text document instantiation. I agree that there is a race condition where the text document is created and sent to the extension host before the word definition is sent.

But we don't have a method getWordDefinition(languageId) with an arbitrary languageId. My concern with adding API that will be flawed even when used correctly. I can see the bug coming where people want to simply read the language configuration up-front, e.g. in their activate method they will call getLanguageConfiguration('typescript') to start another process, etc. I have concerns that a sync API might be broken by default, while an async API can be made correct.

@jrieken
Copy link
Member

jrieken commented Nov 4, 2021

My concern with adding API that will be flawed even when used correctly. I can see the bug coming where people want to simply read the language configuration up-front

I was thinking of some kind of vscode.languages.onDidChangeConfiguration-event that consumers need to track. We do have the corresponding event on the service/registry which tells me that language config is changing. If that's true and happening extension authors might workaround the missing event by calling (async) getLanguageConfiguration(<langId>) in tight loops etc

@ghost
Copy link

ghost commented Nov 11, 2021

re-use vscode-textmate

I have been trying to do exactly that but I can't compile native node modules in vscode-test.

@jrieken jrieken modified the milestones: November 2021, December 2021 Nov 29, 2021
@jrieken jrieken modified the milestones: January 2022, February 2022 Jan 20, 2022
@jrieken jrieken removed this from the February 2022 milestone Feb 2, 2022
@alexr00 alexr00 added this to the Backlog milestone Dec 7, 2022
@zm-cttae
Copy link

zm-cttae commented May 7, 2023

I have done a huge amount of legwork on this in the past few months. I have a PR coming that will make this API method both fast, useful, platform-independent and performant

A key benefit is that documents can be tokenized from the grammar contributed by a registered extension. We are obtaining the precise results that VS Code end users see in the UI.

Subscribe to vsce-toolroom/vscode-textmate-languageservice#22 to follow my progress :)

PS: Main delay is that I always automate passing tests before release.

@zm-cttae
Copy link

zm-cttae commented May 7, 2023

re-use vscode-textmate

I have been trying to do exactly that but I can't compile native node modules in vscode-test.

Webpack solved the issue - and allowed for a browser friendly release that ships deps too 🤾🏾‍♂️💯

@zm-cttae
Copy link

zm-cttae commented Sep 8, 2023

This has been implemented with tests and will ship in a 2.0.0 release either today or tomorrow.

@zm-cttae
Copy link

zm-cttae commented Sep 8, 2023

https://github.com/vsce-toolroom/vscode-textmate-languageservice/releases/tag/v2.0.0

  • Add getTokenInformationAtPosition method for fast positional token polyfill: vscode.TokenInformation.
  • Add getScopeInformationAtPosition method to get Textmate token data: TextmateToken.
  • Add getScopeRangeAtPosition method to get token range: vscode.Range.
  • Add getLanguageConfiguration, getGrammarConfiguration & getContributorExtension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api bug Issue identified by VS Code Team member as probable bug tokenization Text tokenization under-discussion Issue is under discussion for relevance, priority, approach
Projects
None yet
Development

No branches or pull requests

6 participants
@jrieken @dbaeumer @alexdima @alexr00 @zm-cttae and others