forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigSettings.ts
More file actions
153 lines (144 loc) · 5.98 KB
/
configSettings.ts
File metadata and controls
153 lines (144 loc) · 5.98 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
'use strict';
import * as vscode from 'vscode';
import {SystemVariables} from './systemVariables';
import {EventEmitter} from 'events';
import * as path from 'path';
export interface IPythonSettings {
pythonPath: string;
devOptions: any[];
linting: ILintingSettings;
formatting: IFormattingSettings;
unitTest: IUnitTestSettings;
autoComplete: IAutoCompeteSettings;
}
export interface IUnitTestSettings {
nosetestsEnabled: boolean;
nosetestPath: string;
nosetestArgs: string[];
pyTestEnabled: boolean;
pyTestPath: string;
pyTestArgs: string[];
unittestEnabled: boolean;
unittestArgs: string[];
outputWindow: string;
}
export interface IPylintCategorySeverity {
convention: vscode.DiagnosticSeverity;
refactor: vscode.DiagnosticSeverity;
warning: vscode.DiagnosticSeverity;
error: vscode.DiagnosticSeverity;
fatal: vscode.DiagnosticSeverity;
}
export interface ILintingSettings {
enabled: boolean;
prospectorEnabled: boolean;
prospectorArgs: string[];
pylintEnabled: boolean;
pylintArgs: string[];
pep8Enabled: boolean;
pep8Args: string[];
flake8Enabled: boolean;
flake8Args: string[];
pydocstyleEnabled: boolean;
pydocstleArgs: string[];
lintOnTextChange: boolean;
lintOnSave: boolean;
maxNumberOfProblems: number;
pylintCategorySeverity: IPylintCategorySeverity;
prospectorPath: string;
pylintPath: string;
pep8Path: string;
flake8Path: string;
pydocStylePath: string;
outputWindow: string;
}
export interface IFormattingSettings {
provider: string;
autopep8Path: string;
autopep8Args: string[];
yapfPath: string;
yapfArgs: string[];
formatOnSave: boolean;
outputWindow: string;
}
export interface IAutoCompeteSettings {
extraPaths: string[];
}
const systemVariables: SystemVariables = new SystemVariables();
export class PythonSettings extends EventEmitter implements IPythonSettings {
private static pythonSettings: PythonSettings = new PythonSettings();
constructor() {
super();
if (PythonSettings.pythonSettings) {
throw new Error('Singleton class, Use getInstance method');
}
vscode.workspace.onDidChangeConfiguration(() => {
this.initializeSettings();
});
this.initializeSettings();
}
public static getInstance(): PythonSettings {
return PythonSettings.pythonSettings;
}
private initializeSettings() {
let pythonSettings = vscode.workspace.getConfiguration('python');
this.pythonPath = systemVariables.resolveAny(pythonSettings.get<string>('pythonPath'));
this.pythonPath = getAbsolutePath(this.pythonPath, vscode.workspace.rootPath);
this.devOptions = systemVariables.resolveAny(pythonSettings.get<any[]>('devOptions'));
this.devOptions = Array.isArray(this.devOptions) ? this.devOptions : [];
let lintingSettings = systemVariables.resolveAny(pythonSettings.get<ILintingSettings>('linting'));
if (this.linting) {
Object.assign<ILintingSettings, ILintingSettings>(this.linting, lintingSettings);
}
else {
this.linting = lintingSettings;
}
this.linting.pylintPath = getAbsolutePath(this.linting.pylintPath, vscode.workspace.rootPath);
this.linting.flake8Path = getAbsolutePath(this.linting.flake8Path, vscode.workspace.rootPath);
this.linting.pep8Path = getAbsolutePath(this.linting.pep8Path, vscode.workspace.rootPath);
this.linting.prospectorPath = getAbsolutePath(this.linting.prospectorPath, vscode.workspace.rootPath);
this.linting.pydocStylePath = getAbsolutePath(this.linting.pydocStylePath, vscode.workspace.rootPath);
let formattingSettings = systemVariables.resolveAny(pythonSettings.get<IFormattingSettings>('formatting'));
if (this.formatting) {
Object.assign<IFormattingSettings, IFormattingSettings>(this.formatting, formattingSettings);
}
else {
this.formatting = formattingSettings;
}
this.formatting.autopep8Path = getAbsolutePath(this.formatting.autopep8Path, vscode.workspace.rootPath);
this.formatting.yapfPath = getAbsolutePath(this.formatting.yapfPath, vscode.workspace.rootPath);
let autoCompleteSettings = systemVariables.resolveAny(pythonSettings.get<IAutoCompeteSettings>('autoComplete'));
if (this.autoComplete) {
Object.assign<IAutoCompeteSettings, IAutoCompeteSettings>(this.autoComplete, autoCompleteSettings);
}
else {
this.autoComplete = autoCompleteSettings;
}
let unitTestSettings = systemVariables.resolveAny(pythonSettings.get<IUnitTestSettings>('unitTest'));
if (this.unitTest) {
Object.assign<IUnitTestSettings, IUnitTestSettings>(this.unitTest, unitTestSettings);
}
else {
this.unitTest = unitTestSettings;
}
this.emit('change');
this.unitTest.pyTestPath = getAbsolutePath(this.unitTest.pyTestPath, vscode.workspace.rootPath);
this.unitTest.nosetestPath = getAbsolutePath(this.unitTest.nosetestPath, vscode.workspace.rootPath);
// Resolve any variables found in the test arguments
this.unitTest.nosetestArgs = this.unitTest.nosetestArgs.map(arg => systemVariables.resolveAny(arg));
this.unitTest.pyTestArgs = this.unitTest.pyTestArgs.map(arg => systemVariables.resolveAny(arg));
this.unitTest.unittestArgs = this.unitTest.unittestArgs.map(arg => systemVariables.resolveAny(arg));
}
public pythonPath: string;
public devOptions: any[];
public linting: ILintingSettings;
public formatting: IFormattingSettings;
public autoComplete: IAutoCompeteSettings;
public unitTest: IUnitTestSettings;
}
function getAbsolutePath(pathToCheck: string, rootDir: String): string {
if (pathToCheck.indexOf(path.sep) === -1){
return pathToCheck;
}
return path.isAbsolute(pathToCheck) ? pathToCheck : path.resolve(rootDir, pathToCheck);
}