Skip to content

Add "remote files" feature that handles files from remote sessions #438

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
Jan 17, 2017
Merged
Show file tree
Hide file tree
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
67 changes: 67 additions & 0 deletions src/features/RemoteFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import os = require('os');
import path = require('path');
import vscode = require('vscode');
import { IFeature } from '../feature';
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';

export class RemoteFilesFeature implements IFeature {

private tempSessionPathPrefix: string;

constructor() {
// Get the common PowerShell Editor Services temporary file path
// so that remote files from previous sessions can be closed.
this.tempSessionPathPrefix =
path.join(os.tmpdir(), 'PSES-')
.toLowerCase();

// 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.");
}
})
}

public setLanguageClient(languageclient: LanguageClient) {
}

public dispose() {
// Close any leftover remote files before exiting
this.closeRemoteFiles();
}

private isDocumentRemote(doc: vscode.TextDocument) {
return doc.languageId === "powershell" &&
doc.fileName.toLowerCase().startsWith(this.tempSessionPathPrefix);
}

private closeRemoteFiles() {
var remoteDocuments =
vscode.workspace.textDocuments.filter(
doc => this.isDocumentRemote(doc));

function innerCloseFiles(): Thenable<{}> {
if (remoteDocuments.length > 0) {
var doc = remoteDocuments.pop();

return vscode.window
.showTextDocument(doc)
.then(editor => vscode.commands.executeCommand("workbench.action.closeActiveEditor"))
.then(_ => innerCloseFiles());
}
};

innerCloseFiles();
}
}
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { OpenInISEFeature } from './features/OpenInISE';
import { ExpandAliasFeature } from './features/ExpandAlias';
import { ShowHelpFeature } from './features/ShowOnlineHelp';
import { CodeActionsFeature } from './features/CodeActions';
import { RemoteFilesFeature } from './features/RemoteFiles';
import { DebugSessionFeature } from './features/DebugSession';
import { PickPSHostProcessFeature } from './features/DebugSession';
import { SelectPSSARulesFeature } from './features/SelectPSSARules';
Expand Down Expand Up @@ -106,6 +107,7 @@ export function activate(context: vscode.ExtensionContext): void {
new CodeActionsFeature(),
new NewFileOrProjectFeature(),
new DocumentFormatterFeature(),
new RemoteFilesFeature(),
new DebugSessionFeature(),
new PickPSHostProcessFeature()
];
Expand Down