Skip to content

Commit 3b5ede3

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 3b5ede3

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

docs/troubleshooting.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,46 @@ 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
26+
intention of this change was to increase predictability, as double-clicking
27+
PowerShell symbols would now select the same portion that the extension
28+
highlights (with the exception of scoped variables due to the continued
29+
inclusion of `:` as a word separator) as well as align with collected user
30+
feedback.
31+
32+
We excluded `-` because unlike programming languages that use `CamelCase` or
33+
`snake_case`, PowerShell uses a `Verb-Noun` style where dashes are part of many
34+
symbol names (like underscores in other languages). So by excluding it we teach
35+
Visual Studio Code to treat `Verb-Noun` as one symbol/word, which matches what
36+
the extension semantically highlights when the cursor is placed within it.
37+
38+
We originally excluded `$` because PowerShell uses it as a prefix for variable
39+
substition, and many users were already excluding it. This change proved
40+
controversial and so after reviewing even more user feedback after the public
41+
rollout of this change, we've decided to compromise among varying user desires
42+
by continuing to exclude `-` but revert the exclusion of `$`.
43+
44+
You can reset the behavior for PowerShell files to Visual Studio Code defaults
45+
with the following code added to `settings.json`:
46+
47+
```json
48+
"[powershell]": {
49+
"editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:'\",.<>/?"
50+
}
51+
```
52+
53+
Similarly you can edit this setting to exclude `$` just by removing it from the
54+
string, and if you do so, double-clicking `$MyVariable` will then select the
55+
whole symbol, matching what the extension semantically highlights, instead of
56+
just `MyVariable`. Keeping `-` will cause double-clicking `Verb-Noun` to only
57+
select the part of the symbol on the side of the `-` that you clicked. These
58+
settings are personal preferences.
59+
2060
## Problems with syntax highlighting
2161

2262
PowerShell syntax highlighting is performed in combintation by the [PowerShell Extension]
@@ -366,6 +406,7 @@ an issue on GitHub is appropriate.
366406
[semantic highlighting]: https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide
367407
[tackling an issue]: ./development.md
368408
[v2021.2.2]: https://github.com/PowerShell/vscode-powershell/releases/tag/v2021.2.2
409+
[v2021.5.1]: https://github.com/PowerShell/vscode-powershell/releases/tag/v2021.5.1
369410
[VSCode issue]: https://github.com/Microsoft/vscode/issues/42356
370411
[VSCode Settings]: https://code.visualstudio.com/docs/getstarted/settings
371412
[will break this compatibility]: https://github.com/PowerShell/vscode-powershell/issues/1310

package.json

Lines changed: 1 addition & 1 deletion
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)