From 90d9bfcfe95e882f481cacad2644e2aa5a0868f4 Mon Sep 17 00:00:00 2001 From: liyancheng2 Date: Tue, 15 Apr 2025 22:30:54 +0800 Subject: [PATCH 1/2] the tsnocheck scene of linter reuse the incremental mechanism of tsc Issue: https://gitee.com/openharmony/third_party_typescript/issues/IC1FXC Signed-off-by: liyancheng2 Change-Id: Ie9ca442a2e3b0add789fbe66f7b89e63b97c9b87 --- lib/tsc.js | 4 ++++ lib/tsserver.js | 8 ++++++++ lib/tsserverlibrary.d.ts | 1 + lib/tsserverlibrary.js | 8 ++++++++ lib/typescript.d.ts | 1 + lib/typescript.js | 8 ++++++++ lib/typescriptServices.d.ts | 1 + lib/typescriptServices.js | 8 ++++++++ lib/typingsInstaller.js | 8 ++++++++ src/compiler/checker.ts | 1 + src/compiler/program.ts | 7 +++++++ src/compiler/types.ts | 1 + tests/baselines/reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + 14 files changed, 58 insertions(+) diff --git a/lib/tsc.js b/lib/tsc.js index acf97dc03e..907a9903a4 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -43238,6 +43238,7 @@ var ts; deleteConstEnumRelate: function (path) { constEnumRelate && constEnumRelate.delete(path); }, clearQualifiedNameCache: function () { qualifiedNameCache && qualifiedNameCache.clear(); }, getCheckedSourceFiles: function () { return checkedSourceFiles; }, + collectHaveTsNoCheckFilesForLinter: function (sourceFile) { isTypeCheckerForLinter && checkedSourceFiles.add(sourceFile); }, getTypeArgumentsForResolvedSignature: getTypeArgumentsForResolvedSignature, }; function getTypeArgumentsForResolvedSignature(signature) { @@ -103697,6 +103698,9 @@ var ts; var includeBindAndCheckDiagnostics = !isTsNoCheck && (sourceFile.scriptKind === 3 || sourceFile.scriptKind === 4 || sourceFile.scriptKind === 5 || isPlainJs || isCheckJs || sourceFile.scriptKind === 7 || sourceFile.scriptKind === 8); var bindDiagnostics = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : ts.emptyArray; + if (!includeBindAndCheckDiagnostics) { + typeChecker.collectHaveTsNoCheckFilesForLinter(sourceFile); + } var checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : ts.emptyArray; if (isPlainJs) { bindDiagnostics = ts.filter(bindDiagnostics, function (d) { return ts.plainJSErrors.has(d.code); }); diff --git a/lib/tsserver.js b/lib/tsserver.js index 83e89b9d54..9ad0643d78 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -52421,6 +52421,7 @@ var ts; deleteConstEnumRelate: function (path) { constEnumRelate && constEnumRelate.delete(path); }, clearQualifiedNameCache: function () { qualifiedNameCache && qualifiedNameCache.clear(); }, getCheckedSourceFiles: function () { return checkedSourceFiles; }, + collectHaveTsNoCheckFilesForLinter: function (sourceFile) { isTypeCheckerForLinter && checkedSourceFiles.add(sourceFile); }, getTypeArgumentsForResolvedSignature: getTypeArgumentsForResolvedSignature, }; function getTypeArgumentsForResolvedSignature(signature) { @@ -124864,6 +124865,13 @@ var ts; var includeBindAndCheckDiagnostics = !isTsNoCheck && (sourceFile.scriptKind === 3 /* ScriptKind.TS */ || sourceFile.scriptKind === 4 /* ScriptKind.TSX */ || sourceFile.scriptKind === 5 /* ScriptKind.External */ || isPlainJs || isCheckJs || sourceFile.scriptKind === 7 /* ScriptKind.Deferred */ || sourceFile.scriptKind === 8 /* ScriptKind.ETS */); var bindDiagnostics = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : ts.emptyArray; + if (!includeBindAndCheckDiagnostics) { + // Record that this file has @ts-nocheck directive for ArkTS linter check + typeChecker.collectHaveTsNoCheckFilesForLinter(sourceFile); + } + // Get the type checking diagnostics for this file: + // - If diagnostics are enabled: get all type checking errors/warnings + // - If disabled (due to @ts-nocheck or other reasons): return empty array var checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : ts.emptyArray; if (isPlainJs) { bindDiagnostics = ts.filter(bindDiagnostics, function (d) { return ts.plainJSErrors.has(d.code); }); diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index fd484321a4..b86d15474f 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -2546,6 +2546,7 @@ declare namespace ts { getTypeArgumentsForResolvedSignature(signature: Signature): readonly Type[] | undefined; clearQualifiedNameCache?(): void; getCheckedSourceFiles(): Set; + collectHaveTsNoCheckFilesForLinter(sourceFile: SourceFile): void; } export enum NodeBuilderFlags { None = 0, diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index fd0d4dfbd9..5d3587cedc 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -52420,6 +52420,7 @@ var ts; deleteConstEnumRelate: function (path) { constEnumRelate && constEnumRelate.delete(path); }, clearQualifiedNameCache: function () { qualifiedNameCache && qualifiedNameCache.clear(); }, getCheckedSourceFiles: function () { return checkedSourceFiles; }, + collectHaveTsNoCheckFilesForLinter: function (sourceFile) { isTypeCheckerForLinter && checkedSourceFiles.add(sourceFile); }, getTypeArgumentsForResolvedSignature: getTypeArgumentsForResolvedSignature, }; function getTypeArgumentsForResolvedSignature(signature) { @@ -124863,6 +124864,13 @@ var ts; var includeBindAndCheckDiagnostics = !isTsNoCheck && (sourceFile.scriptKind === 3 /* ScriptKind.TS */ || sourceFile.scriptKind === 4 /* ScriptKind.TSX */ || sourceFile.scriptKind === 5 /* ScriptKind.External */ || isPlainJs || isCheckJs || sourceFile.scriptKind === 7 /* ScriptKind.Deferred */ || sourceFile.scriptKind === 8 /* ScriptKind.ETS */); var bindDiagnostics = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : ts.emptyArray; + if (!includeBindAndCheckDiagnostics) { + // Record that this file has @ts-nocheck directive for ArkTS linter check + typeChecker.collectHaveTsNoCheckFilesForLinter(sourceFile); + } + // Get the type checking diagnostics for this file: + // - If diagnostics are enabled: get all type checking errors/warnings + // - If disabled (due to @ts-nocheck or other reasons): return empty array var checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : ts.emptyArray; if (isPlainJs) { bindDiagnostics = ts.filter(bindDiagnostics, function (d) { return ts.plainJSErrors.has(d.code); }); diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index dd5db7f11f..6a74eb1412 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -2546,6 +2546,7 @@ declare namespace ts { getTypeArgumentsForResolvedSignature(signature: Signature): readonly Type[] | undefined; clearQualifiedNameCache?(): void; getCheckedSourceFiles(): Set; + collectHaveTsNoCheckFilesForLinter(sourceFile: SourceFile): void; } export enum NodeBuilderFlags { None = 0, diff --git a/lib/typescript.js b/lib/typescript.js index ad38dd9049..805ed32e84 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -52411,6 +52411,7 @@ var ts; deleteConstEnumRelate: function (path) { constEnumRelate && constEnumRelate.delete(path); }, clearQualifiedNameCache: function () { qualifiedNameCache && qualifiedNameCache.clear(); }, getCheckedSourceFiles: function () { return checkedSourceFiles; }, + collectHaveTsNoCheckFilesForLinter: function (sourceFile) { isTypeCheckerForLinter && checkedSourceFiles.add(sourceFile); }, getTypeArgumentsForResolvedSignature: getTypeArgumentsForResolvedSignature, }; function getTypeArgumentsForResolvedSignature(signature) { @@ -124854,6 +124855,13 @@ var ts; var includeBindAndCheckDiagnostics = !isTsNoCheck && (sourceFile.scriptKind === 3 /* ScriptKind.TS */ || sourceFile.scriptKind === 4 /* ScriptKind.TSX */ || sourceFile.scriptKind === 5 /* ScriptKind.External */ || isPlainJs || isCheckJs || sourceFile.scriptKind === 7 /* ScriptKind.Deferred */ || sourceFile.scriptKind === 8 /* ScriptKind.ETS */); var bindDiagnostics = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : ts.emptyArray; + if (!includeBindAndCheckDiagnostics) { + // Record that this file has @ts-nocheck directive for ArkTS linter check + typeChecker.collectHaveTsNoCheckFilesForLinter(sourceFile); + } + // Get the type checking diagnostics for this file: + // - If diagnostics are enabled: get all type checking errors/warnings + // - If disabled (due to @ts-nocheck or other reasons): return empty array var checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : ts.emptyArray; if (isPlainJs) { bindDiagnostics = ts.filter(bindDiagnostics, function (d) { return ts.plainJSErrors.has(d.code); }); diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index ce5e9eab78..a273ee24d7 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -2546,6 +2546,7 @@ declare namespace ts { getTypeArgumentsForResolvedSignature(signature: Signature): readonly Type[] | undefined; clearQualifiedNameCache?(): void; getCheckedSourceFiles(): Set; + collectHaveTsNoCheckFilesForLinter(sourceFile: SourceFile): void; } export enum NodeBuilderFlags { None = 0, diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 551bd49576..c3916ec18f 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -52411,6 +52411,7 @@ var ts; deleteConstEnumRelate: function (path) { constEnumRelate && constEnumRelate.delete(path); }, clearQualifiedNameCache: function () { qualifiedNameCache && qualifiedNameCache.clear(); }, getCheckedSourceFiles: function () { return checkedSourceFiles; }, + collectHaveTsNoCheckFilesForLinter: function (sourceFile) { isTypeCheckerForLinter && checkedSourceFiles.add(sourceFile); }, getTypeArgumentsForResolvedSignature: getTypeArgumentsForResolvedSignature, }; function getTypeArgumentsForResolvedSignature(signature) { @@ -124854,6 +124855,13 @@ var ts; var includeBindAndCheckDiagnostics = !isTsNoCheck && (sourceFile.scriptKind === 3 /* ScriptKind.TS */ || sourceFile.scriptKind === 4 /* ScriptKind.TSX */ || sourceFile.scriptKind === 5 /* ScriptKind.External */ || isPlainJs || isCheckJs || sourceFile.scriptKind === 7 /* ScriptKind.Deferred */ || sourceFile.scriptKind === 8 /* ScriptKind.ETS */); var bindDiagnostics = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : ts.emptyArray; + if (!includeBindAndCheckDiagnostics) { + // Record that this file has @ts-nocheck directive for ArkTS linter check + typeChecker.collectHaveTsNoCheckFilesForLinter(sourceFile); + } + // Get the type checking diagnostics for this file: + // - If diagnostics are enabled: get all type checking errors/warnings + // - If disabled (due to @ts-nocheck or other reasons): return empty array var checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : ts.emptyArray; if (isPlainJs) { bindDiagnostics = ts.filter(bindDiagnostics, function (d) { return ts.plainJSErrors.has(d.code); }); diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 6b21cc6c4a..0f22525e48 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -52401,6 +52401,7 @@ var ts; deleteConstEnumRelate: function (path) { constEnumRelate && constEnumRelate.delete(path); }, clearQualifiedNameCache: function () { qualifiedNameCache && qualifiedNameCache.clear(); }, getCheckedSourceFiles: function () { return checkedSourceFiles; }, + collectHaveTsNoCheckFilesForLinter: function (sourceFile) { isTypeCheckerForLinter && checkedSourceFiles.add(sourceFile); }, getTypeArgumentsForResolvedSignature: getTypeArgumentsForResolvedSignature, }; function getTypeArgumentsForResolvedSignature(signature) { @@ -124844,6 +124845,13 @@ var ts; var includeBindAndCheckDiagnostics = !isTsNoCheck && (sourceFile.scriptKind === 3 /* ScriptKind.TS */ || sourceFile.scriptKind === 4 /* ScriptKind.TSX */ || sourceFile.scriptKind === 5 /* ScriptKind.External */ || isPlainJs || isCheckJs || sourceFile.scriptKind === 7 /* ScriptKind.Deferred */ || sourceFile.scriptKind === 8 /* ScriptKind.ETS */); var bindDiagnostics = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : ts.emptyArray; + if (!includeBindAndCheckDiagnostics) { + // Record that this file has @ts-nocheck directive for ArkTS linter check + typeChecker.collectHaveTsNoCheckFilesForLinter(sourceFile); + } + // Get the type checking diagnostics for this file: + // - If diagnostics are enabled: get all type checking errors/warnings + // - If disabled (due to @ts-nocheck or other reasons): return empty array var checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : ts.emptyArray; if (isPlainJs) { bindDiagnostics = ts.filter(bindDiagnostics, function (d) { return ts.plainJSErrors.has(d.code); }); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 28648286be..0338d9ef18 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -769,6 +769,7 @@ namespace ts { deleteConstEnumRelate: (path: string) => {constEnumRelate && constEnumRelate.delete(path)}, clearQualifiedNameCache: () => {qualifiedNameCache && qualifiedNameCache.clear()}, getCheckedSourceFiles: () => checkedSourceFiles, + collectHaveTsNoCheckFilesForLinter: (sourceFile: SourceFile) => {isTypeCheckerForLinter && checkedSourceFiles.add(sourceFile)}, getTypeArgumentsForResolvedSignature, }; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index d76f4f3558..42823a2dea 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2347,6 +2347,13 @@ namespace ts { const includeBindAndCheckDiagnostics = !isTsNoCheck && (sourceFile.scriptKind === ScriptKind.TS || sourceFile.scriptKind === ScriptKind.TSX || sourceFile.scriptKind === ScriptKind.External || isPlainJs || isCheckJs || sourceFile.scriptKind === ScriptKind.Deferred || sourceFile.scriptKind === ScriptKind.ETS); let bindDiagnostics: readonly Diagnostic[] = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : emptyArray; + if (!includeBindAndCheckDiagnostics) { + // Record that this file has @ts-nocheck directive for ArkTS linter check + typeChecker.collectHaveTsNoCheckFilesForLinter(sourceFile); + } + // Get the type checking diagnostics for this file: + // - If diagnostics are enabled: get all type checking errors/warnings + // - If disabled (due to @ts-nocheck or other reasons): return empty array let checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : emptyArray; if (isPlainJs) { bindDiagnostics = filter(bindDiagnostics, d => plainJSErrors.has(d.code)); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9930f8b899..a31fcebda4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4987,6 +4987,7 @@ namespace ts { getTypeArgumentsForResolvedSignature(signature: Signature): readonly Type[] | undefined; clearQualifiedNameCache?(): void; getCheckedSourceFiles(): Set; + collectHaveTsNoCheckFilesForLinter(sourceFile: SourceFile): void; } /* @internal */ diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index fd484321a4..b86d15474f 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2546,6 +2546,7 @@ declare namespace ts { getTypeArgumentsForResolvedSignature(signature: Signature): readonly Type[] | undefined; clearQualifiedNameCache?(): void; getCheckedSourceFiles(): Set; + collectHaveTsNoCheckFilesForLinter(sourceFile: SourceFile): void; } export enum NodeBuilderFlags { None = 0, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index dd5db7f11f..6a74eb1412 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2546,6 +2546,7 @@ declare namespace ts { getTypeArgumentsForResolvedSignature(signature: Signature): readonly Type[] | undefined; clearQualifiedNameCache?(): void; getCheckedSourceFiles(): Set; + collectHaveTsNoCheckFilesForLinter(sourceFile: SourceFile): void; } export enum NodeBuilderFlags { None = 0, -- Gitee From 4aa2f8caa883adec785ed81d5555e5c4cc4b9b0b Mon Sep 17 00:00:00 2001 From: c30058867 Date: Tue, 15 Apr 2025 21:13:52 +0800 Subject: [PATCH 2/2] Retain the full logic Issue:https://gitee.com/openharmony/third_party_typescript/issues/IC1FJ5 Signed-off-by: caiy --- lib/tsserver.js | 13 +++++++++++++ lib/tsserverlibrary.js | 13 +++++++++++++ lib/typescript.js | 13 +++++++++++++ lib/typescriptServices.js | 13 +++++++++++++ src/linter/ArkTSLinter_1_1/LinterRunner.ts | 17 ++++++++++++++++- 5 files changed, 68 insertions(+), 1 deletion(-) diff --git a/lib/tsserver.js b/lib/tsserver.js index 9ad0643d78..1f8dc2acce 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -201362,6 +201362,7 @@ var ts; ArkTSLinter_1_1.LibraryTypeCallDiagnosticCheckerNamespace.LibraryTypeCallDiagnosticChecker.instance.clear(); } function collectChangedFilesFromProgramState(state, tsTypeChecker, arkTSVersion, compatibleSdkVersion, compatibleSdkVersionStage) { + var changedFiles = new ts.Set(state.changedFilesSet); // If old arkTSVersion from last run is not same current arkTSVersion from ets_loader, // the process all files in project. // The compatibleSdkVersion and compatibleSdkVersionStage is the same as arkTSVersion @@ -201370,6 +201371,18 @@ var ts; state.compatibleSdkVersionStage !== compatibleSdkVersionStage) { return new ts.Set(ts.arrayFrom(state.fileInfos.keys())); } + // If any source file that affects global scope has been changed, + // then process all files in project. + for (var _i = 0, _a = ts.arrayFrom(changedFiles.keys()); _i < _a.length; _i++) { + var changedFile = _a[_i]; + var fileInfo = state.fileInfos.get(changedFile); + if (fileInfo === null || fileInfo === void 0 ? void 0 : fileInfo.affectsGlobalScope) { + return new ts.Set(ts.arrayFrom(state.fileInfos.keys())); + } + } + if (!state.referencedMap) { + return changedFiles; + } var changeSources = tsTypeChecker.getCheckedSourceFiles(); var targetSet = new ts.Set(); changeSources.forEach(function (x) { return targetSet.add(x.path); }); diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 5d3587cedc..b4c7798f23 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -201107,6 +201107,7 @@ var ts; ArkTSLinter_1_1.LibraryTypeCallDiagnosticCheckerNamespace.LibraryTypeCallDiagnosticChecker.instance.clear(); } function collectChangedFilesFromProgramState(state, tsTypeChecker, arkTSVersion, compatibleSdkVersion, compatibleSdkVersionStage) { + var changedFiles = new ts.Set(state.changedFilesSet); // If old arkTSVersion from last run is not same current arkTSVersion from ets_loader, // the process all files in project. // The compatibleSdkVersion and compatibleSdkVersionStage is the same as arkTSVersion @@ -201115,6 +201116,18 @@ var ts; state.compatibleSdkVersionStage !== compatibleSdkVersionStage) { return new ts.Set(ts.arrayFrom(state.fileInfos.keys())); } + // If any source file that affects global scope has been changed, + // then process all files in project. + for (var _i = 0, _a = ts.arrayFrom(changedFiles.keys()); _i < _a.length; _i++) { + var changedFile = _a[_i]; + var fileInfo = state.fileInfos.get(changedFile); + if (fileInfo === null || fileInfo === void 0 ? void 0 : fileInfo.affectsGlobalScope) { + return new ts.Set(ts.arrayFrom(state.fileInfos.keys())); + } + } + if (!state.referencedMap) { + return changedFiles; + } var changeSources = tsTypeChecker.getCheckedSourceFiles(); var targetSet = new ts.Set(); changeSources.forEach(function (x) { return targetSet.add(x.path); }); diff --git a/lib/typescript.js b/lib/typescript.js index 805ed32e84..66909a24d8 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -190201,6 +190201,7 @@ var ts; ArkTSLinter_1_1.LibraryTypeCallDiagnosticCheckerNamespace.LibraryTypeCallDiagnosticChecker.instance.clear(); } function collectChangedFilesFromProgramState(state, tsTypeChecker, arkTSVersion, compatibleSdkVersion, compatibleSdkVersionStage) { + var changedFiles = new ts.Set(state.changedFilesSet); // If old arkTSVersion from last run is not same current arkTSVersion from ets_loader, // the process all files in project. // The compatibleSdkVersion and compatibleSdkVersionStage is the same as arkTSVersion @@ -190209,6 +190210,18 @@ var ts; state.compatibleSdkVersionStage !== compatibleSdkVersionStage) { return new ts.Set(ts.arrayFrom(state.fileInfos.keys())); } + // If any source file that affects global scope has been changed, + // then process all files in project. + for (var _i = 0, _a = ts.arrayFrom(changedFiles.keys()); _i < _a.length; _i++) { + var changedFile = _a[_i]; + var fileInfo = state.fileInfos.get(changedFile); + if (fileInfo === null || fileInfo === void 0 ? void 0 : fileInfo.affectsGlobalScope) { + return new ts.Set(ts.arrayFrom(state.fileInfos.keys())); + } + } + if (!state.referencedMap) { + return changedFiles; + } var changeSources = tsTypeChecker.getCheckedSourceFiles(); var targetSet = new ts.Set(); changeSources.forEach(function (x) { return targetSet.add(x.path); }); diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index c3916ec18f..ed6f3541fa 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -190201,6 +190201,7 @@ var ts; ArkTSLinter_1_1.LibraryTypeCallDiagnosticCheckerNamespace.LibraryTypeCallDiagnosticChecker.instance.clear(); } function collectChangedFilesFromProgramState(state, tsTypeChecker, arkTSVersion, compatibleSdkVersion, compatibleSdkVersionStage) { + var changedFiles = new ts.Set(state.changedFilesSet); // If old arkTSVersion from last run is not same current arkTSVersion from ets_loader, // the process all files in project. // The compatibleSdkVersion and compatibleSdkVersionStage is the same as arkTSVersion @@ -190209,6 +190210,18 @@ var ts; state.compatibleSdkVersionStage !== compatibleSdkVersionStage) { return new ts.Set(ts.arrayFrom(state.fileInfos.keys())); } + // If any source file that affects global scope has been changed, + // then process all files in project. + for (var _i = 0, _a = ts.arrayFrom(changedFiles.keys()); _i < _a.length; _i++) { + var changedFile = _a[_i]; + var fileInfo = state.fileInfos.get(changedFile); + if (fileInfo === null || fileInfo === void 0 ? void 0 : fileInfo.affectsGlobalScope) { + return new ts.Set(ts.arrayFrom(state.fileInfos.keys())); + } + } + if (!state.referencedMap) { + return changedFiles; + } var changeSources = tsTypeChecker.getCheckedSourceFiles(); var targetSet = new ts.Set(); changeSources.forEach(function (x) { return targetSet.add(x.path); }); diff --git a/src/linter/ArkTSLinter_1_1/LinterRunner.ts b/src/linter/ArkTSLinter_1_1/LinterRunner.ts index 91ee094565..51dceada00 100644 --- a/src/linter/ArkTSLinter_1_1/LinterRunner.ts +++ b/src/linter/ArkTSLinter_1_1/LinterRunner.ts @@ -165,6 +165,8 @@ function collectChangedFilesFromProgramState( compatibleSdkVersion?: number, compatibleSdkVersionStage?: string ): Set { + const changedFiles = new Set(state.changedFilesSet); + // If old arkTSVersion from last run is not same current arkTSVersion from ets_loader, // the process all files in project. // The compatibleSdkVersion and compatibleSdkVersionStage is the same as arkTSVersion @@ -175,7 +177,20 @@ function collectChangedFilesFromProgramState( ) { return new Set(arrayFrom(state.fileInfos.keys())); } - + + // If any source file that affects global scope has been changed, + // then process all files in project. + for (const changedFile of arrayFrom(changedFiles.keys())) { + const fileInfo = state.fileInfos.get(changedFile); + if (fileInfo?.affectsGlobalScope) { + return new Set(arrayFrom(state.fileInfos.keys())); + } + } + + if (!state.referencedMap) { + return changedFiles; + } + const changeSources = tsTypeChecker.getCheckedSourceFiles(); const targetSet = new Set(); changeSources.forEach(x => targetSet.add(x.path)); -- Gitee