Skip to content

The behavior of VS Code's "files.autoGuessEncoding" setting is not replicated when opening files directly from disk #4753

Open

Description

From: microsoft/vscode#87160

Issue Type: Bug

Steps

  • Create .h and .cpp files (with different encoding)
  • Add comments in Chinese to functions in .h file (encoding: GB2312)
  • Use the predefined function in .cpp file (encoding: utf-8)
  • Trigger C++ suggestions

Results

  • In .h file, the commnet texts were rendered as expected.

image

  • In .cpp file, the comment texts got bad encoding.

image

Version

VS Code version: Code 1.41.0 (9579eda04fdb3a9bba2750f15193e5fafe16b959, 2019-12-11T18:37:42.077Z)
OS version: Windows_NT x64 10.0.18362
Remote OS version: Linux x64 3.10.107-1-tlinux2_kvm_guest-0049

System Info
Item Value
CPUs Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz (8 x 3408)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off
surface_control: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.89GB (9.43GB free)
Process Argv
Screen Reader no
VM 0%
Item Value
Remote SSH: docker
OS Linux x64 3.10.107-1-tlinux2_kvm_guest-0049
CPUs Intel(R) Xeon(R) CPU E5-26xx v4 (8 x 3199)
Memory (System) 15.42GB (1.76GB free)
VM 0%

Activity

  1. sean-mcmanus commented on Dec 18, 2019

    @sean-mcmanus
    Contributor

    We only support UTF-8 currently. We're tracking adding support for other encodings with #414 .

  2. bobbrow commented on Jan 9, 2020

    @bobbrow
    Contributor

    Closing duplicate issue.

  3. sean-mcmanus commented on Sep 2, 2020

    @sean-mcmanus
    Contributor

    BOT Man (@BOT-Man-JL) Should be fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/0.30.0-insiders4 . Let us know if you see any remaining bugs with non-UTF-8 encodings.

  4. BOT-Man-JL commented on Sep 2, 2020

    @BOT-Man-JL

    BOT Man (@BOT-Man-JL) Should be fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/0.30.0-insiders4 . Let us know if you see any remaining bugs with non-UTF-8 encodings.

    Sean McManus (@sean-mcmanus) It still has this problem...

    image
    image

  5. Colengms commented on Sep 2, 2020

    @Colengms
    Contributor

    Hi BOT Man (@BOT-Man-JL) . It's not mentioned here, but have you set VS Code's files.encoding setting to GB2312? The C/C++ Extension does not replicate VS Code's files.autoGuessEncoding behavior when opening files directly from disk, but should now use files.encoding when opening files from disk (if the file does not have a BOM, and is not UTF16 LE/BE). If you are setting files.encoding and not getting the proper text, that may be a bug in 0.30.0-insiders4. If you are expecting the encoding to be auto-detected without setting files.encoding, this issue should be re-opened and de-duped from #414 , as that is not currently supported.

  6. BOT-Man-JL commented on Sep 3, 2020

    @BOT-Man-JL

    Hi Colen Garoutte-Carson (@Colengms), my files.encoding was not set.

    In my scenario, I suppose that files.autoGuessEncoding is necessary because each document is either UTF-8 or GB2312 (not the same encoding), or maybe other encoding.

  7. changed the title [-]Cannot auto detect text encoding in suggest widget[/-] [+]The behavior of the VS Code's "files.autoGuessEncoding" setting is not replicated when opening files directly from disk[/+] on Sep 3, 2020
  8. changed the title [-]The behavior of the VS Code's "files.autoGuessEncoding" setting is not replicated when opening files directly from disk[/-] [+]The behavior of VS Code's "files.autoGuessEncoding" setting is not replicated when opening files directly from disk[/+] on Sep 3, 2020
  9. 1 remaining item

  10. yume-chan commented on Dec 2, 2021

    @yume-chan

    Will it help if vscode provides the guessed file encoding to extensions? microsoft/vscode#824

  11. Colengms commented on Dec 2, 2021

    @Colengms
    Contributor

    Simon Chan (@yume-chan) The C/C++ extension loads header files directly from disk, that are (probably) not open in the editor. These files are loaded in a secondary (IntelliSense) native processes. Having an API to detect file encoding that we could pass an arbitrary file path to, might be helpful. But it's unlikely that performance would be acceptable when making synchronous round-trips from native code to TypeScript for each header in a TU with many headers. So, no, it likely would not helpful. We would likely need to accurately replicate the behavior of VS Code's autoGuessEncoding functionality in native code.

  12. Guojx67 commented on Oct 17, 2022

    @Guojx67

    Same issue. So is there any solutions for this bug?

  13. sean-mcmanus commented on Oct 21, 2022

    @sean-mcmanus
    Contributor

    No, it's not fixed yet.

  14. Guojx67 commented on Jan 10, 2023

    @Guojx67

    Same issue. So is there any solutions for this bug?

    I solved my problem in a strange way. Previously, I set vscode file.encoding to gb2312. However, the hovering comments are garbled. But after reading the issue log again, I found that it has been emphasized that "files directly opened from the disk are opened as the file. encoding format". So in principle, there should be no problem. Then I tried to set vscode file.encoding to gbk, and found that the problem was solved.

    The strange thing is that when I set vscode file.encoding to gb2312, there is no problem with the encoding format of files directly opened from vscode.

    Anyway, my problem has been solved. thanks.

  15. removed
    world readyAn issue relating string character encodings, localization translations, etc.
    on Jan 2, 2025
  16. v-frankwang commented on Jan 26, 2025

    @v-frankwang

    VS Code Version:1.96.4
    C/C++ Extension Version:1.23.4

    We verified this issue on the latest version, when I open the folder from disk and open the .cpp file directly it reproduces the issue, but when I open the .h file once and then open the .cpp file the issue does not occur anymore!
    .cpp file

    Image

    .h file

    Image

  17. v-frankwang commented on Feb 20, 2025

    @v-frankwang

    VS Code Version:1.97.2
    C/C++ Extension Version:1.24.1(pre-release)

    We verified this issue on the latest version, when I open the folder from disk and open the .cpp file directly it reproduces the issue, but when I open the .h file once and then open the .cpp file the issue does not occur anymore!
    .cpp file

    Image

    .h file

    Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions