Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intellisense for "[PSCustomObject]" leaves an extra close square bracket causing a syntax error #5003

Open
5 of 6 tasks
JLambEJG opened this issue Jun 11, 2024 · 5 comments
Open
5 of 6 tasks
Labels
Area-Snippets Issue-Bug A bug to squash. Up for Grabs Will shepherd PRs.

Comments

@JLambEJG
Copy link

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

Using Intellisesnse while typing-out [PSCustomObject], before I type the closing square brackets, an extra square bracket is appended, causing a syntax error.

PowerShell Version

$psversiontable ;host

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2024.2.2
InstanceId       : 795c2dfd-55fe-4258-b089-29937135df2b
UI               : System.Management.Automation.Internal.Host.InternalHos 
                   tUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy     
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

code --version
1.90.0
89de5a8d4d6205e5b11647eb6a74844ca23d2573
x64

Extension Version

code --list-extensions --show-versions | select-string powershell

[email protected]

Steps to Reproduce

Type "[PSCustom" and then press the tab key

Visuals

Pressing TAB at this point:
image

Causes this extra square bracket at this point:
image

Logs

No response

@JLambEJG JLambEJG added Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Jun 11, 2024
@JustinGrote
Copy link
Collaborator

Thanks for the report! This is a snippet and will need to be addressed there, should be fairly simple. In the meantime, if you choose the option to sort snippet suggestions to bottom, the normal intellisense will apply.

@JustinGrote JustinGrote added Area-Snippets Up for Grabs Will shepherd PRs. and removed Needs: Triage Maintainer attention needed! labels Jun 12, 2024
@JustinGrote
Copy link
Collaborator

Relevant snippet to fix

"PSCustomObject": {
"prefix": [
"pscustomobject",
"[PSCustomObject]"
],
"description": "Create a custom object from a hashtable of properties. More: Get-Help about_PSCustomObject",
"body": [
"[PSCustomObject]@{",
"\t${1:Name} = ${2:Value}",
"}"
]
},

@ArieHein
Copy link

ArieHein commented Aug 27, 2024

As far as i can see, it seems the external close square bracket isnt really a bug.
The snippet does not add any brackets, as far i understand the logic.

I think you have an extension that adds the right closing bracket but the cursor position doesnt go beyond it when you tab.

Try the following:

  • Type an opening bracket only. If you see a closing bracket appear, start typing just ps
  • Now the cursor will be positioned after the s character but before the closing bracket
  • Press the tab key and you will see the issue you had in your image.

Now repeat but before you press the tab for completion, move the character one position to the right so now it is positioned on the closing bracket.

If you press the tab now, it will be expanded correctly without "extra" closing bracket.

You can also test it without using brackets, but you just can use ps by itself, but if you type psc and then tab, it will expand correctly and again not show "extra" closing bracket.

Hope this made sense.

@JLambEJG
Copy link
Author

Yes, that approach makes sense as a workaround, although it's unique compared to Intellisense's behavior in other contexts. Typically, when the suggestion box appears, pressing TAB fills in the command as expected. However, with [PSCustomObject], Intellisense's performance is inconsistent. I'll make a mental note of how to manage it in these situations. Thank you for the information; it was useful, even if not quite what I was looking for.

@ArieHein
Copy link

ArieHein commented Aug 28, 2024

The intention was not necessarily to provide a workaround, but rather to show why its not really a bug.
But if it helps you get the results , that's cool as well.

What you're seeing, and i do as well, is actually the expected behavior in my eyes.

You can replace the opening bracket with say @@ and typing in between them pscustomobject and then press tab for expansion and you will see that only the inside was expanded.
So what we could potentially argue that the front square bracket should probably not have been replaced, however it counters line 532.

as for consistency, i think its actually behaves the same in other places where the prefix has at least 2 options, one without square brackets and one without. An example is in lines 500-512 using [SuppressMessageAttribute]
And if you start with opening bracket, ending appears automatically, start typing the inside of it and tab and the extra closing bracket appear, so id say it is consistent.

Can always try to run VSCode without anything else other than the PowerShell extension and verify that nothing adds a closing brackets andtest again and you will not see that closing bracket as the closing one will not appear immediately after you typed the opening one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Snippets Issue-Bug A bug to squash. Up for Grabs Will shepherd PRs.
Projects
None yet
Development

No branches or pull requests

3 participants