-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathExpandAlias.ts
57 lines (47 loc) · 2.07 KB
/
ExpandAlias.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
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import vscode = require("vscode");
import Window = vscode.window;
import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient";
import { IFeature } from "../feature";
import { Logger } from "../logging";
export const ExpandAliasRequestType = new RequestType<any, any, void, void>("powerShell/expandAlias");
export class ExpandAliasFeature implements IFeature {
private command: vscode.Disposable;
private languageClient: LanguageClient;
constructor(private log: Logger) {
this.command = vscode.commands.registerCommand("PowerShell.ExpandAlias", () => {
if (this.languageClient === undefined) {
this.log.writeAndShowError(`<${ExpandAliasFeature.name}>: ` +
"Unable to instantiate; language client undefined.");
return;
}
const editor = Window.activeTextEditor;
const document = editor.document;
const selection = editor.selection;
const sls = selection.start;
const sle = selection.end;
let text;
let range;
if ((sls.character === sle.character) && (sls.line === sle.line)) {
text = document.getText();
range = new vscode.Range(0, 0, document.lineCount, text.length);
} else {
text = document.getText(selection);
range = new vscode.Range(sls.line, sls.character, sle.line, sle.character);
}
this.languageClient.sendRequest(ExpandAliasRequestType, { text }).then((result) => {
editor.edit((editBuilder) => {
editBuilder.replace(range, result.text);
});
});
});
}
public dispose() {
this.command.dispose();
}
public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
}
}