forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.ts
More file actions
39 lines (35 loc) · 2.05 KB
/
common.ts
File metadata and controls
39 lines (35 loc) · 2.05 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
import * as path from 'path';
import { ConfigurationTarget, Uri, workspace } from 'vscode';
import { PythonSettings } from '../client/common/configSettings';
const fileInNonRootWorkspace = path.join(__dirname, '..', '..', 'src', 'test', 'pythonFiles', 'dummy.py');
export const rootWorkspaceUri = getWorkspaceRoot();
export type PythonSettingKeys = 'workspaceSymbols.enabled' | 'pythonPath' |
'linting.lintOnSave' | 'linting.lintOnTextChange' |
'linting.enabled' | 'linting.pylintEnabled' |
'linting.flake8Enabled' | 'linting.pep8Enabled' | 'linting.pylamaEnabled' |
'linting.prospectorEnabled' | 'linting.pydocstyleEnabled' | 'linting.mypyEnabled' |
'unitTest.nosetestArgs' | 'unitTest.pyTestArgs' | 'unitTest.unittestArgs' |
'formatting.formatOnSave' | 'formatting.provider' | 'sortImports.args';
export async function updateSetting(setting: PythonSettingKeys, value: {}, resource: Uri, configTarget: ConfigurationTarget) {
const settings = workspace.getConfiguration('python', resource);
const currentValue = settings.inspect(setting);
if (currentValue !== undefined && ((configTarget === ConfigurationTarget.Global && currentValue.globalValue === value) ||
(configTarget === ConfigurationTarget.Workspace && currentValue.workspaceValue === value) ||
(configTarget === ConfigurationTarget.WorkspaceFolder && currentValue.workspaceFolderValue === value))) {
PythonSettings.dispose();
return;
}
// tslint:disable-next-line:await-promise
await settings.update(setting, value, configTarget);
PythonSettings.dispose();
}
function getWorkspaceRoot() {
if (!Array.isArray(workspace.workspaceFolders) || workspace.workspaceFolders.length === 0) {
return Uri.file(path.join(__dirname, '..', '..', 'src', 'test'));
}
if (workspace.workspaceFolders.length === 1) {
return workspace.workspaceFolders[0].uri;
}
const workspaceFolder = workspace.getWorkspaceFolder(Uri.file(fileInNonRootWorkspace));
return workspaceFolder ? workspaceFolder.uri : workspace.workspaceFolders[0].uri;
}