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

onDidChangeActiveTextEditor getting fired with "plaintext" document when opening new file #61825

Closed
mjbvz opened this issue Oct 25, 2018 · 4 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority verified Verification succeeded
Milestone

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Oct 25, 2018

Steps to Reproduce:

  1. In a repo with 3 markdown files.
  2. Make sure all files are closed and then restart vscode
  3. Open the first markdown file and open the preview to the side
  4. With the markdown editor focused, click on one of the other markdown files in the explorer

Bug
Markdown preview does not update to show the preview of the new document.

The root cause is that onDidChangeActiveTextEditor is fired with a editor.document.languageId that is set to plaintext instead of markdown

Does this issue occur when all extensions are disabled?: Yes

@mjbvz mjbvz added the bug Issue identified by VS Code Team member as probable bug label Oct 25, 2018
@mjbvz mjbvz added this to the October 2018 milestone Oct 25, 2018
@mjbvz
Copy link
Contributor Author

mjbvz commented Oct 25, 2018

Could be a promise conversion timing issue. Not sure who the right owner is here but I did some initial investigation. Here's what I believe is going wrong:

  1. Starting in ModelServiceImpl.createModel
  2. This method calls setMode which invokes .then on the mode promise. This block is not evaluated yet.
  3. We next continue on with createModel which calls into MainThreadDocumentsAndEditors. This code sends the document delta to the extesion host with the incorrect plaintext document mode.
  4. At some later point, the .then block from setMode is then evaluated and we update the document to have the correct markdown mode

I suspect the .then in setMode used to by resolved synchronously

@rebornix
Copy link
Member

This is not good. Every time when a file is opened, we will warm up the tokens first before displaying, which is a sync task. So what happens now is

  • Tokenize up to 50ms with plaintext
  • Language update kicks in
  • All tokens are thrown away

@bpasero
Copy link
Member

bpasero commented Oct 26, 2018

Yeah could be likely a Promise/TPromise conversion regression.

@alexdima
Copy link
Member

Definitely caused by the asynchronous then, thank you for the analysis @mjbvz. Since I converted the IModeService to use native promises, I will look into addressing the issue.

@alexdima alexdima added the important Issue identified as high-priority label Oct 26, 2018
@mjbvz mjbvz added the verified Verification succeeded label Nov 1, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants