-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathRemoteFiles.ts
67 lines (54 loc) · 2.34 KB
/
RemoteFiles.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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();
}
}