forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmypy.ts
More file actions
39 lines (31 loc) · 1.68 KB
/
Copy pathmypy.ts
File metadata and controls
39 lines (31 loc) · 1.68 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
'use strict';
import * as baseLinter from './baseLinter';
import { OutputChannel } from 'vscode';
import { Product, ProductExecutableAndArgs } from '../common/installer';
import { TextDocument, CancellationToken } from 'vscode';
const REGEX = '(?<file>.py):(?<line>\\d+): (?<type>\\w+): (?<message>.*)\\r?(\\n|$)';
export class Linter extends baseLinter.BaseLinter {
constructor(outputChannel: OutputChannel) {
super('mypy', Product.mypy, outputChannel);
}
protected runLinter(document: TextDocument, cancellation: CancellationToken): Promise<baseLinter.ILintMessage[]> {
if (!this.pythonSettings.linting.mypyEnabled) {
return Promise.resolve([]);
}
let mypyPath = this.pythonSettings.linting.mypyPath;
let mypyArgs = Array.isArray(this.pythonSettings.linting.mypyArgs) ? this.pythonSettings.linting.mypyArgs : [];
if (mypyArgs.length === 0 && ProductExecutableAndArgs.has(Product.mypy) && mypyPath.toLocaleLowerCase() === 'mypy'){
mypyPath = ProductExecutableAndArgs.get(Product.mypy).executable;
mypyArgs = ProductExecutableAndArgs.get(Product.mypy).args;
}
return new Promise<baseLinter.ILintMessage[]>((resolve, reject) => {
this.run(mypyPath, mypyArgs.concat([document.uri.fsPath]), document, this.getWorkspaceRootPath(document), cancellation, REGEX).then(messages => {
messages.forEach(msg => {
msg.severity = this.parseMessagesSeverity(msg.type, this.pythonSettings.linting.mypyCategorySeverity);
msg.code = msg.type;
});
resolve(messages);
}, reject);
});
}
}