Skip to content

Enable saving remote files opened with psedit #597

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

Merged
merged 1 commit into from
Mar 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/features/RemoteFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DidSaveTextDocumentParams> =
{ 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
Expand All @@ -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() {
Expand Down