Skip to content

Commit 1137c68

Browse files
committed
Include $ in PowerShell word separators
Add to troubleshooting guide how to modify this behavior and the reasoning behind the suggestions.
1 parent 88f9688 commit 1137c68

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

docs/troubleshooting.md

+40
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,45 @@ Script analysis is provided by the [PSScriptAnalyzer] project on GitHub. If the
1717
message starts with `[PSScriptAnalyzer]` or if you are getting faulty script diagnostics
1818
(red and green squiggly lines under PowerShell in scripts) please [open an issue there].
1919

20+
## Double-click isn't selecting the whole variable
21+
22+
Visual Studio Code provides a default set of word separators, that is,
23+
characters that split words and so affect double-click selections. The editor's
24+
defaults include both `-` and `$`. In [v2021.5.1] we starting providing a
25+
default value for PowerShell files that excludes these two symbols. The primary
26+
motivation for this was to make the editor's selection behavior more closely
27+
match the extension's highlighting behavior (where whole symbols such as
28+
`Verb-Noun` and `$MyVariable` are highlighted) as well as align with collected
29+
user feedback.
30+
31+
We excluded `-` because unlike programming languages that use `CamelCase` or
32+
`snake_case`, PowerShell uses a `Verb-Noun` style where dashes are part of many
33+
symbol names (like underscores in other languages). So by excluding it we teach
34+
Visual Studio Code to treat `Verb-Noun` as one symbol/word, which matches what
35+
the extension semantically highlights when the cursor is placed within it.
36+
37+
We originally excluded `$` because PowerShell uses it as a prefix for variable
38+
substition, and many users were already excluding it. This change proved
39+
controversial and so after reviewing even more user feedback after the public
40+
rollout of this change, we've decided to compromise among varying user desires
41+
by continuing to exclude `-` but revert the exclusion of `$`.
42+
43+
You can reset the behavior for PowerShell files to Visual Studio Code defaults
44+
with the following code added to `settings.json`:
45+
46+
```json
47+
"[powershell]": {
48+
"editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:'\",.<>/?"
49+
}
50+
```
51+
52+
Similarly you can edit this setting to exclude `$` just by removing it from the
53+
string, and if you do so, double-clicking `$MyVariable` will then select the
54+
whole symbol, matching what the extension semantically highlights, instead of
55+
just `MyVariable`. Keeping `-` will cause double-clicking `Verb-Noun` to only
56+
select the part of the symbol on the side of the `-` that you clicked. These
57+
settings are personal preferences.
58+
2059
## Problems with syntax highlighting
2160

2261
PowerShell syntax highlighting is performed in combintation by the [PowerShell Extension]
@@ -366,6 +405,7 @@ an issue on GitHub is appropriate.
366405
[semantic highlighting]: https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide
367406
[tackling an issue]: ./development.md
368407
[v2021.2.2]: https://github.com/PowerShell/vscode-powershell/releases/tag/v2021.2.2
408+
[v2021.5.1]: https://github.com/PowerShell/vscode-powershell/releases/tag/v2021.5.1
369409
[VSCode issue]: https://github.com/Microsoft/vscode/issues/42356
370410
[VSCode Settings]: https://code.visualstudio.com/docs/getstarted/settings
371411
[will break this compatibility]: https://github.com/PowerShell/vscode-powershell/issues/1310

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@
899899
"[powershell]": {
900900
"debug.saveBeforeStart": "nonUntitledEditorsInActiveGroup",
901901
"editor.semanticHighlighting.enabled": false,
902-
"editor.wordSeparators": "`~!@#%^&*()=+[{]}\\|;:'\",.<>/?"
902+
"editor.wordSeparators": "`~!@#$%^&*()=+[{]}\\|;:'\",.<>/?"
903903
}
904904
},
905905
"themes": [

0 commit comments

Comments
 (0)