Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
More TSLINT warning cleanup
  • Loading branch information
rkeithhill committed Jan 4, 2018
commit ea808b5e683a7ea35cc60bfc917ddfb0641055f1
57 changes: 28 additions & 29 deletions src/features/RemoteFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
* 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, TextDocumentIdentifier } from 'vscode-languageclient';
import os = require("os");
import path = require("path");
import vscode = require("vscode");
import { LanguageClient, NotificationType, RequestType, TextDocumentIdentifier } from "vscode-languageclient";
import { IFeature } from "../feature";

// NOTE: The following two DidSaveTextDocument* types will
// be removed when #593 gets fixed.

export interface DidSaveTextDocumentParams {
/**
* The document that was closed.
*/
textDocument: TextDocumentIdentifier;
export interface IDidSaveTextDocumentParams {
/**
* The document that was closed.
*/
textDocument: TextDocumentIdentifier;
}

export namespace DidSaveTextDocumentNotification {
export const type = new NotificationType<DidSaveTextDocumentParams, void>('textDocument/didSave');
}
export const DidSaveTextDocumentNotificationType =
new NotificationType<IDidSaveTextDocumentParams, void>(
"textDocument/didSave");

export class RemoteFilesFeature implements IFeature {

Expand All @@ -31,51 +31,50 @@ export class RemoteFilesFeature implements IFeature {
// 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-')
path.join(os.tmpdir(), "PSES-")
.toLowerCase();

// At startup, close any lingering temporary remote files
this.closeRemoteFiles();

vscode.workspace.onDidSaveTextDocument(doc => {
vscode.workspace.onDidSaveTextDocument((doc) => {
if (this.languageClient && this.isDocumentRemote(doc)) {
this.languageClient.sendNotification(
DidSaveTextDocumentNotification.type,
DidSaveTextDocumentNotificationType,
{
textDocument: TextDocumentIdentifier.create(doc.uri.toString())
textDocument: TextDocumentIdentifier.create(doc.uri.toString()),
});
}
})
}

public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
});
}

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

public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
}

private isDocumentRemote(doc: vscode.TextDocument) {
return doc.fileName.toLowerCase().startsWith(this.tempSessionPathPrefix);
}

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

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

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

innerCloseFiles();
}
Expand Down
31 changes: 15 additions & 16 deletions src/features/ShowOnlineHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,41 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

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

export namespace ShowOnlineHelpRequest {
export const type = new RequestType<string, void, void, void>('powerShell/showOnlineHelp');
}
export const ShowOnlineHelpRequestType =
new RequestType<string, void, void, void>("powerShell/showOnlineHelp");

export class ShowHelpFeature implements IFeature {

private command: vscode.Disposable;
private languageClient: LanguageClient;

constructor() {
this.command = vscode.commands.registerCommand('PowerShell.OnlineHelp', () => {
this.command = vscode.commands.registerCommand("PowerShell.OnlineHelp", () => {
if (this.languageClient === undefined) {
// TODO: Log error message
return;
}

const editor = vscode.window.activeTextEditor;

var selection = editor.selection;
var doc = editor.document;
var cwr = doc.getWordRangeAtPosition(selection.active)
var text = doc.getText(cwr);
const selection = editor.selection;
const doc = editor.document;
const cwr = doc.getWordRangeAtPosition(selection.active);
const text = doc.getText(cwr);

this.languageClient.sendRequest(ShowOnlineHelpRequest.type, text);
this.languageClient.sendRequest(ShowOnlineHelpRequestType, text);
});
}

public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
}

public dispose() {
this.command.dispose();
}

public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
}
}
11 changes: 7 additions & 4 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,15 +767,18 @@ class SessionMenuItem implements vscode.QuickPickItem {

constructor(
public readonly label: string,
public readonly callback: () => void = () => { })
{
// tslint:disable-next-line:no-empty
public readonly callback: () => void = () => {}) {
}
}

export const PowerShellVersionRequestType =
new RequestType0<IPowerShellVersionDetails, void, void>("powerShell/getVersion");
new RequestType0<IPowerShellVersionDetails, void, void>(
"powerShell/getVersion");

export const RunspaceChangedEventType = new NotificationType<IRunspaceDetails, void>("powerShell/runspaceChanged");
export const RunspaceChangedEventType =
new NotificationType<IRunspaceDetails, void>(
"powerShell/runspaceChanged");

export enum RunspaceType {
Local,
Expand Down