Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 21, 2025

Implementing better PowerShell version logging for activation debugging as requested in issue #706.

The issue stems from the PR review comment (#693 (comment)) suggesting that logging PowerShell version information would be valuable for debugging activation failures, especially given the differences between Windows PowerShell 5.x and PowerShell 7+.

Changes Made:

  • Analyze current PowerShell activation flow in pwshStartup.ts and pwshEnvs.ts
  • Examine existing logging patterns and utilities
  • Test current build/compile state of project
  • Create utility function to detect PowerShell version via $PSVersionTable.PSVersion.Major
  • Add PowerShell version logging to relevant activation code paths
  • Add version logging for both conda and non-conda activation scenarios
  • Ensure logging follows existing patterns (traceInfo/traceVerbose)
  • Test changes and verify proper logging output
  • Use shorter -c flag instead of -Command for PowerShell commands

Implementation Details:

  1. Added getPowerShellVersion() function - Detects PowerShell major version using $PSVersionTable.PSVersion.Major command with -c flag
  2. Enhanced installation logging - Now logs PowerShell version when shells are detected (e.g., "SHELL: pwsh is installed (version 7)")
  3. Enhanced activation script error messages - PowerShell errors now include version info (e.g., "Failed to activate Python environment (PowerShell 7): error details")

Testing:

  • All existing unit tests pass (128 passing)
  • Code compiles successfully with no lint errors
  • Manual testing confirms PowerShell version detection works correctly

These changes provide better diagnostic information for debugging PowerShell activation issues without affecting existing functionality.

Fixes #706.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Leave better logs for pwsh version for activation Add PowerShell version logging for activation debugging Sep 21, 2025
Copilot AI requested a review from eleanorjboyd September 21, 2025 21:51
@eleanorjboyd
Copy link
Member

@anthonykim1 was this what you were looking for in terms of logging? And is this the right way to do it? Lgtm but don't know the area as well

@eleanorjboyd eleanorjboyd marked this pull request as ready for review September 21, 2025 22:58
@vs-code-engineering vs-code-engineering bot added this to the September 2025 milestone Sep 21, 2025
@eleanorjboyd eleanorjboyd removed this from the September 2025 milestone Sep 29, 2025
*/
async function getPowerShellVersion(shell: 'powershell' | 'pwsh'): Promise<string | undefined> {
try {
const command = `${shell} -Command "\$PSVersionTable.PSVersion.Major"`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, I think you can even make it pwsh -c '$PSVersionTable.PSVersion.Major'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot follow through on comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Changed to use -c flag in commit 3f8a2b4.

anthonykim1
anthonykim1 previously approved these changes Oct 7, 2025
Changed from -Command to -c as suggested in review.

Co-authored-by: eleanorjboyd <[email protected]>
@vs-code-engineering vs-code-engineering bot added this to the October 2025 milestone Oct 8, 2025
Copilot finished work on behalf of eleanorjboyd October 8, 2025 03:05
@eleanorjboyd eleanorjboyd enabled auto-merge (squash) October 8, 2025 14:45
@eleanorjboyd eleanorjboyd merged commit 1c9601c into main Oct 8, 2025
11 checks passed
@eleanorjboyd eleanorjboyd deleted the copilot/fix-706 branch October 8, 2025 16:36
NguyenCuong1989 referenced this pull request in NguyenCuong1989/vscode-python-environments Oct 23, 2025
Implementing better PowerShell version logging for activation debugging
as requested in issue #706.

The issue stems from the PR review comment
(microsoft/vscode-python-environments#693 (comment))
suggesting that logging PowerShell version information would be valuable
for debugging activation failures, especially given the differences
between Windows PowerShell 5.x and PowerShell 7+.

## Changes Made:
- [x] Analyze current PowerShell activation flow in pwshStartup.ts and
pwshEnvs.ts
- [x] Examine existing logging patterns and utilities
- [x] Test current build/compile state of project
- [x] Create utility function to detect PowerShell version via
`$PSVersionTable.PSVersion.Major`
- [x] Add PowerShell version logging to relevant activation code paths
- [x] Add version logging for both conda and non-conda activation
scenarios
- [x] Ensure logging follows existing patterns (traceInfo/traceVerbose)
- [x] Test changes and verify proper logging output
- [x] Use shorter -c flag instead of -Command for PowerShell commands

## Implementation Details:
1. **Added `getPowerShellVersion()` function** - Detects PowerShell
major version using `$PSVersionTable.PSVersion.Major` command with `-c`
flag
2. **Enhanced installation logging** - Now logs PowerShell version when
shells are detected (e.g., "SHELL: pwsh is installed (version 7)")
3. **Enhanced activation script error messages** - PowerShell errors now
include version info (e.g., "Failed to activate Python environment
(PowerShell 7): error details")

## Testing:
- All existing unit tests pass (128 passing)
- Code compiles successfully with no lint errors
- Manual testing confirms PowerShell version detection works correctly

These changes provide better diagnostic information for debugging
PowerShell activation issues without affecting existing functionality.

Fixes #706.

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 Share your feedback on Copilot coding agent for the chance to win a
$200 gift card! Click
[here](https://survey3.medallia.com/?EAHeSx-AP01bZqG0Ld9QLQ) to start
the survey.

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: eleanorjboyd <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leave better logs for pwsh version for activation

4 participants