coc-extensions / coc-powershell

PowerShellEditorService integration for coc.vim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[coc.nvim] Error on active extension coc-powershell: TypeError: (intermediate value) is not iterable

Gankarloo opened this issue · comments

System Details

  • Vim or NeoVim?: Vim
  • Version of Vim (run vim --version) or NeoVim (run nvim --version): 8.1
  • Version of coc-powershell (in Vim or NeoVim: :CocList extensions coc-powershell): 0.0.21
  • Operating System: Windows 10
  • PowerShell version (in PowerShell: $PSVersionTable): 5.1.17763.592

Issue Description

[coc.nvim] Error on active extension coc-powershell: TypeError: (intermediate value) is not iterable

Expected Behaviour

No error on loading extension

Actual Behaviour

Above error
and extension not active.

CocInfo:

## versions

vim version: VIM - Vi IMproved 8.1 (2018 May 18, compiled May 18 2018 18:36:07)
node version: v10.16.3
coc.nvim version: 0.0.74-e04013a8bd
term: undefined
platform: win32

## Messages
Messages maintainer: Bram Moolenaar <Bram@vim.org>
"\tmp\Powershell Scripts\Find-GPObyMatch.ps1" 0L, 0C
[coc.nvim] Error on active extension coc-powershell: TypeError: (intermediate value) is not iterable
## Output channel: snippets


## Output channel: powershell

starting.
pwshPath = C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
bundledModulesPath = C:\Users\ankarloog\Dropbox\Utilities\gVimPortable8\Data\settings\AppData\Local\coc\extensions\node_modules\coc-powershell\PowerShellEditorServices

I started getting this error recently too. It was working a few weeks ago.

PowerShell/Windows:


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

Coc info:

:CocInfo
## versions

vim version: VIM - Vi IMproved 8.1 (2018 May 18, compiled Sep 25 2019 14:31:47)
node version: v8.11.3
coc.nvim version: 0.0.74-317e3212e3
term: undefined
platform: win32

Are you using gVim? I heard there was an issue with gVim and I don't think there's much we can do about that.

Yes, I'm using gVim. The problem occurs on Vim too (Windows again). This was working a few months ago. I've reverted back to several Vim versions that I've compiled over the past year and also compiled the latest Vim (8.1.2176). None of them worked.

I've tried the coc JavaScript and Python plugins and they're working in gVim.

I've also updated nodejs to the latest version: v10.16.3.

Is there any diagnostics I could do to help?

This is probably related to our use of a terminal buffer. JS and Python don't use that. @yatli or @chemzqm any thoughts on how we can diagnose this? It works well on non-Windows.

I have reproduced the issue.

Fixed by neoclide/coc.nvim@36e4768, there is an unnamed variable, also improved the error message

I can confirm that the error has disappeared. Auto-completion is now working and a PowerShell Integrated Console appears when a .ps1 file is opened. Thank you for fixing this error.

However, when the .ps1 is closed, the PowerShell is the only window open and I can't close it! Exit or Quit does nothing. The only thing I can do is click the X in the top right corner to close the gvim app. When I click X, the following message appears:

Kill job in "!C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive 
d:\data\LinuxHome\AppData\Local\coc\extensions\node_modules\coc-powershell\PowerShellEditorServices\PowerShellEditorServices\Start-Edit
orServices.ps1 -HostName coc.vim -HostProfileId coc.vim -HostVersion 2.0.0 -LogPath d:\data\LinuxHome\AppData\Local\coc\extensions\node_
modules\coc-powershell\.pses\logs\fe4f880d396adc752f861abcd0fb8147-16456\log.txt -LogLevel Normal -BundledModulesPath 
d:\data\LinuxHome\AppData\Local\coc\extensions\node_modules\coc-powershell\PowerShellEditorServices -EnableConsoleRepl 
-SessionDetailsPath d:\data\LinuxHome\AppData\Local\coc\extensions\node_modules\coc-powershell\.pses\logs\fe4f880d396adc752f861abcd0f
b8147-16456\session"?

The version of PowerShell in the console is 5.1 not the 6.2 that's installed. Is there a reason the latest version isn't used? Both are in the path but 6.2 appears first in the PATH environment variable.

@Praful

Thank you for fixing this error.

Thanks @chemzqm! 🎉

the PowerShell is the only window open and I can't close it!

You mean the actual PowerShell shell that you launched gvim from? Or the PowerShell Integrated Console? If the latter, try :q. or :qall?

The version of PowerShell in the console is 5.1 not the 6.2 that's installed. Is there a reason the latest version isn't used?

We don't look at the PATH because it's expensive. Currently on Windows, we use 5.1 by default. You can change this by adding "powershell.powerShellExePath": "/path/to/pwsh.exe". To you :CocConfig.

That code path will change, once PowerShell/vscode-powershell#2238 goes through in the vscode extension. That will have PowerShell Core be the default if it is installed.

You mean the actual PowerShell shell that you launched gvim from? Or the PowerShell Integrated Console? If the latter, try :q. or :qall?

I'm referring here to the PowerShell Integrated Console. Once that becomes the sole window open in gvim, I can't do anything except type in the console! The gvim menus are disabled and :q or :qall are just entered into the console, as if they were shell commands.

If I :qall when the .ps1 script is also open (ie two windows are open: the script and the PowerShell Integrated Console), I get the Kill job in "!C:\WINDOWS\System32\... prompt I quoted in my previous message. Once I click Yes, gvim closes.

You can change this by adding "powershell.powerShellExePath": "/path/to/pwsh.exe".

Thanks, that worked. Is there a reason that my PowerShell profile is not being invoked (for either 5.1 or 6.2) when the PowerShell Integrated Console appears?

BTW, thank you for providing an incredibly useful plugin!

@Praful

I'm referring here to the PowerShell Integrated Console. Once that becomes the sole window open in gvim, I can't do anything except type in the console! The gvim menus are disabled and :q or :qall are just entered into the console, as if they were shell commands.

First do ctrl+\, ctrl+n I think, to go to "Normal" mode for the terminal. Then do :q. Although gVim might have a different way to exit a terminal buffer.

Is there a reason that my PowerShell profile is not being invoked (for either 5.1 or 6.2) when the PowerShell Integrated Console appears?

It's a different profile. In the PowerShell Integrated Console, run $profile to get the path to the coc-powershell profile.

This is similar to how the VSCode extension or ISE have different profiles.

That code path will change, once PowerShell/vscode-powershell#2238 goes through in the vscode extension. That will have PowerShell Core be the default if it is installed.

@TylerLeonhardt is this because you're planning to bring the update into coc-powershell?

@corbob yep. In fact, I might steal that code and publish it on npm.

First do ctrl+, ctrl+n I think, to go to "Normal" mode for the terminal. Then do :q.

Thanks - that works. However, the behaviour is quirky.

If I close the script first (:q), the PowerShell Integrated Console (PSIC) is now the full window. If I press ctrl+\, ctrl+n, the PSIC prompts:

Kill job in "!C:/Program Files/PowerShell/6/pwsh.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive 
d:\data\LinuxHome\AppData\Local\coc\extensions\node_modules\coc-powershell\PowerShellEditorServices\PowerShellEditorServices\Start-EditorServices.ps1 -HostName coc.vim -HostProfileId coc.vim -HostVersion 2.0.0 -LogPath d:\data\LinuxHome\AppData\Local\coc\extensions\node_modules\coc-powershell\.pses\logs\322c8e0cf791da7487c39ff41b00c77e-4216\log.txt -LogLevel Normal -BundledModulesPath d:\data\LinuxHome\AppData\Local\coc\extensions\node_modules\coc-powershell\PowerShellEditorServices -EnableConsoleRepl -SessionDetailsPath d:\data\LinuxHome\AppData\Local\coc\extensions\node_modules\coc-powershell\.pses\logs\322c8e0cf791da7487c39ff41b00c77e-4216\session"?

After I click Yes, the PSIC closes but another PSIC opens!

I then repeat the above sequence: go to normal mode on the newly created PSIC, click Yes at prompt. Then the PSIC closes and gvim quits.

Vim display the same behaviour as gvim. This is all on Windows 10 1903.

This used to all work seamlessly when I last used it (about five months ago). Was there a PSIC because I don't remember one? Is it necessary to have a (visible or invisible) PSIC at all?

It's a different profile. In the PowerShell Integrated Console, run $profile to get the path to the coc-powershell profile.

The profile coc.vim_profile.ps1 is empty. Obviously, I can just put a call to the default PowerShell profile in coc.vim_profile.ps1 but is there a reason you favour an empty profile over the one PowerShell uses by default (Microsoft.PowerShell_profile.ps1)?

This used to all work seamlessly when I last used it (about five months ago). Was there a PSIC because I don't remember one? Is it necessary to have a (visible or invisible) PSIC at all?

It's kinda new... There's a setting to hide it at start up. It's like...

"powerShell.integratedConsole.showOnStartup":false

but is there a reason you favour an empty profile over the one PowerShell uses by default (Microsoft.PowerShell_profile.ps1)?

It's a different host and therefore should be a different profile. That's typically the guidance.

It's a different host and therefore should be a different profile. That's typically the guidance.

This is also what is done in the ISE and vscode. If you populate $profile.CurrentUserAllHosts or $profile.AllUsersAllHosts it should be picked up (or at least it is in vscode).

Thanks @chemzqm Now it works.
I also find the PSIC annoying when exiting vim or I accidently switch to that buffer.
Is there a way to automatically close the Terminal buffer when the buffer running coc-powershell is closed?

@TylerLeonhardt

"powerShell.integratedConsole.showOnStartup":false

The above works. However, the PSIC is just hidden. The same kill job... prompts appear when quitting gvim.

If you try to :bd the PSIC, you get:

Save changes to "!C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoProfile 
-NonInteractive c:\data\LinuxHome\AppData\Local\coc\extensions\node_modules\coc-powershell\PowerShellEditorServi
ces\PowerShellEditorServices\Start-EditorServices.ps1 -HostName coc.vim -HostProfileId coc.vim -HostVersion 2.0.0 
-LogPath c:\data\LinuxHome\AppData\Local\coc\extensions\node_modules\coc-powershell\.pses\logs\e0bbe13ceb999
84bbc38ad2fc447995c-6232\log.txt -LogLevel Normal -BundledModulesPath c:\data\LinuxHome\AppData\Local\coc\ext
ensions\node_modules\coc-powershell\PowerShellEditorServices -EnableConsoleRepl -SessionDetailsPath 
c:\data\LinuxHome\AppData\Local\coc\extensions\node_modules\coc-powershell\.pses\logs\e0bbe13ceb99984bbc38a
d2fc447995c-6232\session"?

with possible options of "Yes", "No" and "Cancel". Regardless of which you choose, nothing visibly happens! So the only way of closing the PSIC is to quit (g)vim on Windows.

Is this intentional behaviour? What problem was the PSIC solving when it was introduced that warrants tolerating the prompts?!

@corbob
Thanks for the suggestion. Where should the variables be set?

What problem was the PSIC solving when it was introduced that warrants tolerating the prompts?!

Please understand that I don't think this prompt appeared before and doesn't appear on non-Windows which is what I use. This is a 100% community driven product and some things will be missed/bugs will show up since it's very difficult to write proper tests.

That said, @yatli has typically been the one "manually testing by using" on Windows - have you seen this before?

PSIC was introduced to provide an ISE-like experience where you can select a line of code, hit F8 and it will run it in the PSIC below. It was an experience we were trying to align with.

@Praful here's the doc on profiles which should help in understanding what each profile in PowerShell does and when it gets run.

@TylerLeonhardt sorry - I didn't mean to sound critical but rather understand the rationale behind the feature. I'm not an ISE user but it's reasonable to emulate some of its features. I like the sound of the F8 command.

@Praful here's the doc on profiles which should help in understanding what each profile in PowerShell does and when it gets run.

I read this when @corbob mentioned the $profile NoteProperty types. However, I couldn't see anywhere to set them. In the PSIC none of the four $profile member properties refer to the default Windows profile. So I tried calling my Windows PS profile from coc.vim_profile.ps1 without any joy. I may have made a mistake and will try later.

coc.nvim uses different mechanisms for vim and nvim, to start terminals -- jobs for vim specifically.

I've just tested with gvim.exe and here's what happens on :q:
image

Here's :bd:
image

@TylerLeonhardt in addition to activate, we need to tear down the language service with a deactivate method. That's the place where we should destroy the terminal (and thus the job).

That said, it's still a bit strange to have to tear down a shell when the last .ps1 buffer is gone..

@Praful no worries! The $profile paths are just file paths so what I would recommend is opening the file that $PROFILE.CurrentUserAllHosts gives you and put the code that you want to run for both vim and the normal console in that.

Make sure you comment out the code in the normal console profile so that you don't have the same code running twice!

I've made vim kill the terminal job when window is closed.

@TylerLeonhardt

The $profile paths are just file paths so what I would recommend is opening the file that $PROFILE.CurrentUserAllHosts gives you and put the code that you want to run for both vim and the normal console in that.

Ah, I see. I was trying to change what the variable pointed to. It was as simple as renaming Microsoft.PowerShell_profile.ps1 to profile.ps for all hosts to use the same profile for the current user.

@chemzqm

I've made vim kill the terminal job when window is closed.

Thanks - that's removed the kill job... prompt.

In case you expected otherwise, I still can't :bd the PSIC: the Save changes to "!C:/Program Files/PowerShell/6/pwsh.exe... prompt appears and closing the window it's in (if there are multiple windows open) keeps the PSIC buffer around.