@@ -17,6 +17,46 @@ 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
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
+
20
60
## Problems with syntax highlighting
21
61
22
62
PowerShell syntax highlighting is performed in combintation by the [ PowerShell Extension]
@@ -366,6 +406,7 @@ an issue on GitHub is appropriate.
366
406
[ semantic highlighting ] : https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide
367
407
[ tackling an issue ] : ./development.md
368
408
[ 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
369
410
[ VSCode issue ] : https://github.com/Microsoft/vscode/issues/42356
370
411
[ VSCode Settings ] : https://code.visualstudio.com/docs/getstarted/settings
371
412
[ will break this compatibility ] : https://github.com/PowerShell/vscode-powershell/issues/1310
0 commit comments