Vscode-powershell: Holding Ctrl+Shift+Left/Right Arrow doesn't work in the variable selection

Created on 10 Jun 2018  ·  19Comments  ·  Source: PowerShell/vscode-powershell

System Details

  • Operating system name and version: Win 10
  • VS Code version: 1.23.1
  • PowerShell extension version: 1.7.0.0

Issue Description

I can't select a variable with CTRL+SHIFT+LEFT/RIGHT ARROW, it doesn't continue highlighting a $ character.

kind regard :-)

All 19 comments

Hi @Ali64B, would you be able to provide a small reproducible scenario? Like a code snippet we could try to reproduce this with? And if the behaviour is more visual, you should be able to upload a GIF here that demonstrates it.

Variable in PowerShell must start with “$” and since “$” has been introduced as white space character there is no way to select the whole variable name with one time using CTRL+SHIFT+LEFT/RIGHT ARROW.

Hey @Ali64B, can you elaborate on what you mean by

since "$" has been introduced as a white space character

I'd be interested in knowing if this issue repros without the PowerShell extension installed. If it does repro, this could be an issue we need to bring up with VSCode itself on how we can fix this at their level.

Hi @rjmholt.
That is exactly what I told.

@Ali64B No I mean, that regex defines "words" in PowerShell, and already includes $variable, so that should already work (but evidently doesn't).

Is there another place where you're saying we're defining whitespace characters?

Otherwise, it may be a change we need to make in the VSCode code, although I'm not sure where.

So to be clear, I'm not sure what is causing this bug, but I think the line I linked above is already correct.

Good find! That looks like it might be the part in question. That means users can override that setting then yes??

Yes , you're right.

So I'm thinking we should come up with a good regex for PowerShell and post it here (so that anyone can use it). And then work out if there's a way for us to set that setting when the extension is running.

I've also followed up on that issue you linked.

@Ali64B you might want to take a look at this as a work around.

https://github.com/Microsoft/vscode/issues/2036#issuecomment-193873124

, "editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?"

Since we don't have this at the language level yet, I'm gonna go ahead and close this in favor of the VSCode issue.

Let me know if you think otherwise!

So I tried that "editor.wordSeparators" for a while and decided I didn't like it. When you double-click to select a variable $foo it will not highlight any instances of the form ${foo} which is common inside double-quoted strings. I'm going back to the default value for this setting.

Does this work better?

"editor.wordSeparators": "`~!@#%^&*()-=+[}\\|;:'\",.<>/?"

Also, I'm annoyed its a just a character list rather than a regex or something... I thought the "word" definition was supposed to deal with this.

Still leaves the ${var} form unselected:

image

And you still have the issue of the whole variable not being selected when you specify the scope e.g,: $global:foo = 1.

Oh whoops, I left one of the braces in. Also we could try taking the colon out too:

"editor.wordSeparators": "`~!#%^&*()-=+[]\\|;'\",.<>/?"

(Also took the @ out for splatting)

That handles the $script:foo = 1 case but it still won't highlight the variable in this string "${script:foo}" when I have selected $script:foo in the assignment statement.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TheDanishDynamo picture TheDanishDynamo  ·  3Comments

itfranck picture itfranck  ·  3Comments

nathan-alden-hp picture nathan-alden-hp  ·  3Comments

guidooliveira picture guidooliveira  ·  3Comments

pcgeek86 picture pcgeek86  ·  4Comments