forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprospector.ts
More file actions
69 lines (64 loc) · 2.28 KB
/
Copy pathprospector.ts
File metadata and controls
69 lines (64 loc) · 2.28 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
import * as path from 'path';
import { CancellationToken, TextDocument } from 'vscode';
import '../common/extensions';
import { Product } from '../common/types';
import { IServiceContainer } from '../ioc/types';
import { traceError, traceLog } from '../logging';
import { BaseLinter } from './baseLinter';
import { ILintMessage } from './types';
interface IProspectorResponse {
messages: IProspectorMessage[];
}
interface IProspectorMessage {
source: string;
message: string;
code: string;
location: IProspectorLocation;
}
interface IProspectorLocation {
function: string;
path: string;
line: number;
character: number;
module: 'beforeFormat';
}
export class Prospector extends BaseLinter {
constructor(serviceContainer: IServiceContainer) {
super(Product.prospector, serviceContainer);
}
protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<ILintMessage[]> {
const cwd = this.getWorkingDirectoryPath(document);
const relativePath = path.relative(cwd, document.uri.fsPath);
return this.run([relativePath], document, cancellation);
}
protected async parseMessages(
output: string,
_document: TextDocument,
_token: CancellationToken,
_regEx: string,
): Promise<ILintMessage[]> {
let parsedData: IProspectorResponse;
try {
parsedData = JSON.parse(output);
} catch (ex) {
traceLog(`${'#'.repeat(10)}Linting Output - ${this.info.id}${'#'.repeat(10)}`);
traceLog(output);
traceError('Failed to parse Prospector output', ex);
return [];
}
return parsedData.messages
.filter((_value, index) => index <= this.pythonSettings.linting.maxNumberOfProblems)
.map((msg) => {
const lineNumber =
msg.location.line === null || Number.isNaN(msg.location.line) ? 1 : msg.location.line;
return {
code: msg.code,
message: msg.message,
column: msg.location.character,
line: lineNumber,
type: msg.code,
provider: `${this.info.id} - ${msg.source}`,
};
});
}
}