Skip to content

Commit 5c4305f

Browse files
devversionalxhub
authored andcommitted
feat(language-service): support migrating full classes to signal inputs in VSCode (#57975)
This commit expands the VScode integration of the signal input migration to allow migration of full classes and all their inputs. This enables a faster workflow than just migrating every member individually. In addition, we now properly support migrating classes that are unexported and no actual metadata is available in `ngtsc` (but this is fine for the migration). PR Close #57975
1 parent e8b2d5f commit 5c4305f

14 files changed

Lines changed: 876 additions & 305 deletions

File tree

packages/core/schematics/migrations/signal-migration/src/best_effort_mode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {InputIncompatibilityReason} from './input_detection/incompatibility';
1010
import {KnownInputs} from './input_detection/known_inputs';
1111

1212
/** Input reasons that cannot be ignored. */
13-
const nonIgnorableInputIncompatibilities: InputIncompatibilityReason[] = [
13+
export const nonIgnorableInputIncompatibilities: InputIncompatibilityReason[] = [
1414
// Outside of scope inputs should not be migrated. E.g. references to inputs in `node_modules/`.
1515
InputIncompatibilityReason.OutsideOfMigrationScope,
1616
// Explicitly filtered inputs cannot be skipped via best effort mode.

packages/core/schematics/migrations/signal-migration/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ export {type ClassFieldDescriptor} from './passes/reference_resolution/known_fie
2020
export {type InputDescriptor, getInputDescriptor, isInputDescriptor} from './utils/input_id';
2121
export {SignalInputMigration} from './migration';
2222
export {type MigrationConfig} from './migration_config';
23+
export {nonIgnorableInputIncompatibilities} from './best_effort_mode';
24+
export {InputIncompatibilityReason} from './input_detection/incompatibility';

packages/language-service/api.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export type GetTemplateLocationForComponentResponse = ts.DocumentSpan | undefine
7878
*/
7979
export type ApplyRefactoringProgressFn = (percentage: number, updateMessage: string) => void;
8080

81+
/** Interface describing the result for computing edits of a refactoring. */
82+
export interface ApplyRefactoringResult extends Omit<ts.RefactorEditInfo, 'notApplicableReason'> {
83+
errorMessage?: string;
84+
warningMessage?: string;
85+
}
86+
8187
/**
8288
* `NgLanguageService` describes an instance of an Angular language service,
8389
* whose API surface is a strict superset of TypeScript's language service.
@@ -96,7 +102,7 @@ export interface NgLanguageService extends ts.LanguageService {
96102
positionOrRange: number | ts.TextRange,
97103
refactorName: string,
98104
reportProgress: ApplyRefactoringProgressFn,
99-
): Promise<ts.RefactorEditInfo | undefined>;
105+
): Promise<ApplyRefactoringResult | undefined>;
100106

101107
hasCodeFixesForErrorCode(errorCode: number): boolean;
102108
}

packages/language-service/src/language_service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import ts from 'typescript';
1919

2020
import {
2121
ApplyRefactoringProgressFn,
22+
ApplyRefactoringResult,
2223
GetComponentLocationsForTemplateResponse,
2324
GetTcbResponse,
2425
GetTemplateLocationForComponentResponse,
@@ -587,7 +588,7 @@ export class LanguageService {
587588
positionOrRange: number | ts.TextRange,
588589
refactorName: string,
589590
reportProgress: ApplyRefactoringProgressFn,
590-
): Promise<ts.RefactorEditInfo | undefined> {
591+
): Promise<ApplyRefactoringResult | undefined> {
591592
const matchingRefactoring = allRefactorings.find((r) => r.id === refactorName);
592593
if (matchingRefactoring === undefined) {
593594
return undefined;

packages/language-service/src/refactorings/BUILD.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ package(default_visibility = ["//packages/language-service:__subpackages__"])
55
ts_library(
66
name = "refactorings",
77
srcs = glob([
8-
"*.ts",
8+
"**/*.ts",
99
]),
1010
deps = [
1111
"//packages/compiler-cli",
12+
"//packages/compiler-cli/src/ngtsc/annotations",
1213
"//packages/compiler-cli/src/ngtsc/core",
1314
"//packages/compiler-cli/src/ngtsc/file_system",
1415
"//packages/compiler-cli/src/ngtsc/metadata",
16+
"//packages/compiler-cli/src/ngtsc/reflection",
1517
"//packages/core/schematics/migrations/signal-migration/src",
1618
"//packages/core/schematics/utils/tsurge",
1719
"//packages/language-service:api",

packages/language-service/src/refactorings/convert_to_signal_input.ts

Lines changed: 0 additions & 224 deletions
This file was deleted.

0 commit comments

Comments
 (0)