Skip to content

Commit f9c89b4

Browse files
committed
Added support for prospector
1 parent ab6aabd commit f9c89b4

4 files changed

Lines changed: 68 additions & 2 deletions

File tree

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@
272272
"default": true,
273273
"description": "Whether to lint Python files."
274274
},
275+
"python.linting.prospectorEnabled": {
276+
"type": "boolean",
277+
"default": false,
278+
"description": "Whether to lint Python files using prospector."
279+
},
275280
"python.linting.pylintEnabled": {
276281
"type": "boolean",
277282
"default": true,
@@ -362,6 +367,21 @@
362367
"Warning"
363368
]
364369
},
370+
"python.linting.prospectorPath": {
371+
"type": "string",
372+
"default": "prospector",
373+
"description": "Path to Prospector, you can use a custom version of prospector by modifying this setting to include the full path."
374+
},
375+
"python.linting.prospectorSourcePath": {
376+
"type": "string",
377+
"default": "",
378+
"description": "Path to python source (relative to workspace)."
379+
},
380+
"python.linting.prospectorExtraCommands": {
381+
"type": "string",
382+
"default": "",
383+
"description": "Extra command line options to be passed to (ex: path to profile to be used)."
384+
},
365385
"python.linting.pylintPath": {
366386
"type": "string",
367387
"default": "pylint",

src/client/common/configSettings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface IPylintCategorySeverity {
2626
}
2727
export interface ILintingSettings {
2828
enabled: boolean;
29+
prospectorEnabled: boolean,
2930
pylintEnabled: boolean;
3031
pep8Enabled: boolean;
3132
flake8Enabled: boolean;
@@ -34,6 +35,9 @@ export interface ILintingSettings {
3435
lintOnSave: boolean;
3536
maxNumberOfProblems: number;
3637
pylintCategorySeverity: IPylintCategorySeverity;
38+
prospectorPath: string;
39+
prospectorSourcePath: string;
40+
prospectorExtraCommands: string;
3741
pylintPath: string;
3842
pep8Path: string;
3943
flake8Path: string;

src/client/linters/prospector.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
import * as path from 'path';
4+
import * as baseLinter from './baseLinter';
5+
import * as settings from './../common/configSettings';
6+
import {OutputChannel, workspace} from 'vscode';
7+
8+
const PROSPECTOR_COMMANDLINE = " --output-format=vscode";
9+
10+
const REGEX = '(?<line>\\d+),(?<column>\\d+),(?<type>[\\w-]+),(?<code>[\\w-]+):(?<message>.*)\\r?(\\n|$)';
11+
12+
13+
export class Linter extends baseLinter.BaseLinter {
14+
constructor(rootDir: string, pythonSettings: settings.IPythonSettings, outputChannel: OutputChannel) {
15+
super("prospector", pythonSettings, outputChannel);
16+
}
17+
18+
public runLinter(filePath: string, txtDocumentLines: string[]): Promise<baseLinter.ILintMessage[]> {
19+
if (!this.pythonSettings.linting.prospectorEnabled) {
20+
return Promise.resolve([]);
21+
}
22+
23+
var prospectorPath = this.pythonSettings.linting.prospectorPath;
24+
var prospectorSourcePath = this.pythonSettings.linting.prospectorSourcePath;
25+
var prospectorExtraCommands = this.pythonSettings.linting.prospectorExtraCommands;
26+
// prospector works best with relative path
27+
var fileName = filePath.replace(path.join(workspace.rootPath, prospectorSourcePath, '/'), '');
28+
var cmdLine = `${prospectorPath} ${PROSPECTOR_COMMANDLINE} ${prospectorExtraCommands} "${fileName}"`;
29+
return new Promise<baseLinter.ILintMessage[]>((resolve, reject) => {
30+
this.run(cmdLine, filePath, txtDocumentLines, path.join(workspace.rootPath, prospectorSourcePath) , REGEX).then(messages=> {
31+
//All messages in prospector are treated as warn, ings for now
32+
messages.forEach(msg=> {
33+
msg.severity = baseLinter.LintMessageSeverity.Information;
34+
});
35+
36+
resolve(messages);
37+
}, reject);
38+
});
39+
}
40+
}

src/client/providers/lintProvider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as vscode from 'vscode';
77
import * as path from 'path';
88
import * as linter from '../linters/baseLinter';
9+
import * as prospector from './../linters/prospector';
910
import * as pylint from './../linters/pylint';
1011
import * as pep8 from './../linters/pep8Linter';
1112
import * as flake8 from './../linters/flake8';
@@ -32,7 +33,7 @@ function createDiagnostics(message: linter.ILintMessage, txtDocumentLines: strin
3233
var sourceLine = txtDocumentLines[message.line - 1];
3334
var sourceStart = sourceLine.substring(message.column - 1);
3435
var endCol = txtDocumentLines[message.line - 1].length;
35-
36+
3637
//try to get the first word from the startig position
3738
if (message.possibleWord === "string" && message.possibleWord.length > 0) {
3839
endCol = message.column + message.possibleWord.length;
@@ -65,6 +66,7 @@ export class LintProvider extends vscode.Disposable {
6566
this.diagnosticCollection = vscode.languages.createDiagnosticCollection("python");
6667
var disposables = [];
6768

69+
this.linters.push(new prospector.Linter(this.context.asAbsolutePath("."), this.settings, this.outputChannel));
6870
this.linters.push(new pylint.Linter(this.context.asAbsolutePath("."), this.settings, this.outputChannel));
6971
this.linters.push(new pep8.Linter(this.context.asAbsolutePath("."), this.settings, this.outputChannel));
7072
this.linters.push(new flake8.Linter(this.context.asAbsolutePath("."), this.settings, this.outputChannel));
@@ -131,7 +133,7 @@ export class LintProvider extends vscode.Disposable {
131133
var messages = [];
132134
//Limit the number of messages to the max value
133135
consolidatedMessages = consolidatedMessages.filter((value, index) => index <= this.settings.linting.maxNumberOfProblems);
134-
136+
135137
//Build the message and suffix the message with the name of the linter used
136138
consolidatedMessages.forEach(d=> {
137139
d.message = `${d.message} (${d.provider})`;

0 commit comments

Comments
 (0)