Skip to content

Commit db8d74e

Browse files
committed
displaying errors for linter errors #402
1 parent 51cc479 commit db8d74e

2 files changed

Lines changed: 40 additions & 9 deletions

File tree

src/client/common/installer.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ export class Installer {
8080
const useOtherFormatter = `Use '${alternateFormatter}' formatter`;
8181
const options = [];
8282
if (Formatters.indexOf(product) === -1) {
83-
options.push(...[installOption, disableOption, 'Help']);
83+
options.push(...[installOption, disableOption]);
8484
}
8585
else {
86-
options.push(...[installOption, useOtherFormatter, 'Help']);
86+
options.push(...[installOption, useOtherFormatter]);
8787
}
8888
vscode.window.showErrorMessage(`${productType} ${productName} is not installed`, ...options).then(item => {
8989
switch (item) {
@@ -92,9 +92,14 @@ export class Installer {
9292
break;
9393
}
9494
case disableOption: {
95-
const pythonConfig = vscode.workspace.getConfiguration('python');
96-
const settingToDisable = SettingToDisableProduct.get(product);
97-
pythonConfig.update(settingToDisable, false);
95+
if (Linters.indexOf(product) >= 0) {
96+
disableLinter(product);
97+
}
98+
else {
99+
const pythonConfig = vscode.workspace.getConfiguration('python');
100+
const settingToDisable = SettingToDisableProduct.get(product);
101+
pythonConfig.update(settingToDisable, false);
102+
}
98103
break;
99104
}
100105
case useOtherFormatter: {
@@ -128,4 +133,10 @@ export class Installer {
128133
Installer.terminal.sendText(installScript);
129134
Installer.terminal.show(false);
130135
}
136+
}
137+
138+
export function disableLinter(product: Product) {
139+
const pythonConfig = vscode.workspace.getConfiguration('python');
140+
const settingToDisable = SettingToDisableProduct.get(product);
141+
pythonConfig.update(settingToDisable, false);
131142
}

src/client/linters/baseLinter.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { execPythonFile } from './../common/utils';
33
import * as settings from './../common/configSettings';
44
import { OutputChannel } from 'vscode';
55
import { isNotInstalledError } from '../common/helpers';
6-
import { Installer, Product } from '../common/installer';
6+
import { Installer, Product, disableLinter } from '../common/installer';
7+
import * as vscode from 'vscode';
78

89
let NamedRegexp = null;
910
const REGEX = '(?<line>\\d+),(?<column>\\d+),(?<type>\\w+),(?<code>\\w\\d+):(?<message>.*)\\r?(\\n|$)';
@@ -51,7 +52,7 @@ export abstract class BaseLinter {
5152
public Id: string;
5253
private installer: Installer;
5354
protected pythonSettings: settings.IPythonSettings;
54-
constructor(id: string, private product:Product, protected outputChannel: OutputChannel, protected workspaceRootPath: string) {
55+
constructor(id: string, private product: Product, protected outputChannel: OutputChannel, protected workspaceRootPath: string) {
5556
this.Id = id;
5657
this.installer = new Installer();
5758
this.pythonSettings = settings.PythonSettings.getInstance();
@@ -127,12 +128,31 @@ export abstract class BaseLinter {
127128
customError = `Linting failed, custom arguments in the 'python.linting.${this.Id}Path' is not supported.\n` +
128129
`Custom arguments to the linters can be defined in 'python.linting.${this.Id}Args' setting of settings.json.\n` +
129130
'For further details, please see https://github.com/DonJayamanne/pythonVSCode/wiki/Troubleshooting-Linting#2-linting-with-xxx-failed-';
131+
vscode.window.showErrorMessage(`Unsupported configuration for '${this.Id}'`, 'View Errors').then(item => {
132+
if (item === 'View Errors') {
133+
this.outputChannel.show();
134+
}
135+
});
130136
}
131137
else {
132-
customError += `\nYou could either install the '${this.Id}' linter or turn it off in setings.json via "python.linting.${this.Id}Enabled = false".`;this.installer.promptToInstall(this.product);
138+
customError += `\nYou could either install the '${this.Id}' linter or turn it off in setings.json via "python.linting.${this.Id}Enabled = false".`;
139+
this.installer.promptToInstall(this.product);
133140
}
134141
}
135-
142+
else {
143+
vscode.window.showErrorMessage(`There was an error in running the linter '${this.Id}'`, 'Disable linter', 'View Errors').then(item => {
144+
switch (item) {
145+
case 'Disable linter': {
146+
disableLinter(this.product);
147+
break;
148+
}
149+
case 'View Errors': {
150+
this.outputChannel.show();
151+
break;
152+
}
153+
}
154+
});
155+
}
136156
this.outputChannel.appendLine(`\n${customError}\n${error + ''}`);
137157
}
138158
}

0 commit comments

Comments
 (0)