PowerShell / PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
MIT License
632 stars 215 forks source link

No IntelliSense suggestions for variable pasted into script #170

Open dfinke opened 8 years ago

dfinke commented 8 years ago
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.

daviwil commented 8 years ago

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

dfinke commented 8 years ago

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

daviwil commented 8 years ago

Interesting, good data point to have for investigation

dfinke commented 8 years ago

Returns 0 matches unless you do get- first.

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

daviwil commented 8 years ago

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.

dfinke commented 8 years ago

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

daviwil commented 8 years ago

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.

dfinke commented 8 years ago

Good to know

TylerLeonhardt commented 6 years ago

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.