Skip to content

Add documentation for configuring encoding with VSCode and PowerShell #3743

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

Merged
merged 5 commits into from
Feb 28, 2019

Conversation

rjmholt
Copy link
Contributor

@rjmholt rjmholt commented Feb 21, 2019

From PowerShell/vscode-powershell#1761.

Version(s) of document impacted

  • Impacts 6.next document
  • Impacts 6 document
  • Impacts 5.1 document
  • Impacts 5.0 document
  • Impacts 4.0 document
  • Impacts 3.0 document

Reason(s) for not updating all version of documents

  • The documented feature was introduced in version (list version here) of PowerShell
  • This issue only shows up in version (list version(s) here) of the document
  • This PR partially fixes the issue, and issue # tracks the remaining work

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 5c4dbec:

🕙 Preparing: average preparing time is 1 min(s) 9 sec(s)

@rjmholt
Copy link
Contributor Author

rjmholt commented Feb 21, 2019

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 5c4dbec:

🕙 Incremental building: average incremental building time is 12 min(s) 47 sec(s)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 5c4dbec:

✅ Validation status: passed

File Status Preview URL Details
reference/docs-conceptual/components/vscode/vscode-encoding-configuration.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@zjalexander
Copy link
Contributor

OPS Build status updates of commit df461d8:

🕙 Preparing: average preparing time is 1 min(s) 9 sec(s)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit df461d8:

🕙 Incremental building: average incremental building time is 12 min(s) 48 sec(s)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit df461d8:

✅ Validation status: passed

File Status Preview URL Details
reference/docs-conceptual/components/vscode/vscode-encoding-configuration.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@SydneyhSmith
Copy link
Contributor

Yeah, looks good to me, thanks Rob!

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 312d081:

🕙 Preparing: average preparing time is 1 min(s) 9 sec(s)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 312d081:

🕙 Incremental building: average incremental building time is 12 min(s) 48 sec(s)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 312d081:

✅ Validation status: passed

File Status Preview URL Details
reference/docs-conceptual/components/vscode/vscode-encoding-configuration.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@sdwheeler
Copy link
Collaborator

@rjmholt I need to do some major edits for style, etc. I will update the PR and ask you to review.

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 603c928:

🕙 Preparing: average preparing time is 1 min(s) 9 sec(s)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 603c928:

🕙 Incremental building: average incremental building time is 12 min(s) 49 sec(s)

@sdwheeler
Copy link
Collaborator

@rjmholt @TylerLeonhardt Please review my changes to this PR.

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 603c928:

✅ Validation status: passed

File Status Preview URL Details
reference/docs-conceptual/components/vscode/understanding-file-encoding.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)
reference/docs-conceptual/components/vscode/using-vscode.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)
reference/docs-conceptual/toc.yml ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 53034a0:

🕙 Preparing: average preparing time is 1 min(s) 9 sec(s)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 53034a0:

🕙 Incremental building: average incremental building time is 12 min(s) 50 sec(s)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 53034a0:

✅ Validation status: passed

File Status Preview URL Details
reference/docs-conceptual/components/vscode/understanding-file-encoding.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)
reference/docs-conceptual/components/vscode/using-vscode.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)
reference/docs-conceptual/toc.yml ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 0a7cdc4:

🕙 Preparing: average preparing time is 1 min(s) 9 sec(s)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 0a7cdc4:

🕙 Incremental building: average incremental building time is 12 min(s) 50 sec(s)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 0a7cdc4:

✅ Validation status: passed

File Status Preview URL Details
reference/docs-conceptual/components/vscode/understanding-file-encoding.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)
reference/docs-conceptual/components/vscode/using-vscode.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)
reference/docs-conceptual/toc.yml ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.


When using VS Code to create and edit PowerShell scripts, it is important that your files are saved
using the correct character encoding format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need a shortcut section at the top of some kind, if only a link to the recommended settings in the other doc.

Otherwise I think people aren't going to read the whole thing and will just keep opening issues in the vscode-PowerShell repo.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the preview rendering of the article. All H2 appear in the right-nav panel. Very easy to jump to the configuration header. Also, an abbreviated version of this is in the using-vscode.md article.

extension falls back to loading that script's content from the file system. VSCode defaults to
UTF-8 encoding, but uses [byte-order mark][], or BOM, detection to select the correct encoding.

The problem occurs when assuming the encoding of BOM-less formats (like [UTF-8] with no BOM and [Windows-1252]).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linking to UTF-8 and Windows-1252 seems inconsistent. I think it should either be a link in the first instance or a link everywhere. Certainly we need to have some discoverable way to explain what is meant by UTF-8 and Windows-1252.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be first mention. I will fix it.


In the Linux world, on the web, and in .NET Standard, UTF-8 is now the dominant encoding.

Unicode encodings also have the concept of a byte-order mark (BOM). BOMs occur at the beginning of
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byte-order mark should be a link here, since this paragraph explains the concept

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already a link at first mention. Do we want to move this content up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't want to front-load the concept. We can leave for now I think

Choosing an encoding depends on the platforms and applications you use to read and write your
PowerShell files.

On Windows, many applications have long used [Windows-1252]. Many .NET applications use [UTF-16],
Copy link
Contributor Author

@rjmholt rjmholt Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph now seems fragmented and should be merged with the one below. It might be better as a series of points:

Different systems and applications tend to use different encodings:

- In .NET Standard, on the web and in the Linux world, [UTF-8][] is now the dominant encoding.
- Many .NET Framework applications use [UTF-16][]. For historical reasons, this is sometimes called "Unicode" in the .NET ecosystem, a term that now refers to a broad [standard](https://en.wikipedia.org/wiki/Unicode) including both UTF-8 and UTF-16.
- On Windows, many native applications predating Unicode continue to use [Windows-1252][] by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joeyaiello made the good point that the Unicode term is mainly used in .NET.

It's important because of the [System.Text.Encoding]::Unicode enum value and the Get-Content -Encoding Unicode parameter value, which both refer to UTF-16. We have to say "Unicode", but don't want people to think they want to use the "Unicode" encoding.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used your bulleted list.

to be bytes that rarely occur in non-Unicode text, allowing a reasonable guess that text is Unicode
when a BOM is present.

BOMs are optional and their adoption isn't as popular in the Linux world because a dependable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be either because of or is used

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is

```

The following [this script](https://gist.github.com/rjmholt/3d8dd4849f718c914132ce3c5b278e0e) can be
used to determine what encoded your PowerShell session infers for a script without a BOM.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
used to determine what encoded your PowerShell session infers for a script without a BOM.
used to determine what encoding your PowerShell session infers for a script without a BOM:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

### Scripts

Scripts already on the file system may need to be re-encoded to your new chosen encoding. In the
bottom bar of VSCode, you'll see the label UTF-8. Click it to open the action bar and select
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also keep the link to something visual with this information. I always find GUI instructions impossible to follow

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added link to vscode docs

## What is file encoding and why is it important?

VSCode manages the interface between a human entering strings of characters into a buffer and
reading/writing blocks of bytes to the filesystem. When VSCode saves the file, it uses a text
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reading/writing blocks of bytes to the filesystem. When VSCode saves the file, it uses a text
reading/writing blocks of bytes to the filesystem. When VSCode saves a file, it uses a text

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

2. When scripts are executed directly in the Integrated Console, they're read from the file by
PowerShell directly. Tf PowerShell's encoding differs from VSCode's, something can go wrong here.
3. When a script that is open in VSCode references another script that is not open in VSCode, the
extension falls back to loading that script's content from the file system. VSCode defaults to
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last sentence here needs to refer to the extension, not VSCode. PowerShell Editor Services loads the file in this case, and also does BOM detection.

It's an important distinction since many of our users don't know where the line ends between VSCode and the PowerShell extension.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. It was unclear to me as well. Fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an unfortunately complicated architecture, made worse by the fact that the PowerShell extension doesn't have a nice name to differentiate itself as a component

VSCode's default encoding is UTF-8 without BOM.

To set [VSCode's encoding](https://code.visualstudio.com/docs/editor/codebasics#_file-encoding-support),
go to the VSCode settings (Ctrl+,) and set the `"files.encoding"` setting:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key chords should still be emphasised in some way. If the <kbd> tags are unacceptable, the VSCode docs use monospace spans.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some back-and-forth about this. We try to minimize inline HTML tags but this one is valuable. Restored the kbd tags.

Copy link
Contributor Author

@rjmholt rjmholt Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're the only tags I use in markdown -- hopefully it will get a native syntax eventually

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 0aa9bbe:

🕙 Preparing: average preparing time is 1 min(s) 9 sec(s)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 0aa9bbe:

🕙 Incremental building: average incremental building time is 12 min(s) 50 sec(s)

Copy link
Contributor Author

@rjmholt rjmholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't approve my own PR, but LGTM -- just needs that last suggestion change I think (I tagged you @sdwheeler)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 0aa9bbe:

✅ Validation status: passed

File Status Preview URL Details
reference/docs-conceptual/components/vscode/understanding-file-encoding.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)
reference/docs-conceptual/components/vscode/using-vscode.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)
reference/docs-conceptual/toc.yml ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 2cfd5c9:

🕙 Preparing: average preparing time is 1 min(s) 9 sec(s)

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 2cfd5c9:

🕙 Incremental building: average incremental building time is 12 min(s) 50 sec(s)

@sdwheeler
Copy link
Collaborator

@rjmholt I fixed that last item you tagged. Waiting for build to finish. Thanks.

@zjalexander
Copy link
Contributor

OPS Build status updates of commit 2cfd5c9:

✅ Validation status: passed

File Status Preview URL Details
reference/docs-conceptual/components/vscode/understanding-file-encoding.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)
reference/docs-conceptual/components/vscode/using-vscode.md ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)
reference/docs-conceptual/toc.yml ✅Succeeded View (powershell-3.0)
View (powershell-4.0)
View (powershell-5.0)
View (powershell-5.1)
View (powershell-6)

For more details, please refer to the build report.

Note: If you changed an existing file name or deleted a file, broken links in other files to the deleted or renamed file are listed only in the full build report.

@sdwheeler sdwheeler merged commit f6d5a26 into MicrosoftDocs:staging Feb 28, 2019
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.

5 participants