@@ -17,6 +17,45 @@ Script analysis is provided by the [PSScriptAnalyzer] project on GitHub. If the
17
17
message starts with ` [PSScriptAnalyzer] ` or if you are getting faulty script diagnostics
18
18
(red and green squiggly lines under PowerShell in scripts) please [ open an issue there] .
19
19
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
+
20
59
## Problems with syntax highlighting
21
60
22
61
PowerShell syntax highlighting is performed in combintation by the [ PowerShell Extension]
@@ -366,6 +405,7 @@ an issue on GitHub is appropriate.
366
405
[ semantic highlighting ] : https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide
367
406
[ tackling an issue ] : ./development.md
368
407
[ 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
369
409
[ VSCode issue ] : https://github.com/Microsoft/vscode/issues/42356
370
410
[ VSCode Settings ] : https://code.visualstudio.com/docs/getstarted/settings
371
411
[ will break this compatibility ] : https://github.com/PowerShell/vscode-powershell/issues/1310
0 commit comments