Skip to content

Commit d87f483

Browse files
clydinAndrewKushnir
authored andcommitted
refactor(language-service): reuse code fixes map for has fix check (#58759)
The error codes that have fixes are present in a Map instance and can be directly leveraged to determine if an error code can be fixed. This avoids multiple levels of iteration that would otherwise be needed. PR Close #58759
1 parent d4f5c85 commit d87f483

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/language-service/src/codefixes/code_fixes.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {TemplateInfo} from '../utils';
1414
import {CodeActionMeta, FixIdForCodeFixesAll, isFixAllAvailable} from './utils';
1515

1616
export class CodeFixes {
17-
private errorCodeToFixes: Map<number, CodeActionMeta[]> = new Map();
17+
private errorCodeToFixes = new Map<number, CodeActionMeta[]>();
1818
private fixIdToRegistration = new Map<FixIdForCodeFixesAll, CodeActionMeta>();
1919

2020
constructor(
@@ -40,6 +40,10 @@ export class CodeFixes {
4040
}
4141
}
4242

43+
hasFixForCode(code: number): boolean {
44+
return this.errorCodeToFixes.has(code);
45+
}
46+
4347
/**
4448
* When the user moves the cursor or hovers on a diagnostics, this function will be invoked by LS,
4549
* and collect all the responses from the `codeActionMetas` which could handle the `errorCodes`.

packages/language-service/src/language_service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ export class LanguageService {
385385
* Related context: https://github.com/angular/vscode-ng-language-service/pull/2050#discussion_r1673079263
386386
*/
387387
hasCodeFixesForErrorCode(errorCode: number): boolean {
388-
return this.codeFixes.codeActionMetas.some((m) => m.errorCodes.includes(errorCode));
388+
return this.codeFixes.hasFixForCode(errorCode);
389389
}
390390

391391
getCodeFixesAtPosition(

0 commit comments

Comments
 (0)