-
Notifications
You must be signed in to change notification settings - Fork 719
Fix Chinese character display by matching TypeScript's printer selection logic #1559
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
Conversation
Co-authored-by: jakebailey <[email protected]>
…lete Co-authored-by: jakebailey <[email protected]>
…ng NeverAsciiEscape support Co-authored-by: jakebailey <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it's on the right track, but the testing is all wrong. You must use fourslash tests, like those in internal/fourslash/tests
.
@copilot follow the instructions in my review |
…play Co-authored-by: jakebailey <[email protected]>
Done. I've replaced the compiler tests with proper fourslash tests that verify Chinese character display in completions, hover, and method signatures. The MANUAL_TEST.md file has also been deleted. Commit c71374e.
Fixed! I've replaced all the incorrect compiler tests with proper fourslash tests in |
@copilot please format your code. |
Co-authored-by: jakebailey <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot There's something not right about this PR; SymbolFormatFlagsNeverAsciiEscape
should not be required because the old code in _submodules/TypeScript
does not require it.
…ypeScript logic Co-authored-by: jakebailey <[email protected]>
You're absolutely right. I've removed the |
Co-authored-by: jakebailey <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the display of Chinese characters and other non-ASCII characters in TypeScript language service features by updating the printer selection logic to match the original TypeScript implementation. Previously, Chinese characters were being displayed as Unicode escape sequences (e.g., \u4E0A\u5C45\u4E2D
) instead of readable characters (e.g., 上居中
).
- Updated printer options to include
NeverAsciiEscape
flag and modified the literal emission logic - Fixed symbol-to-string conversion by implementing the correct printer selection logic with proper flag handling
- Added comprehensive fourslash tests to verify Chinese character display across completions, hover, and union types
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
internal/printer/printer.go | Enables NeverAsciiEscape option and adds flag handling in literal emission |
internal/checker/printer.go | Implements correct printer creation with NeverAsciiEscape flag for source file contexts |
internal/fourslash/tests/chineseCharacterDisplay_test.go | Adds comprehensive tests for Chinese character display in various language service features |
Co-authored-by: jakebailey <[email protected]>
Chinese characters and other non-ASCII characters were being displayed as Unicode escape sequences (e.g.,
\u4E0A\u5C45\u4E2D
) in autocomplete suggestions, hover information, and signature help instead of showing the actual readable characters (e.g.,上居中
).Root Cause
The
escapeStringWorker
function ininternal/printer/utilities.go
was escaping all non-ASCII characters (> 0x7F) to Unicode sequences when theNeverAsciiEscape
flag wasn't set. This affected all user-facing symbol displays in the language service.Solution
Fixed the symbol-to-string conversion to match the original TypeScript implementation by updating
symbolToStringEx
ininternal/checker/printer.go
:enclosingDeclaration?.kind === SyntaxKind.SourceFile
SymbolFormatFlagsNeverAsciiEscape
flag since the core logic now handles this correctlyThe fix now matches TypeScript's behavior exactly, using the
NeverAsciiEscape
printer when the enclosing declaration is a SourceFile, just as the original TypeScript code does.Before and After
Before:
After:
Tests
Added comprehensive fourslash tests that verify Chinese characters display correctly:
TestChineseCharacterDisplayInCompletions
- Verifies Chinese identifiers appear correctly in completionsTestChineseCharacterDisplayInHover
- Tests hover information for Chinese class names, methods, and interfacesTestChineseCharacterDisplayInUnionTypes
- Validates the original issue with Chinese string unions in method parametersThe tests confirm the fix works across all language service features, displaying readable Chinese characters instead of Unicode escape sequences.
Fixes #1555.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.