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

False expression: Token end is child end 【I don't know what to call this issue]】 #48139

Closed
Judu233 opened this issue Mar 6, 2022 · 4 comments · Fixed by #48793
Closed
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@Judu233
Copy link

Judu233 commented Mar 6, 2022

Bug Report

 [error] <semantic> TypeScript Server Error (4.6.2)
Debug Failure. False expression: Token end is child end
Error: Debug Failure. False expression: Token end is child end
    at processChildNode (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:144315:38)
    at e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:144255:21
    at visitNode (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:29849:24)
    at Object.forEachChild (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:29972:21)
    at processNode (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:144254:20)
    at formatSpanWorker (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:144055:17)
    at e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:144019:140
    at Object.getFormattingScanner (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:142646:23)
    at Object.formatNodeGivenIndentation (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:144019:31)
    at e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:129984:46
    at Object.flatMap (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:508:25)
    at getEntryForMemberCompletion (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:129982:38)
    at createCompletionEntry (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:129802:23)
    at getCompletionEntriesFromSymbols (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:130166:29)
    at completionInfoFromData (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:129620:17)
    at Object.getCompletionsAtPosition (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:129481:36)
    at Object.getCompletionsAtPosition (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:161847:35)
    at IpcIOSession.Session.getCompletions (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:173395:64)
    at Session.handlers.ts.Map.ts.getEntries._a.<computed> (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:172237:61)
    at e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:174044:88
    at IpcIOSession.Session.executeWithRequestId (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:174035:28)
    at IpcIOSession.Session.executeCommand (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:174044:33)
    at IpcIOSession.Session.onMessage (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:174070:35)
    at process.<anonymous> (e:\vs code\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js:176705:31)
    at process.emit (events.js:315:20)
    at emit (internal/child_process.js:903:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:21): Error: <semantic> TypeScript Server Error (4.6.2)

🔎 Search Terms

N/A since I'm not sure how to describe it.
It suddenly appeared at a certain moment. I don't know how to trigger it. I tried to reinstall vscode, but it didn't work

🕗 Version & Regression Information

vscode version:
image
ts version: 4.6.2

⏯ Playground Link

In playground link, it is normal

💻 Code

class A {
    $a(){

    }

    b(){

    }
}

class B extends A{
   //As long as there is input here, an error will be reported, and there is no type prompt
}

🙁 Actual behavior

sp20220306_144311_603

🙂 Expected behavior

It should prompt the $a method and the b method

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 8, 2022
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.7.1 milestone Mar 8, 2022
@a-tarasyuk
Copy link
Contributor

escapeSnippetText adds \ for all $

write: s => baseWriter.write(escapeSnippetText(s)),
nonEscapingWrite: baseWriter.write,
writeLiteral: s => baseWriter.writeLiteral(escapeSnippetText(s)),
writeStringLiteral: s => baseWriter.writeStringLiteral(escapeSnippetText(s)),
writeSymbol: (s, symbol) => baseWriter.writeSymbol(escapeSnippetText(s), symbol),
writeParameter: s => baseWriter.writeParameter(escapeSnippetText(s)),
writeComment: s => baseWriter.writeComment(escapeSnippetText(s)),
writeProperty: s => baseWriter.writeProperty(escapeSnippetText(s)),

formatting doesn't handle escaping \ because \$a (or \$\$a) is not a valid identifier.

return formatting.formatNodeGivenIndentation(
nodeWithPos,
syntheticFile,
sourceFile.languageVariant,
/* indentation */ 0,
/* delta */ 0,
{ ...formatContext, options: formatOptions });

+1 related #48215 issue

Should TS Server return escaped snippet \$0? Or should only names be escaped \$\$a? I think we can call escapeSnippetText after formatting, just need to be sure that snippets \$0 have to be escaped too.

/cc @andrewbranch

@andrewbranch
Copy link
Member

Oh good find @a-tarasyuk, I think it makes sense to do the escaping after formatting. If we really needed to, we could have the formatter ignore snippet nodes (there’s a property on the attached EmitNode IIRC) but if the simple solution of swapping the order of operations works, that’s great.

@a-tarasyuk
Copy link
Contributor

If we really needed to, we could have the formatter ignore snippet nodes (there’s a property on the attached EmitNode IIRC)

Currently, the insertText response looks like this

"\\$\\$b(): `test\\${string}` {\n    $0\n}"

$0 is not escaped. And this source text breaks formatting. If we apply escapeSnippetText here

return { insertText, isSnippet, importAdder, replacementSpan };

return { insertText: escapeSnippetText(insertText), isSnippet, importAdder, replacementSpan };

the response will be changed to

"\\$\\$b(): `test\\${string}` {\n    \\$0\n}"

Should TS Server return escaped snippet $0? Or should only names be escaped $$a?

Not sure if escaped snippets (\\$0) affect VSCode (or other clients) or not.

@andrewbranch
Copy link
Member

Oh, right. The $0 placeholder needs to reach VS Code unescaped. So maybe the formatter does need to be aware of these snippet nodes.

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.

5 participants