Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderRonde committed Mar 28, 2024
2 parents 4e9d555 + 83280fb commit d262f94
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions client/src/lib/errorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as vscode from 'vscode';

interface PHPStanError {
message: string;
lineNumber: number;
lineNumber: number | null;
}

export class ErrorManager implements Disposable, vscode.CodeActionProvider {
Expand All @@ -15,7 +15,7 @@ export class ErrorManager implements Disposable, vscode.CodeActionProvider {
string,
{
message: string;
lineNumber: number;
lineNumber: number | null;
}[]
>;
notFileSpecificErrors: string[];
Expand Down Expand Up @@ -117,6 +117,13 @@ export class ErrorManager implements Disposable, vscode.CodeActionProvider {
(doc) => doc.uri.toString() === uri.toString()
);

if (!error.lineNumber) {
return this._createDiagnostic(
new vscode.Range(0, 0, 0, 0),
error.message
);
}

const lineNumber = error.lineNumber - 1;

if (!file) {
Expand Down Expand Up @@ -236,6 +243,9 @@ export class ErrorManager implements Disposable, vscode.CodeActionProvider {
const actions: ErrorCodeAction[] = [];

for (const error of errors) {
if (error.lineNumber === null) {
continue;
}
if (error.lineNumber !== range.start.line + 1) {
continue;
}
Expand Down Expand Up @@ -267,6 +277,11 @@ class ErrorCodeAction extends vscode.CodeAction {
}

public resolveEdit(): void {
if (this._error.lineNumber === null) {
// Theoretically not reachable
return;
}

this.edit = new vscode.WorkspaceEdit();
const errorRange = new vscode.Range(
this._error.lineNumber - 1,
Expand Down
2 changes: 1 addition & 1 deletion server/src/lib/phpstan/outputParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface ReportedErrors {
string,
{
message: string;
lineNumber: number;
lineNumber: number | null;
}[]
>;
notFileSpecificErrors: string[];
Expand Down
2 changes: 1 addition & 1 deletion server/src/lib/phpstan/pro/proErrorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ interface ReportedError {
definiteFixerSuggestion: unknown | null;
file: string;
id: string;
line: number;
line: number | null;
message: string;
}

Expand Down

0 comments on commit d262f94

Please sign in to comment.