rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.09k stars 1.57k forks source link

There are inconsistencies when clicking 'run' and 'debug' on the main function. #17758

Open aphage opened 1 month ago

aphage commented 1 month ago

rust-analyzer version: rust-analyzer version: 0.3.2053-standalone (fd74511f3 2024-07-28)

rustc version: rustc 1.76.0 (07dca489a 2024-02-04)

editor or extension: Version: 1.91.1 (system setup)

relevant settings: default

code snippet to reproduce:

fn main() {
    println!("Hello, world!");
    println!("你好,世界!");
}

屏幕截图 2024-08-01 084611 屏幕截图 2024-08-01 085101

There are inconsistencies when clicking 'run' and 'debug' on the main function.

aphage commented 1 month ago

CodeLLDB: v1.10.0

Veykril commented 1 month ago

~What inconsistencies specifically?~ Ah the output is scrambled in the latter

aphage commented 1 month ago

~What inconsistencies specifically?~ Ah the output is scrambled in the latter

yes.

roife commented 1 month ago

This might be an issue about encoding of the terminal: UTF-8 is used during runtime, but a different encoding (possibly GBK) is used during debugging.

Due to historical reasons, Windows has not fully migrated to UTF-8, leading to this problem (which cannot be reproduced on Linux or macOS).

Veykril commented 1 month ago

Can we somehow work around this? (by being explicit about encodings within the extension somewhere maybe?)

roife commented 1 month ago

Emmm, this issue might occur wherever CodeLLDB (or the cmd) is used, so I believe the best approach is to change settings in terminal.integrated.profiles.windows.

"terminal.integrated.profiles.windows": {
    "PowerShell": {
        "source": "PowerShell",
        "icon": "terminal-powershell",
        "args": ["-NoExit", "chcp 65001"]
    },
    "Command Prompt": {
        "path": [
            "${env:windir}\\Sysnative\\cmd.exe",
            "${env:windir}\\System32\\cmd.exe"
        ],
        "args": ["/K", "chcp 65001"],
        "icon": "terminal-cmd"
    },
    "Git Bash": {
        "source": "Git Bash"
    }
}

Here chcp 65001 is used to enable UTF-8.

aphage commented 1 month ago

OK, should we close this issue?