-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathutils.ts
29 lines (24 loc) · 1.22 KB
/
utils.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
"use strict";
import * as path from "path";
import * as vscode from "vscode";
import { IPowerShellExtensionClient } from "../src/features/ExternalApi";
// This lets us test the rest of our path assumptions against the baseline of
// this test file existing at `<root>/out/test/utils.js`.
export const rootPath = path.resolve(__dirname, "../../")
// tslint:disable-next-line: no-var-requires
const packageJSON: any = require(path.resolve(rootPath, "package.json"));
export const extensionId = `${packageJSON.publisher}.${packageJSON.name}`;
export async function ensureExtensionIsActivated(): Promise<IPowerShellExtensionClient> {
const extension = vscode.extensions.getExtension(extensionId);
if (!extension.isActive) { await extension.activate(); }
return extension!.exports as IPowerShellExtensionClient;
}
export async function ensureEditorServicesIsConnected(): Promise<IPowerShellExtensionClient> {
const extension = await ensureExtensionIsActivated();
const sessionId = extension.registerExternalExtension(extensionId);
await extension.waitUntilStarted(sessionId);
extension.unregisterExternalExtension(sessionId);
return extension;
}