Skip to content

Commit 391e54a

Browse files
committed
Enable saving remote files opened with psedit
This change enables the saving of files opened from a remote session using the psedit command. When the editor saves the file contents it sends a DidSaveTextDocumentNotification to the language server which in turn sends the document's contents back to the remote session to be saved in the original file. Resolves #583.
1 parent 635a1bb commit 391e54a

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

Diff for: src/features/RemoteFiles.ts

+24-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,27 @@ import os = require('os');
66
import path = require('path');
77
import vscode = require('vscode');
88
import { IFeature } from '../feature';
9-
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';
9+
import { LanguageClient, RequestType, NotificationType, TextDocumentIdentifier } from 'vscode-languageclient';
10+
11+
// NOTE: The following two DidSaveTextDocument* types will
12+
// be removed when #593 gets fixed.
13+
14+
export interface DidSaveTextDocumentParams {
15+
/**
16+
* The document that was closed.
17+
*/
18+
textDocument: TextDocumentIdentifier;
19+
}
20+
21+
export namespace DidSaveTextDocumentNotification {
22+
export const type: NotificationType<DidSaveTextDocumentParams> =
23+
{ get method() { return 'textDocument/didSave'; } }
24+
}
1025

1126
export class RemoteFilesFeature implements IFeature {
1227

1328
private tempSessionPathPrefix: string;
29+
private languageClient: LanguageClient;
1430

1531
constructor() {
1632
// Get the common PowerShell Editor Services temporary file path
@@ -22,18 +38,19 @@ export class RemoteFilesFeature implements IFeature {
2238
// At startup, close any lingering temporary remote files
2339
this.closeRemoteFiles();
2440

25-
// TEMPORARY: Register for the onDidSave event so that we can alert
26-
// the user when they attempt to save a remote file. We don't
27-
// currently propagate saved content back to the remote session.
2841
vscode.workspace.onDidSaveTextDocument(doc => {
29-
if (this.isDocumentRemote(doc)) {
30-
vscode.window.showWarningMessage(
31-
"Changes to remote files are not yet saved back in the remote session, coming in 0.10.0.");
42+
if (this.languageClient && this.isDocumentRemote(doc)) {
43+
this.languageClient.sendNotification(
44+
DidSaveTextDocumentNotification.type,
45+
{
46+
textDocument: TextDocumentIdentifier.create(doc.uri.toString())
47+
});
3248
}
3349
})
3450
}
3551

3652
public setLanguageClient(languageclient: LanguageClient) {
53+
this.languageClient = languageclient;
3754
}
3855

3956
public dispose() {

0 commit comments

Comments
 (0)