You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However VS Code currently doesn't report a .go file not encoded as UTF-8. As a result, if a source code has been created outside VS Code as UTF-16 and is edited with VS code, editing works fine, but compiling doesn't.
Describe the solution you'd like
When opening a .go file, alert if encoding is not UTF-8.
Set an error on line 1 about the encoding (maybe a task for gopls?).
Additional context
See also golang/go#71872 about the compiler not being kind to diagnose this encoding issue.
Use case: a Go source file incorrectly created on Windows using the echo command from Windows PowerShell.
Windows PowerShellCopyright (C) Microsoft Corporation. Tous droits réservés.Installez la dernière version de PowerShell pour de nouvelles fonctionnalités et améliorations ! https://aka.ms/PSWindowsPS C:\Users\dolmen> cd CodePS C:\Users\dolmen\Code> mkdir hello Répertoire : C:\Users\dolmen\CodeMode LastWriteTime Length Name---- ------------- ------ ----d----- 21/02/2025 13:46 helloPS C:\Users\dolmen\Code> cd helloPS C:\Users\dolmen\Code\hello> go mod init github.com/dolmen-go/hellogo: creating new go.mod: module github.com/dolmen-go/helloPS C:\Users\dolmen\Code\hello> echo "package main" > hello.goPS C:\Users\dolmen\Code\hello> type hello.gopackage mainPS C:\Users\dolmen\Code\hello> go build .read C:\Users\dolmen\Code\hello\hello.go: unexpected NUL in inputPS C:\Users\dolmen\Code\hello> Format-Hex hello.go Chemin d'accès : C:\Users\dolmen\Code\hello\hello.go 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F00000000 FF FE 70 00 61 00 63 00 6B 00 61 00 67 00 65 00 .þp.a.c.k.a.g.e.00000010 20 00 6D 00 61 00 69 00 6E 00 0D 00 0A 00 .m.a.i.n.....PS C:\Users\dolmen\Code\hello> go fmt .read C:\Users\dolmen\Code\hello\hello.go: unexpected NUL in input
Screenshot of VS Code showing the hello.go file encoded as UTF-16 LE (bottom right) and no error reported. Sorry about the french locale.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
The Go language specification allows only UTF-8 as a valid encoding of source files. Spec: https://go.dev/ref/spec#Source_code_representation
However VS Code currently doesn't report a .go file not encoded as UTF-8. As a result, if a source code has been created outside VS Code as UTF-16 and is edited with VS code, editing works fine, but compiling doesn't.
Describe the solution you'd like
gopls
?).Additional context
See also golang/go#71872 about the compiler not being kind to diagnose this encoding issue.
Use case: a Go source file incorrectly created on Windows using the
echo
command from Windows PowerShell.Screenshot of VS Code showing the

hello.go
file encoded as UTF-16 LE (bottom right) and no error reported. Sorry about the french locale.The text was updated successfully, but these errors were encountered: