From 391e54ae4fe64ebc1af4148b98e5b04ec87efd9d Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 21 Mar 2017 12:27:27 -0700 Subject: [PATCH] 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. --- src/features/RemoteFiles.ts | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/features/RemoteFiles.ts b/src/features/RemoteFiles.ts index fbe164a5b6..854824260f 100644 --- a/src/features/RemoteFiles.ts +++ b/src/features/RemoteFiles.ts @@ -6,11 +6,27 @@ import os = require('os'); import path = require('path'); import vscode = require('vscode'); import { IFeature } from '../feature'; -import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient'; +import { LanguageClient, RequestType, NotificationType, TextDocumentIdentifier } from 'vscode-languageclient'; + +// NOTE: The following two DidSaveTextDocument* types will +// be removed when #593 gets fixed. + +export interface DidSaveTextDocumentParams { + /** + * The document that was closed. + */ + textDocument: TextDocumentIdentifier; +} + +export namespace DidSaveTextDocumentNotification { + export const type: NotificationType = + { get method() { return 'textDocument/didSave'; } } +} export class RemoteFilesFeature implements IFeature { private tempSessionPathPrefix: string; + private languageClient: LanguageClient; constructor() { // Get the common PowerShell Editor Services temporary file path @@ -22,18 +38,19 @@ export class RemoteFilesFeature implements IFeature { // At startup, close any lingering temporary remote files this.closeRemoteFiles(); - // TEMPORARY: Register for the onDidSave event so that we can alert - // the user when they attempt to save a remote file. We don't - // currently propagate saved content back to the remote session. vscode.workspace.onDidSaveTextDocument(doc => { - if (this.isDocumentRemote(doc)) { - vscode.window.showWarningMessage( - "Changes to remote files are not yet saved back in the remote session, coming in 0.10.0."); + if (this.languageClient && this.isDocumentRemote(doc)) { + this.languageClient.sendNotification( + DidSaveTextDocumentNotification.type, + { + textDocument: TextDocumentIdentifier.create(doc.uri.toString()) + }); } }) } public setLanguageClient(languageclient: LanguageClient) { + this.languageClient = languageclient; } public dispose() {