Skip to content

Commit a6c487f

Browse files
authored
Merge pull request #88 from jrmajor/ignore-error
2 parents e83910d + 9c6520a commit a6c487f

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

client/src/notificationReceivers/errorManager.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@ import * as vscode from 'vscode';
66
interface PHPStanError {
77
message: string;
88
lineNumber: number | null;
9+
ignorable: boolean;
10+
identifier: string | null;
911
}
1012

1113
export class ErrorManager implements Disposable, vscode.CodeActionProvider {
1214
private readonly _diagnosticsCollection: vscode.DiagnosticCollection;
1315
private _errors: {
14-
fileSpecificErrors: Map<
15-
string,
16-
{
17-
message: string;
18-
lineNumber: number | null;
19-
}[]
20-
>;
16+
fileSpecificErrors: Map<string, PHPStanError[]>;
2117
notFileSpecificErrors: string[];
2218
} = {
2319
fileSpecificErrors: new Map(),
@@ -68,8 +64,10 @@ export class ErrorManager implements Disposable, vscode.CodeActionProvider {
6864
) ?? []),
6965
...this._errors.notFileSpecificErrors.map(
7066
(message) => ({
71-
lineNumber: 0,
7267
message,
68+
lineNumber: null,
69+
ignorable: false,
70+
identifier: null,
7371
})
7472
),
7573
]);
@@ -249,6 +247,9 @@ export class ErrorManager implements Disposable, vscode.CodeActionProvider {
249247
if (error.lineNumber !== range.start.line + 1) {
250248
continue;
251249
}
250+
if (!error.ignorable) {
251+
continue;
252+
}
252253
const action = new ErrorCodeAction(document, error);
253254
actions.push(action);
254255
}
@@ -289,14 +290,15 @@ class ErrorCodeAction extends vscode.CodeAction {
289290
this._error.lineNumber - 1,
290291
this._document.lineAt(this._error.lineNumber - 1).text.length
291292
);
293+
const ignoreCommentContent = this._error.identifier
294+
? `@phpstan-ignore ${this._error.identifier}`
295+
: '@phpstan-ignore-next-line';
292296
const originalText = this._document.getText(errorRange);
293-
const lineIndent = /^(\s*)/.exec(originalText);
297+
const indent = /^(\s*)/.exec(originalText)?.[1] ?? '';
294298
this.edit.replace(
295299
this._document.uri,
296300
errorRange,
297-
`${
298-
lineIndent?.[1] ?? ''
299-
}// @phpstan-ignore-next-line\n${originalText}`,
301+
`${indent}// ${ignoreCommentContent}\n${originalText}`,
300302
{
301303
label: 'Ignore PHPStan error',
302304
needsConfirmation: false,

server/src/lib/phpstan/check.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export class PHPStanCheck implements AsyncDisposable {
5858
...output.files[key].messages.map((message) => ({
5959
message: message.message + messagePostfix,
6060
lineNumber: message.line,
61+
ignorable: message.ignorable,
62+
identifier: message.identifier ?? null,
6163
})),
6264
];
6365
}
@@ -270,6 +272,8 @@ export interface ReportedErrors {
270272
{
271273
message: string;
272274
lineNumber: number | null;
275+
ignorable: boolean;
276+
identifier: string | null;
273277
}[]
274278
>;
275279
notFileSpecificErrors: string[];

server/src/lib/phpstan/pro/proErrorManager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ export class PHPStanProErrorManager implements Disposable {
218218
fileSpecificErrors[uri].push({
219219
message: fileError.message,
220220
lineNumber: fileError.line,
221+
ignorable: fileError.ignorable,
222+
identifier: fileError.identifier ?? null,
221223
});
222224
}
223225
void this._classConfig.connection.sendNotification(errorNotification, {
@@ -244,6 +246,8 @@ interface ReportedError {
244246
id: string;
245247
line: number | null;
246248
message: string;
249+
ignorable: boolean;
250+
identifier: string | null;
247251
}
248252

249253
interface ProReportedErrors {

server/src/lib/phpstan/processRunner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface PHPStanCheckResult {
2929
{
3030
errors: number;
3131
messages: {
32+
identifier?: string;
3233
ignorable: boolean;
3334
line: number;
3435
message: string;

0 commit comments

Comments
 (0)