PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.67k stars 478 forks source link

Remote editing only works for .ps1 files but not others #2166

Open OnurGumus opened 4 years ago

OnurGumus commented 4 years ago

When I follow this documentation https://docs.microsoft.com/en-us/powershell/scripting/components/vscode/using-vscode-for-remote-editing-and-debugging?view=powershell-6

I noticed remote editing only works for .ps1 files. For other extensions, you can save the file but it won't sync back to the server. I am using PowerShell v7 preview 3 for both host and server and both host and server are windows machines along with Latest VSCode and Powershell extension

A relevant issue has been earlier reported but closed: https://github.com/PowerShell/vscode-powershell/issues/1040

SydneyhSmith commented 4 years ago

@OnurGumus thanks for opening this issue...It would be really helpful if you could also attach the logs--instructions for how to do that are here , please also provide repro steps, as well as a detailed description of the behavior you are experiencing...thanks!

OnurGumus commented 4 years ago

@SydneyhSmith all repo steps has been clearly stated in the opening issue. If you actually spend 2 minutes and read what I wrote, you will understand the problem. I am not intended to provide further info regarding how to reproduce and loggings as the issue and repro steps are crystal clear.

TylerLeonhardt commented 4 years ago

@OnurGumus I just followed the steps, and the file saves as expected.

before: image

after I added a line in the editor: image

We need the logs because something might be specific to your system. Please provide those and also what OS's you're using.

Also, do you have access to the file you're trying to save?

OnurGumus commented 4 years ago

@TylerLeonhardt, if you read the issue carefully, it clearly states both server and client are windows machines. In your case you are using Linux.

To be specific client is latest windows 10 pro rtm X64 and server is windows server 2019 standard edition 1809.

I am creating the file with new item. Saving only works when the extension is ps1. Also you use a different command than the linked tutorial as new-editor-file whereas I am using psedit, not sure if it makes any difference.

OnurGumus commented 4 years ago

I will provide the logs once I have access to my computer.

TylerLeonhardt commented 4 years ago

Missed the part about Windows. My bad. Just for future reference, we have an issue template so that we don't miss these details the first time around. It just streamlines the process.

New-EditorFile creates a file and opens it in vscode. It's the equivalent to New-Item and then psedit (which is an alias of Open-EditorFile).

I still need to know - what communication protocol are you using? ssh or winrm?

OnurGumus commented 4 years ago

It's winrm. I agree that my writing style makes those details less visible. But I thought your template was really overwhelming since it was easy to repro from my point of view.

SydneyhSmith commented 4 years ago

@OnurGumus we will try to stand up an environment similar to yours and repro this...in the meantime it would still be helpful to see your logs--thanks!

centreboard commented 4 years ago

Hi, I'm having the same issue from Windows 10 PC to Windows Server Reproduced both with 6.2 and 7-preview3

My prompt and logs attached

[npe-file-01]: PS C:\Users\majohnson_admin\Documents> "Test" > test.ps1
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> Get-Content test.ps1
Test
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> psedit test.ps1
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> Get-Content test.ps1
Edited
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> "Test" > test.txt
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> Get-Content test.txt
Test
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> psedit test.txt
[npe-file-01]: PS C:\Users\majohnson_admin\Documents> Get-Content test.txt
Test
[npe-file-01]: PS C:\Users\majohnson_admin\Documents>

1568362690-2cf65ee5-9dce-4f0e-b10e-421124476b0e1568360608478.zip

ghost commented 4 years ago

This issue is being closed as inactive, if this issue is still occurring it will be re-opened

centreboard commented 4 years ago

@SydneyhSmith I'm still having this issue. Let me know if you need any further information

mkarpuk commented 4 years ago

Faced the same issue today (Windows 10 with Powershell 5). Is any additional information required? (This issue is still labelled as 'Needs-Repro-Info')

OnurGumus commented 4 years ago

@SydneyhSmith may I ask why you remove Needs:Attention?

TylerLeonhardt commented 4 years ago

The "Needs: Attention" label is only applied if someone said something after we have:

We acknowledge this bug (it's still open and has the Issue-Bug label) but we haven't made progress on it yet to report anything back. It's not the highest priority issue compared to others but when we have resources to spend some time in this space I promise to give an update.

We removed that label because we have nothing to report back or add to the conversation.

OnurGumus commented 4 years ago

@TylerLeonhardt it's you to decide the priorities but allow me to explain the impact of this. Right now it's impossible to edit a remote file through powershell remoting by any means from windows to windows. Sounds pretty serious to me.

rjmholt commented 4 years ago

I've been looking into this this week, but haven't been able to reproduce any issues remoting into Windows PowerShell 5.1 on Windows Server 2016 or 2019, from PowerShell 5.1 or 7. One example:

psedit

@OnurGumus, @centreboard, @mkarpuk, @dylan-azucena would you be able to share the following details of your setup please:

To get the OS name and version, try:

systeminfo | select -first 2 -skip 2

which should have an output like:

OS Name:                   Microsoft Windows Server 2019 Datacenter
OS Version:                10.0.17763 N/A Build 17763

To get the PowerShell version, try $PSVersionTable.

dylan-azucena commented 4 years ago

@rjmholt I'm no longer seeing the issue, I attempted your test and was able to remotely edit a txt file and save it successfully.

FWIW:

Remoting From

OS: macos Catalina (10.15.2) PS: 6.2.3 Core

Remoting To

OS: Microsoft Windows Server 2016 Datacenter (10.0.14393 N/A Build 14393) PS: 5.1.14393.3053 Desktop

Command

Enter-PSSession -ComputerName $server -Credential $admin -Authentication basic -UseSSL -SessionOption $pso

rjmholt commented 4 years ago

I've just tested this remoting over SSH from PS 7-rc.1 to 6.2.3 and PS 7 to 7 and was able to save the file like in the GIF above.

Hopefully we can collect more information to determine what might be causing this on some systems.

OnurGumus commented 4 years ago

@rjmholt what is your source operating system?

OnurGumus commented 4 years ago

@dylan-azucena you are trying from Mac. The issue is from windows to windows.

The problem still exists by the way. I have just tested today: Source OS : windows 10 x64 1903, Powershell 7.0 rc1 Target OS : Windows 2019 x64 Standard edition 1809

rjmholt commented 4 years ago

@OnurGumus

Target OS : Windows 2019 x64 Standard edition 1809

Could you specify the version of PowerShell you're trying to remote into and the remoting command you're using to do it?

rjmholt commented 4 years ago

@rjmholt what is your source operating system?

OS Name:                   Microsoft Windows 10 Enterprise Insider Preview
OS Version:                10.0.19535 N/A Build 19535
OnurGumus commented 4 years ago

@rjmholt Source:

PowerShell 7.0.0-rc.1
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/powershell
Type 'help' to get help.

PS C:\Users\Onur.Gumus>  systeminfo | select -first 2 -skip 2
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.18363 N/A Build 18363

Target:

PowerShell 7.0.0-rc.1
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/powershell
Type 'help' to get help.

PS C:\Users\gatesdev>  systeminfo | select -first 2 -skip 2
OS Name:                   Microsoft Windows Server 2019 Standard
OS Version:                10.0.17763 N/A Build 17763
rjmholt commented 4 years ago

@OnurGumus are you remoting with a command like this:

$s = New-PSSession -HostName $ipAddress -Credential $credential
Enter-PSSession $s

Or are you using a different command (perhaps WSMan-based?)

rjmholt commented 4 years ago

For my own reference, this is the relevant code path:

OnurGumus commented 4 years ago

@rjmholt I am not using SSH. I am using this

Enter-PSSession -ComputerName  $ipAddress -Credential $credential
rjmholt commented 4 years ago

@centreboard looking through your logs I see the following notifications (in chronological order) about test.txt:

2019-09-13 09:19:59.634 [VERBOSE] tid:5 in 'ExecuteCommand' C:\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: line 492
    Attempting to execute command(s):

        "Test" > test.txt
        Out-Default
2019-09-13 09:20:08.430 [VERBOSE] tid:27 in 'ExecuteCommand' C:\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: line 492
    Attempting to execute command(s):

        Get-Content test.txt
        Out-Default
2019-09-13 09:20:12.909 [VERBOSE] tid:7 in 'ExecuteCommand' C:\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: line 492
    Attempting to execute command(s):

        psedit test.txt
        Out-Default
2019-09-13 09:20:12.977 [VERBOSE] tid:6 in 'WriteMessage' C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs: line 88
    Writing Request 'editor/openFile' with id 2

    {
      "jsonrpc": "2.0",
      "id": "2",
      "method": "editor/openFile",
      "params": {
        "filePath": "C:\\Users\\majohnson\\AppData\\Local\\Temp\\PSES-3636\\RemoteFiles\\964015699\\NPE-FILE-01\\test.txt",
        "preview": true
      }
    }
2019-09-13 09:20:23.631 [VERBOSE] tid:27 in 'ExecuteCommand' C:\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs: line 492
    Attempting to execute command(s):

        Get-Content test.txt
        Out-Default
2019-09-13 09:20:25.797 [VERBOSE] tid:7 in 'WriteMessage' C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageWriter.cs: line 88
    Writing Request 'editor/closeFile' with id 4

    {
      "jsonrpc": "2.0",
      "id": "4",
      "method": "editor/closeFile",
      "params": "C:\\Users\\majohnson\\AppData\\Local\\Temp\\PSES-3636\\RemoteFiles\\964015699\\NPE-FILE-01\\test.txt"
    }

There doesn't seem to be a textDocument/saveFile notification for test.txt in the logs, only test.ps1. That notification is something that VSCode (not the PowerShell extension) sends when you save a file.

Given that information, it might be worth making sure your VSCode version is up to date and trying to reproduce the issue with the following steps (or let me know if you used different steps):

If the problem persists, please upload your logs again so we can take a look. If you could also capture a GIF of what's happening, that would be ideal.

rjmholt commented 4 years ago

@OnurGumus

I am using this

Enter-PSSession -ComputerName $ipAddress -Credential $credential

Are you using a -ConfigurationName? Without that parameter, you will remote into Windows PowerShell 5.1.

In either case, I've followed the remote file editing steps over WSMan from 7-rc.1 both without a configuration name (remoting into 5.1) and with a configuration name (remoting into 7-rc.1), but haven't yet been able to reproduce the issue:

remoteedit

It might be worth seeing if there's anything recorded in the logs that helps. If you're using the preview extension, you'll need to grab the payload logs to catch the messages.

OnurGumus commented 4 years ago

@rjmholt Thanks for the effort. I was not using -ConfigurationName. When I tried below

Enter-PSSession -ComputerName 192.168.63.25 -Credential gatesdev -ConfigurationName 'Powershell.7'

Enter-PSSession: Connecting to remote server 192.168.63.25 failed with the following error message : The WS-Management service cannot process the request. Cannot find the Powershell.7 session configuration in the WSMan: drive on the 192.168.63.25 computer. For more information, see the about_Remote_Troubleshooting Help topic.
OnurGumus commented 4 years ago

@rjmholt could it be because I set the remoting long time ago against powershell 6?

rjmholt commented 4 years ago

@rjmholt could it be because I set the remoting long time ago against powershell 6?

Very possible. It depends on whether you've enabled WSMan-based remoting on PowerShell installation.

To set up WSMan-based remoting in PowerShell 6/7, you can follow this document.

If you set it up for PowerShell 6, the configuration name you want might be powershell.6.0.0. But the easiest way to make sure is to just set up remoting again from the PowerShell you want to remote into using the steps in the document linked above.

None of that explains why you're unable to save the file though. The issue you linked in the original description is quite old, but the code referenced is in the client here:

https://github.com/PowerShell/vscode-powershell/blob/32c96233889adc0c49d51910e20955812b39fd98/src/features/RemoteFiles.ts#L40-L49

If you open a remote file for editing again, would you be able to share the path of the local temp file it creates? I wonder if this is a URI internationalisation issue...

SydneyhSmith commented 4 years ago

@OnurGumus yesterday we published an update which fixed some of the URI issues we had been seeing, are you able to test this on the latest version of the PowerShell Preview extension (2020.1.0)

centreboard commented 4 years ago

@rjmholt Thanks for looking through,

@centreboard looking through your logs I see the following notifications (in chronological order) about test.txt:

There doesn't seem to be a textDocument/saveFile notification for test.txt in the logs, only test.ps1. That notification is something that VSCode (not the PowerShell extension) sends when you save a file.

Given that information, it might be worth making sure your VSCode version is up to date and trying to reproduce the issue with the following steps (or let me know if you used different steps):

  • Open the Integrated Console
  • Enter a PSSession on the remote machine
  • Create a file with PowerShell (like New-Item ./test.txt -Value 'Test')
  • Edit the file in VSCode with psedit
  • Save the file from VSCode (as you would an ordinary local file)
  • Check the content of the file from PowerShell (e.g. with Get-Content ./test.txt)

If the problem persists, please upload your logs again so we can take a look. If you could also capture a GIF of what's happening, that would be ideal.

Those steps are correct. I can still reproduce with test.ps1 being saved to the server and test.txt not. I've checked VSCode is on 1.41.1 using ms-vscode.powershell 2020.1.0 I'm running Windows 10 (1809) using Powershell 7-rc2

OS Name: Microsoft Windows 10 Enterprise OS Version: 10.0.17763 N/A Build 17763

I'm using Enter-PSSession -ComputerName $computer -Credential $credential to Windows Server 2016 running Powershell 5.1.14393.3383

OS Name: Microsoft Windows Server 2016 Standard OS Version: 10.0.14393 N/A Build 14393

Any tips on recording a GIF on an enterprise machine? I'll generate some more logs next week

rjmholt commented 4 years ago

Any tips on recording a GIF on an enterprise machine

I use this to record gifs, although I think some other contributors have something better that records keyboard input. Alternately, I think Alt+Shift+R will record the screen on Windows, but you'll then have to convert it from mp4 to gif if you want to upload it directly to a GitHub comment.

Looking again at your logs, the path to the temp file seems like it's only got ASCII characters in it, so URI issue seems less likely. I also thought it could be a permissions issue with the temp directory used for local files, but that wouldn't account for ps1 files working.

I'll see if I can dig through the codebase to find something that might explain the symptoms.

centreboard commented 4 years ago

@rjmholt I've attached a gif of trying psedit test.txt The logs should also show the successful psedit test.ps1 psedit_txt 1580118535-4bfb4a3d-47b1-4a15-a6a2-3fb446c2e98d1580118522765.zip

(I've also double checked that running "Edit" > test.txt in the remote session does change the content of test.txt)

TylerLeonhardt commented 4 years ago

That path has a negative number... very curious... that gif is SUPER helpful, thanks @centreboard!!

rjmholt commented 4 years ago

That path has a negative number

Reading the previous logs though, that doesn't seem to be a common factor

TylerLeonhardt commented 4 years ago

@centreboard after you save the file the first time in VS Code, can you Get-Content the temp file path? I'm curious if the temp file is being saved correctly. You can see the temp file path just below the tab in VS Code.

rjmholt commented 4 years ago

I'm also still wondering why VSCode wouldn't send us a didSave notification. Given that @centreboard is on 1.41.1, it seems unlikely that it's a bug in that VSCode version.

It could be a configuration thing maybe, so maybe we should take a look at the configuration settings?

Otherwise, it might be worth seeing if we can trace a save in VSCode. That should be possible by starting VSCode with trace logging and inspecting the logs here.

From there we'd expect to see log entries beginning with [text file model].

centreboard commented 4 years ago

@TylerLeonhardt I can confirm that test.ps1 as an identical folder path with a negative id to test.txt when opended with psedit @rjmholt I've run code --log trace and reproduced again: 20200128T094922.zip

rjmholt commented 4 years ago

The VSCode logs I was hoping for aren't in that zip it seems. Their documentation on logging might be lacking.

I'm going to try firing up an RS3 VM to see if I can get a reproduction in a more faithful environment.

rjmholt commented 4 years ago

Ok I haven't been able to reproduce remoting from:

OS Name:                   Microsoft Windows 10 Enterprise
OS Version:                10.0.17763 N/A Build 17763

to:

OS Name:                   Microsoft Windows Server 2016 Datacenter
OS Version:                10.0.14393 N/A Build 1439

At this point, if I find time, I'll see if I can read through the code and see where code paths for PS and non-PS files diverge for some clues.

keithallenjackson commented 4 years ago

I am having this same issue. It also appears the autocomplete is unaware that I am in a remote session and continually autocompletes to the folder I was previously in before entering a remote session. I am on the latest version of VSCode and the powershell extension. My system uses Powershell 5.1. I am using WinRM with Enter-PSSession cmdlet.

Client: VSCode 1.45 Powershell Extension 2020.4.0 OS: Windows 10 x64 1809

Server: Windows Server 2012 R2

My initial though after reading through this thread: Perhaps the extension is only receiving saveFile notifications on file extensions associated with the powershell vscode extension (ps1, psm1, psd1, etc)?

keithallenjackson commented 4 years ago

Looks like the file is being saved in a temporary location, but then never sent to the remote system.

image

rjmholt commented 4 years ago

@keithallenjackson

Perhaps the extension is only receiving saveFile notifications on file extensions associated with the powershell vscode extension (ps1, psm1, psd1, etc)?

That's what it seemed to look like in https://github.com/PowerShell/vscode-powershell/issues/2166#issuecomment-575010493.

However if the file you're seeing in https://github.com/PowerShell/vscode-powershell/issues/2166#issuecomment-628650383 is up to date, then that suggests that the save notification isn't the issue. Instead, it may occur somewhere around here.

rjmholt commented 4 years ago

I think some important factors in this so far are:

ghost commented 2 years ago

This issue was closed automatically as repro info was indicated as needed, but there has been no activity in over a week. Please feel free to reopen with any available information!

andyleejordan commented 2 years ago

This seems like it actually did have repro info (and indeed, is a very long issue). Re-opening and removing that label.

p-rogalski commented 2 weeks ago

Any news on this bug? It's really annoying to rename every file to *.ps1 just to edit it.

This get's more important every day, since PowerShell ISE is deprecated and the PowerShell VS Code extension is advertised as a fully featured replacement!