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

Diagnostics and semantic tokens get incorrectly highlighted after doing some specific actions in a line #56677

Closed
blaumeise20 opened this issue Sep 7, 2023 · 2 comments · Fixed by #58538
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@blaumeise20
Copy link
Contributor

blaumeise20 commented Sep 7, 2023

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

  • VS Code Version: 1.81.1
  • OS Version: Windows 11 (10.0.22621)

Steps to Reproduce:

  1. Make a new file and set the language to JavaScript or TypeScript.
  2. Paste this code:
    function bug(
        test // true = test test 123
    ) {}
  3. Put your cursor next to the second slash of the comment.
  4. Press backspace.
  5. Type * twice. (This will automatically extend to /**| */ as JSDoc comments are marked as auto closing pairs)
  6. Move your cursor three characters to the right using the arrow keys (It should be after the closing slash).
  7. Press backspace three times.
    Your code should now look like this:
    function bug(
        test /**| true = test test 123
    ) {}
    Where | is the cursor position.
  8. Now press End (Windows) or Cmd+RightArrow (Mac) to go to the end of the line.
  9. Type */.
  10. Enjoy the bug ;-)

If anyone can't reproduce it, this is the outcome for me:
image

@alexdima
Copy link
Member

alexdima commented Dec 5, 2023

@blaumeise20 Appologies for the slow reaction. Thank you for the very good repro steps!

@mjbvz I can totally reproduce and I see a lot of errors coming in from the ts server:

 ERR <syntax> TypeScript Server Error (5.2.2)
Debug Failure. False expression.
Error: Debug Failure. False expression.
    at Object.updateSourceFile2
...

@alexdima alexdima added Bug A bug in TypeScript and removed Bug A bug in TypeScript labels Dec 5, 2023
@mjbvz mjbvz transferred this issue from microsoft/vscode Dec 5, 2023
@mjbvz mjbvz removed their assignment Dec 5, 2023
@sheetalkamat sheetalkamat self-assigned this Dec 5, 2023
@sheetalkamat
Copy link
Member

sheetalkamat commented Dec 5, 2023

Testcase for the root cause is incremental parser going off the rails:

 it("when comment is completed", () => {
        const source = "function bug(\r\n    test /** */ true = test test 123\r\n) {}";
        const oldText = ts.ScriptSnapshot.fromString(source);
        const index = source.indexOf("/");
        const newTextAndChange = withChange(oldText, index, 1, "");

        compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants