Skip to content

Commit

Permalink
Merge pull request #88 from jrmajor/ignore-error
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderRonde authored Aug 3, 2024
2 parents e83910d + 9c6520a commit a6c487f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
26 changes: 14 additions & 12 deletions client/src/notificationReceivers/errorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import * as vscode from 'vscode';
interface PHPStanError {
message: string;
lineNumber: number | null;
ignorable: boolean;
identifier: string | null;
}

export class ErrorManager implements Disposable, vscode.CodeActionProvider {
private readonly _diagnosticsCollection: vscode.DiagnosticCollection;
private _errors: {
fileSpecificErrors: Map<
string,
{
message: string;
lineNumber: number | null;
}[]
>;
fileSpecificErrors: Map<string, PHPStanError[]>;
notFileSpecificErrors: string[];
} = {
fileSpecificErrors: new Map(),
Expand Down Expand Up @@ -68,8 +64,10 @@ export class ErrorManager implements Disposable, vscode.CodeActionProvider {
) ?? []),
...this._errors.notFileSpecificErrors.map(
(message) => ({
lineNumber: 0,
message,
lineNumber: null,
ignorable: false,
identifier: null,
})
),
]);
Expand Down Expand Up @@ -249,6 +247,9 @@ export class ErrorManager implements Disposable, vscode.CodeActionProvider {
if (error.lineNumber !== range.start.line + 1) {
continue;
}
if (!error.ignorable) {
continue;
}
const action = new ErrorCodeAction(document, error);
actions.push(action);
}
Expand Down Expand Up @@ -289,14 +290,15 @@ class ErrorCodeAction extends vscode.CodeAction {
this._error.lineNumber - 1,
this._document.lineAt(this._error.lineNumber - 1).text.length
);
const ignoreCommentContent = this._error.identifier
? `@phpstan-ignore ${this._error.identifier}`
: '@phpstan-ignore-next-line';
const originalText = this._document.getText(errorRange);
const lineIndent = /^(\s*)/.exec(originalText);
const indent = /^(\s*)/.exec(originalText)?.[1] ?? '';
this.edit.replace(
this._document.uri,
errorRange,
`${
lineIndent?.[1] ?? ''
}// @phpstan-ignore-next-line\n${originalText}`,
`${indent}// ${ignoreCommentContent}\n${originalText}`,
{
label: 'Ignore PHPStan error',
needsConfirmation: false,
Expand Down
4 changes: 4 additions & 0 deletions server/src/lib/phpstan/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export class PHPStanCheck implements AsyncDisposable {
...output.files[key].messages.map((message) => ({
message: message.message + messagePostfix,
lineNumber: message.line,
ignorable: message.ignorable,
identifier: message.identifier ?? null,
})),
];
}
Expand Down Expand Up @@ -270,6 +272,8 @@ export interface ReportedErrors {
{
message: string;
lineNumber: number | null;
ignorable: boolean;
identifier: string | null;
}[]
>;
notFileSpecificErrors: string[];
Expand Down
4 changes: 4 additions & 0 deletions server/src/lib/phpstan/pro/proErrorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ export class PHPStanProErrorManager implements Disposable {
fileSpecificErrors[uri].push({
message: fileError.message,
lineNumber: fileError.line,
ignorable: fileError.ignorable,
identifier: fileError.identifier ?? null,
});
}
void this._classConfig.connection.sendNotification(errorNotification, {
Expand All @@ -244,6 +246,8 @@ interface ReportedError {
id: string;
line: number | null;
message: string;
ignorable: boolean;
identifier: string | null;
}

interface ProReportedErrors {
Expand Down
1 change: 1 addition & 0 deletions server/src/lib/phpstan/processRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface PHPStanCheckResult {
{
errors: number;
messages: {
identifier?: string;
ignorable: boolean;
line: number;
message: string;
Expand Down

0 comments on commit a6c487f

Please sign in to comment.