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

Errors that occur when loading profile scripts aren't written to the console #689

Closed
wsmelton opened this issue Apr 19, 2017 · 36 comments
Closed
Milestone

Comments

@wsmelton
Copy link

System Details

  • Operating system name and version: Windows 10 Pro
  • VS Code version: 1.11.2
  • PowerShell extension version: 0.12.2
  • Output from $PSVersionTable:
PS C:\GitHub\dbatools> code -v
1.11.2
6eaebe3b9c70406d67c97779468c324a7a95db0e
PS C:\GitHub\dbatools>
PS C:\GitHub\dbatools> $pseditor.EditorServicesVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
0      12     1      0


PS C:\GitHub\dbatools>
PS C:\GitHub\dbatools> code --list-extensions --show-versions
eamodio.gitlens@3.4.5
gerane.Theme-Blackboard@0.0.2
gerane.Theme-earthsong-light@0.0.2
LaurentTreguier.vscode-simple-icons@1.2.0
michelemelluso.gitignore@1.0.1
ms-mssql.mssql@0.3.0
ms-vscode.PowerShell@0.12.2
ms-vscode.wordcount@0.1.0
RolandGreim.sharecode@0.4.0
sensourceinc.vscode-sql-beautify@0.0.4
Shan.code-settings-sync@2.6.2
swyphcosmo.spellchecker@1.2.13
tinaciousdesign.theme-tinaciousdesign@0.2.4
Tyriar.theme-sapphire@0.1.0
PS C:\GitHub\dbatools>
PS C:\GitHub\dbatools> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.1066
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.1066
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

Running VS Code the initial terminal that is started for PowerShell showing as "1: PowerShell Integrated Console" does not load my user profile. This is with powershell.enableProfileLoading set to true.

Although if I start a new terminal for PowerShell I can see that my profile does get loaded.

Attached Logs

Logs.zip

@daviwil
Copy link
Contributor

daviwil commented Apr 19, 2017

We use a different profile for VS Code: Microsoft.VSCode_profile.ps1.

@wsmelton
Copy link
Author

wsmelton commented Apr 19, 2017

So it never acknowledges this setting??

  // Loads user and system-wide PowerShell profiles (profile.ps1 and Microsoft.VSCode_profile.ps1) 
into the PowerShell session. This affects IntelliSense and interactive script execution, 
but it does not affect the debugger.
  "powershell.enableProfileLoading": true,

@daviwil
Copy link
Contributor

daviwil commented Apr 19, 2017

Sorry, my answer was too brief. Which specific profile script are you expecting it to load? My assumption was that you expect Microsoft.PowerShell_profile.ps1 to be loaded since that's the one that's used in powershell.exe. The "PowerShell Integrated Console" loads Microsoft.VSCode_profile.ps1 because it's a different PowerShell host than the one in powershell.exe

@wsmelton
Copy link
Author

I expected it to load my profile.ps1 just as PowerShell.exe does. If it is not going to I will just disable that console because I have no reason to keep up with 2 copies of my profile.

@wsmelton
Copy link
Author

Which I guess is another issue to submit the ability to disable the integrated console.

@daviwil
Copy link
Contributor

daviwil commented Apr 19, 2017

You can prevent the console from appearing on startup with this setting: "powershell.integratedConsole.showOnStartup": false,. However, if profile.ps1 is not being loaded, that's probably a bug. I'll investigate to fix this for the next update.

@daviwil daviwil changed the title Integrated Terminal does not seem to load profile Integrated Console does not load profile.ps1 Apr 19, 2017
@daviwil daviwil added this to the April 2017 milestone Apr 19, 2017
@wsmelton
Copy link
Author

Well I'd prefer to have the full PowerShell.exe as my terminal. Running modules and commands via the integrated console give different results compared to the same being done in PowerShell.exe. (e.g. Import-Module dbatools).

@daviwil
Copy link
Contributor

daviwil commented Apr 19, 2017

If it's purely a matter of preference, that's totally understandable. However, I'd like to make the Integrated Console as compatible as I can. Could you briefly tell me what gaps you see?

@wsmelton
Copy link
Author

  1. Custom types in modules (mostly dbatools) will error and not load in the integrated console. [However, trying this just now it seems to have stopped...not sure where this was fixed.]
  2. Certain times the output will jump around the cursor. Meaning when I have multiple lines of output of say 10 lines. The 10 lines will output but the cursor will show up at line 8 of the 10, hit enter and it will reset or refresh to show below that output. If I get it to happen again I will try to show screenshot of it.

@daviwil
Copy link
Contributor

daviwil commented Apr 19, 2017

Keep an eye out for the custom types one and let me know if you see it again. That shouldn't be happening so I'd like to fix it if I'm causing it somehow. The cursor issues will be resolved in the very near future before we hit 1.0. They're pretty annoying!

Thanks for the feedback!

@wsmelton
Copy link
Author

wsmelton commented Apr 28, 2017

Here is an example of format (not necessarily cursor). I added the vscode profile and all it does is Import-Module posh-git:
image

Hitting enter will bring the format back to normal.

@daviwil
Copy link
Contributor

daviwil commented Apr 28, 2017

Ahhh, are you using Windows 10 Creators Update? There are some general issues with VS Code's integrated terminal in Creator's Update caused by some changes in the Windows console host.

@wsmelton
Copy link
Author

"Creators update"? Don't think so, I do not have Windows 10 set to the fast track or anything. I'm on Windows 10.0.14393.

@daviwil daviwil modified the milestones: April 2017, May 2017 May 8, 2017
@lipkau
Copy link
Contributor

lipkau commented May 15, 2017

I have the same problem.
I am on Anniversary Update (BuildVersion 10.0.14393.953).
My profile script: "\\mydomain.com\shareName\Lipkau\Documents\WindowsPowerShell\profile.ps1"
image
image

@daviwil daviwil added the Issue-Bug A bug to squash. label May 15, 2017
@daviwil daviwil modified the milestones: 1.1.0, May 2017 May 15, 2017
@daviwil
Copy link
Contributor

daviwil commented May 15, 2017

I'll take a look at this for the next update.

@lipkau
Copy link
Contributor

lipkau commented May 16, 2017

I retract my comment.
It was an error in my profile. I apologize.

@daviwil
Copy link
Contributor

daviwil commented May 17, 2017

Hey Shawn, it turns out that errors that occur while loading your profile script aren't currently being written to the console. I can confirm that profile.ps1 does get loaded so you've probably just got an error in that profile that isn't showing up in the console. I'm fixing the error writing issue for tomorrow's update.

@daviwil daviwil changed the title Integrated Console does not load profile.ps1 Errors that occur when loading profile scripts aren't written to the console May 17, 2017
daviwil added a commit to daviwil/PowerShellEditorServices that referenced this issue May 17, 2017
This change causes both errors and object output to be written to the
host when profiles are being loaded.  Users who had issues in their
profile scripts thought that the scripts weren't being loaded when in
fact there were errors not being displayed.  Also, users using
Write-Output in their profile scripts did not see that output.  This
change makes the PSES host consistent with the PowerShell ConsoleHost,
writing both forms of output when loading profile scripts.

Resolves PowerShell/vscode-powershell#689
Resolves PowerShell/vscode-powershell#663
daviwil added a commit to PowerShell/PowerShellEditorServices that referenced this issue May 17, 2017
This change causes both errors and object output to be written to the
host when profiles are being loaded.  Users who had issues in their
profile scripts thought that the scripts weren't being loaded when in
fact there were errors not being displayed.  Also, users using
Write-Output in their profile scripts did not see that output.  This
change makes the PSES host consistent with the PowerShell ConsoleHost,
writing both forms of output when loading profile scripts.

Resolves PowerShell/vscode-powershell#689
Resolves PowerShell/vscode-powershell#663
@Jaykul
Copy link

Jaykul commented May 17, 2017

The problem is that this host is missing a lot of things that the normal console host has, like the color settings in $Host.PrivateData, so profiles that work fine in ConHost (or even ISE) don't necessarily work fine here.

@daviwil
Copy link
Contributor

daviwil commented May 17, 2017

Yep, that's what I'm guessing. Getting the errors to display is the first step in figuring out what people are doing that isn't supported here yet. I'll see if I can get the PrivateData support added in the next release or two.

@wsmelton
Copy link
Author

My profile.ps1 has no errors in it. PowerShell.exe would show those if it did when loading it (outside of VS Code), and it loads cleanly.

@wsmelton
Copy link
Author

My exact profile on my local machine if you want something to test with...

Microsoft.PowerShell_profile - Copy.txt

@rkeithhill
Copy link
Contributor

rkeithhill commented May 18, 2017

@wsmelton Just to be sure, check $Error right after the integrated console comes up.

@wsmelton
Copy link
Author

wsmelton commented May 18, 2017

All clear.

image

@wsmelton
Copy link
Author

wsmelton commented Jun 5, 2017

This is still an issue with my profile not loading into the integrated terminal. Is that going to be fixed or I just need to use the PowerShell.exe terminal? None of the functions I have in my main profile are being loaded.

@daviwil
Copy link
Contributor

daviwil commented Jun 5, 2017

Do you see any errors written to the console when it loads? I have a high degree of certainty that there's an error in your profile script that prevents it from completing.

@daviwil
Copy link
Contributor

daviwil commented Jun 5, 2017

Also check the $Errors variable to see if anything is there

@wsmelton
Copy link
Author

wsmelton commented Jun 5, 2017

None. It loads fine for PowerShell.exe terminal with no errors so can't be my profile.

@daviwil
Copy link
Contributor

daviwil commented Jun 5, 2017

By the way, I noticed in an earlier comment that you pasted your Microsoft.PowerShell_profile.ps1 file. As I mentioned before, we use Microsoft.VSCode_profile.ps1. Do you have one of those? What are its contents?

@daviwil
Copy link
Contributor

daviwil commented Jun 5, 2017

Also, what's in your profile.ps1 file?

@daviwil
Copy link
Contributor

daviwil commented Jun 5, 2017

It just occurred to me after looking at your Microsoft.PowerShell_profile.txt that the functions you expect to exist aren't being loaded in your profile.ps1 anyway. I'd recommend one of two options:

  1. Move the contents of your Microsoft.PowerShell_profile.ps1 to a file in the same folder called profile.ps1
  2. Create a new file in the same folder called Microsoft.VSCode_profile.ps1 and put this in it:
. (Join-Path -Path (Split-Path $profile) -ChildPath Microsoft.PowerShell_profile.ps1)

@wsmelton
Copy link
Author

wsmelton commented Jun 5, 2017

I'll just continue using PowerShell.exe terminal. I'm not going to keep up with 2 seperate profiles.

@daviwil
Copy link
Contributor

daviwil commented Jun 5, 2017

Using my second recommendation, you won't have to. But do whatever you like :)

@xiddix
Copy link

xiddix commented Jun 29, 2017

Thanks! Redirecting the VSCode_profile to also load my Powershell_profile is exactly what I was looking for and works fine for me. One line of code to maintain. I prefer the separation so that if there are any debugging preferences that I want to add in the integrated profile, it doesn't affect my main shell. Nice!

@cassta
Copy link

cassta commented Jul 4, 2017

Hello, I'm still a bit confused. Was searching for couple of days to get better understanding how does the VSCode Powershell extension handles profiles and finally got to this thread. My understanding from the description of setting "powershell.enableProfileLoading": true is that it should also handle system wide profiles. Nevertheless I do not have available any other profile than the one for "AllUsersAllHosts". And it doesn't get loaded for sure. How can I change VSCode Powershell Extension behavior to take this profile into account?

@daviwil
Copy link
Contributor

daviwil commented Jul 5, 2017

@cassta can you capture Verbose logs and attach them here? Instructions: https://github.com/PowerShell/vscode-powershell#2-capture-verbose-logs-and-send-them-to-us

@cassta
Copy link

cassta commented Jul 7, 2017

@daviwil, I'm sorry, my bad. Not sure why I didn't realize it earlier, but as I use by default 64-bit version of Powershell I simply missed that VSCode is "just" 32-bit application, therefore working with profiles in SYSWOW64. Once profile was replicated to expected location everything started to work fine. Sorry for any inconvenience caused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants