forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.ts
More file actions
59 lines (55 loc) · 2.29 KB
/
common.ts
File metadata and controls
59 lines (55 loc) · 2.29 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// tslint:disable:no-any no-invalid-this no-default-export no-console
import * as assert from 'assert';
import * as fs from 'fs-extra';
import * as glob from 'glob';
import * as path from 'path';
import * as vscode from 'vscode';
import { SMOKE_TEST_EXTENSIONS_DIR } from '../constants';
import { noop, sleep } from '../core';
export async function updateSetting(setting: string, value: any) {
const resource = vscode.workspace.workspaceFolders![0].uri;
await vscode.workspace
.getConfiguration('python', resource)
.update(setting, value, vscode.ConfigurationTarget.WorkspaceFolder);
}
export async function removeLanguageServerFiles() {
const folders = await getLanaguageServerFolders();
await Promise.all(folders.map(item => fs.remove(item).catch(noop)));
}
async function getLanaguageServerFolders(): Promise<string[]> {
return new Promise<string[]>((resolve, reject) => {
glob('languageServer.*', { cwd: SMOKE_TEST_EXTENSIONS_DIR }, (ex, matches) => {
ex ? reject(ex) : resolve(matches.map(item => path.join(SMOKE_TEST_EXTENSIONS_DIR, item)));
});
});
}
export function isJediEnabled() {
const resource = vscode.workspace.workspaceFolders![0].uri;
const settings = vscode.workspace.getConfiguration('python', resource);
return settings.get<boolean>('jediEnabled') === true;
}
export async function enableJedi(enable: boolean | undefined) {
if (isJediEnabled() === enable) {
return;
}
await updateSetting('jediEnabled', enable);
}
export async function openFileAndWaitForLS(file: string): Promise<vscode.TextDocument> {
const textDocument = await vscode.workspace.openTextDocument(file);
await vscode.window.showTextDocument(textDocument);
assert(vscode.window.activeTextEditor, 'No active editor');
// Make sure LS completes file loading and analysis.
// In test mode it awaits for the completion before trying
// to fetch data for completion, hover.etc.
await vscode.commands.executeCommand(
'vscode.executeCompletionItemProvider',
textDocument.uri,
new vscode.Position(0, 0)
);
// For for LS to get extracted.
await sleep(10_000);
return textDocument;
}