Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 11, 2025

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 in internal/printer/utilities.go was escaping all non-ASCII characters (> 0x7F) to Unicode sequences when the NeverAsciiEscape 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 in internal/checker/printer.go:

  1. Simplified printer selection logic - Updated the condition to exactly match TypeScript: enclosingDeclaration?.kind === SyntaxKind.SourceFile
  2. Added matching comment - Added the same "add neverAsciiEscape for GH#39027" comment as in TypeScript
  3. Removed unnecessary flag - Eliminated the custom SymbolFormatFlagsNeverAsciiEscape flag since the core logic now handles this correctly

The 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:

setLengthTextPositionPreset(preset: "\u4E0A\u5C45\u4E2D" | "\u4E0B\u5C45\u4E2D" | ...

After:

setLengthTextPositionPreset(preset: "上居中" | "下居中" | "右居中" | "左居中", ...

Tests

Added comprehensive fourslash tests that verify Chinese characters display correctly:

  • TestChineseCharacterDisplayInCompletions - Verifies Chinese identifiers appear correctly in completions
  • TestChineseCharacterDisplayInHover - Tests hover information for Chinese class names, methods, and interfaces
  • TestChineseCharacterDisplayInUnionTypes - Validates the original issue with Chinese string unions in method parameters

The 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.

@Copilot Copilot AI changed the title [WIP] autocomplete does not display as chinese when typing Fix Chinese character display in autocomplete and hover by implementing NeverAsciiEscape support Aug 11, 2025
@Copilot Copilot AI requested a review from jakebailey August 11, 2025 20:54
Copilot finished work on behalf of jakebailey August 11, 2025 20:54
Copy link
Member

@jakebailey jakebailey left a 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.

@jakebailey
Copy link
Member

@copilot follow the instructions in my review

Copy link
Contributor Author

Copilot AI commented Aug 11, 2025

@copilot follow the instructions in my review

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.

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.

Fixed! I've replaced all the incorrect compiler tests with proper fourslash tests in internal/fourslash/tests/chineseCharacterDisplay_test.go that verify Chinese character display works correctly in completions, hover, and method signatures. Commit c71374e.

@Copilot Copilot AI requested a review from jakebailey August 11, 2025 21:16
Copilot finished work on behalf of jakebailey August 11, 2025 21:16
@jakebailey
Copy link
Member

@copilot please format your code.

Copy link
Contributor Author

Copilot AI commented Aug 11, 2025

@copilot please format your code.

Code formatted according to project standards. Commit 5d4722a.

Copilot finished work on behalf of jakebailey August 11, 2025 21:31
Copy link
Member

@jakebailey jakebailey left a 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.

Copy link
Contributor Author

Copilot AI commented Aug 11, 2025

@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.

You're absolutely right. I've removed the SymbolFormatFlagsNeverAsciiEscape flag entirely and updated the logic to match the original TypeScript code exactly. The printer selection now only depends on whether the enclosing declaration is a SourceFile, just like in TypeScript. Commit a921563.

@Copilot Copilot AI changed the title Fix Chinese character display in autocomplete and hover by implementing NeverAsciiEscape support Fix Chinese character display by matching TypeScript's printer selection logic Aug 11, 2025
@Copilot Copilot AI requested a review from jakebailey August 11, 2025 21:51
Copilot finished work on behalf of jakebailey August 11, 2025 21:51
@Copilot Copilot AI requested a review from jakebailey August 11, 2025 22:08
Copilot finished work on behalf of jakebailey August 11, 2025 22:08
@jakebailey jakebailey marked this pull request as ready for review August 11, 2025 22:10
@Copilot Copilot AI review requested due to automatic review settings August 11, 2025 22:10
Copy link
Contributor

@Copilot Copilot AI left a 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

@Copilot Copilot AI requested a review from jakebailey August 11, 2025 22:39
Copilot finished work on behalf of jakebailey August 11, 2025 22:39
@jakebailey jakebailey added this pull request to the merge queue Aug 11, 2025
Merged via the queue into main with commit 0caf18a Aug 11, 2025
22 checks passed
@jakebailey jakebailey deleted the copilot/fix-1555 branch August 11, 2025 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

autocomplete does not display as chinese when typing

4 participants