PowerShellEditorServices icon indicating copy to clipboard operation
PowerShellEditorServices copied to clipboard

No IntelliSense suggestions for variable pasted into script

Open dfinke opened this issue 9 years ago • 9 comments

Add-Type -AssemblyName System.Windows.Forms
$form = New-Object System.Windows.Forms.Form
$form.

Paste this into a ps1 file in vs code. I get no intellisense $form..

If I retype each line, then $form. shows intellisense.

dfinke avatar Feb 25 '16 22:02 dfinke

Really strange that this only happens after pasting. I'll have to walk through the steps to see what might be different.

daviwil avatar Feb 25 '16 22:02 daviwil

If I prime the pump, type get-, then paste, intellisense works.

dfinke avatar Feb 25 '16 23:02 dfinke

Interesting, good data point to have for investigation

daviwil avatar Feb 25 '16 23:02 daviwil

Returns 0 matches unless you do get- first.

https://github.com/PowerShell/PowerShellEditorServices/blob/master/src/PowerShellEditorServices/Language/AstOperations.cs#l68-l74

dfinke avatar Feb 25 '16 23:02 dfinke

I've been looking into this a bit, seems like the ISE gets IntelliSense correctly under the same circumstances. Trying to compare the Editor Services code to it to see what could be different but I haven't found anything conclusive yet.

daviwil avatar Mar 09 '16 19:03 daviwil

Yeah, nothing obvious about this. It's definitely frustrating as a user but fixing it, it's a tough one.

dfinke avatar Mar 09 '16 19:03 dfinke

Got some insight from Jason about this, it seems the reason why this works in the ISE is because System.Windows.Forms is already loaded in the host by the time you ask for IntelliSense so the completion engine is able to give it to you. That assembly is not loaded by default in PSES so its metadata doesn't get loaded until you type its name in for the parameter of "New-Object". If you paste in the code, the completion engine was never used on the assembly so the PowerShell engine doesn't have any way to get those completions.

I'll put this on the backlog until we decide whether this should be considered "by design" or come up with some other clever solution for it.

daviwil avatar Mar 09 '16 22:03 daviwil

Good to know

dfinke avatar Mar 09 '16 22:03 dfinke

Hey @dfinke,

I just gave the repro a try in VSCode and was able get intellisense with a ctrl+SPACE

image

Can you give it another try and see what you find? It's looking like this issue might be fixed.

TylerLeonhardt avatar Dec 07 '17 18:12 TylerLeonhardt