From c7e47ca80ea3b81d531648c4861b18bb7bf6ddfa Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 25 Mar 2024 16:16:28 -0700 Subject: [PATCH] Allow --withIncrementalVerifier to pass on commandline to tsserver to run incremental verification --- src/harness/harnessLanguageService.ts | 6 +++--- src/harness/tsconfig.json | 3 ++- src/incrementalVerifier/_namespaces/ts.server.ts | 4 ++++ src/incrementalVerifier/_namespaces/ts.ts | 9 +++++++++ src/incrementalVerifier/tsconfig.json | 10 ++++++++++ .../verifier.ts} | 5 +++++ src/testRunner/tsconfig.json | 1 + src/testRunner/unittests/helpers/tscWatch.ts | 2 +- src/testRunner/unittests/helpers/tsserver.ts | 6 +++--- src/testRunner/unittests/services/extract/helpers.ts | 6 +++--- .../unittests/tsserver/cachingFileSystemInformation.ts | 6 +++--- src/testRunner/unittests/tsserver/documentRegistry.ts | 2 +- src/testRunner/unittests/tsserver/session.ts | 6 +++--- src/tsconfig.json | 1 + src/tsserver/nodeServer.ts | 4 +++- src/typescript/_namespaces/ts.ts | 1 + src/typescript/tsconfig.json | 3 ++- 17 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 src/incrementalVerifier/_namespaces/ts.server.ts create mode 100644 src/incrementalVerifier/_namespaces/ts.ts create mode 100644 src/incrementalVerifier/tsconfig.json rename src/{harness/incrementalUtils.ts => incrementalVerifier/verifier.ts} (97%) diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 3bab845bbdd..2177ca3e9e4 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -1,3 +1,6 @@ +import { + incrementalVerifier, +} from "../incrementalVerifier/verifier"; import * as collections from "./_namespaces/collections"; import * as fakes from "./_namespaces/fakes"; import { @@ -11,9 +14,6 @@ import { } from "./_namespaces/ts"; import * as vfs from "./_namespaces/vfs"; import * as vpath from "./_namespaces/vpath"; -import { - incrementalVerifier, -} from "./incrementalUtils"; import { patchServiceForStateBaseline, } from "./projectServiceStateLogger"; diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index f95c91b8c8a..65d7ad03cd6 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -13,7 +13,8 @@ { "path": "../jsTyping" }, { "path": "../server" }, { "path": "../typingsInstallerCore" }, - { "path": "../deprecatedCompat" } + { "path": "../deprecatedCompat" }, + { "path": "../incrementalVerifier" } ], "include": ["**/*"] diff --git a/src/incrementalVerifier/_namespaces/ts.server.ts b/src/incrementalVerifier/_namespaces/ts.server.ts new file mode 100644 index 00000000000..21b0d0335fb --- /dev/null +++ b/src/incrementalVerifier/_namespaces/ts.server.ts @@ -0,0 +1,4 @@ +/* Generated file to emulate the ts.server namespace. */ + +export * from "../../jsTyping/_namespaces/ts.server"; +export * from "../../server/_namespaces/ts.server"; diff --git a/src/incrementalVerifier/_namespaces/ts.ts b/src/incrementalVerifier/_namespaces/ts.ts new file mode 100644 index 00000000000..623b658db5d --- /dev/null +++ b/src/incrementalVerifier/_namespaces/ts.ts @@ -0,0 +1,9 @@ +/* Generated file to emulate the ts namespace. */ + +export * from "../../compiler/_namespaces/ts"; +export * from "../../jsTyping/_namespaces/ts"; +export * from "../../services/_namespaces/ts"; +export * from "../../server/_namespaces/ts"; +export * from "../verifier"; +import * as server from "./ts.server"; +export { server }; diff --git a/src/incrementalVerifier/tsconfig.json b/src/incrementalVerifier/tsconfig.json new file mode 100644 index 00000000000..9b54d2bdb9c --- /dev/null +++ b/src/incrementalVerifier/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../tsconfig-base", + "references": [ + { "path": "../compiler" }, + { "path": "../jsTyping" }, + { "path": "../services" }, + { "path": "../server" } + ], + "include": ["**/*"] +} diff --git a/src/harness/incrementalUtils.ts b/src/incrementalVerifier/verifier.ts similarity index 97% rename from src/harness/incrementalUtils.ts rename to src/incrementalVerifier/verifier.ts index 8a361aa4a9f..3387a25027c 100644 --- a/src/harness/incrementalUtils.ts +++ b/src/incrementalVerifier/verifier.ts @@ -1,5 +1,6 @@ import * as ts from "./_namespaces/ts"; +/** @internal */ export function reportDocumentRegistryStats(documentRegistry: ts.DocumentRegistry) { const str: string[] = []; documentRegistry.getBuckets().forEach((bucketEntries, key) => { @@ -193,12 +194,14 @@ function getProgramStructure(program: ts.Program | undefined) { return baseline.join("\n"); } +/** @internal */ export function verifyProgramStructure(expectedProgram: ts.Program, actualProgram: ts.Program, projectName: string) { const actual = getProgramStructure(actualProgram); const expected = getProgramStructure(expectedProgram); ts.Debug.assert(actual === expected, `Program verification:: ${projectName}`); } +/** @internal */ export function verifyResolutionCache( actual: ts.ResolutionCache, actualProgram: ts.Program, @@ -583,11 +586,13 @@ function onProjectCreation(project: ts.server.Project) { (project as ts.ResolutionCacheHost).afterResolveSingleModuleNameWithoutWatching = afterResolveSingleModuleNameWithoutWatching; } +/** @internal */ export interface IncrementalVerifierCallbacks { beforeVerification?(): any; afterVerification?(dataFromBefore: any): void; } +/** @internal */ export function incrementalVerifier(service: ts.server.ProjectService) { service.verifyDocumentRegistry = withIncrementalVerifierCallbacks(service, verifyDocumentRegistry); service.verifyProgram = withIncrementalVerifierCallbacks(service, verifyProgram); diff --git a/src/testRunner/tsconfig.json b/src/testRunner/tsconfig.json index 29d2f351b62..04f5d90feb2 100644 --- a/src/testRunner/tsconfig.json +++ b/src/testRunner/tsconfig.json @@ -15,6 +15,7 @@ { "path": "../server" }, { "path": "../typingsInstallerCore" }, { "path": "../deprecatedCompat" }, + { "path": "../incrementalVerifier" }, { "path": "../harness" } ], "include": ["**/*"] diff --git a/src/testRunner/unittests/helpers/tscWatch.ts b/src/testRunner/unittests/helpers/tscWatch.ts index 554c3fc37b0..d02b478f190 100644 --- a/src/testRunner/unittests/helpers/tscWatch.ts +++ b/src/testRunner/unittests/helpers/tscWatch.ts @@ -1,7 +1,7 @@ import { verifyProgramStructure, verifyResolutionCache, -} from "../../../harness/incrementalUtils"; +} from "../../../incrementalVerifier/verifier"; import { patchHostForBuildInfoReadWrite, } from "../../_namespaces/fakes"; diff --git a/src/testRunner/unittests/helpers/tsserver.ts b/src/testRunner/unittests/helpers/tsserver.ts index d206ac66028..58a2aa2ca1d 100644 --- a/src/testRunner/unittests/helpers/tsserver.ts +++ b/src/testRunner/unittests/helpers/tsserver.ts @@ -1,6 +1,3 @@ -import { - incrementalVerifier, -} from "../../../harness/incrementalUtils"; import { patchServiceForStateBaseline, } from "../../../harness/projectServiceStateLogger"; @@ -8,6 +5,9 @@ import { createLoggerWithInMemoryLogs, LoggerWithInMemoryLogs, } from "../../../harness/tsserverLogger"; +import { + incrementalVerifier, +} from "../../../incrementalVerifier/verifier"; import * as Harness from "../../_namespaces/Harness"; import * as ts from "../../_namespaces/ts"; import { diff --git a/src/testRunner/unittests/services/extract/helpers.ts b/src/testRunner/unittests/services/extract/helpers.ts index 5f5c8b14197..4193d26be7f 100644 --- a/src/testRunner/unittests/services/extract/helpers.ts +++ b/src/testRunner/unittests/services/extract/helpers.ts @@ -1,9 +1,9 @@ -import { - incrementalVerifier, -} from "../../../../harness/incrementalUtils"; import { createHasErrorMessageLogger, } from "../../../../harness/tsserverLogger"; +import { + incrementalVerifier, +} from "../../../../incrementalVerifier/verifier"; import * as Harness from "../../../_namespaces/Harness"; import * as ts from "../../../_namespaces/ts"; import { diff --git a/src/testRunner/unittests/tsserver/cachingFileSystemInformation.ts b/src/testRunner/unittests/tsserver/cachingFileSystemInformation.ts index 184da488e05..fec733c617c 100644 --- a/src/testRunner/unittests/tsserver/cachingFileSystemInformation.ts +++ b/src/testRunner/unittests/tsserver/cachingFileSystemInformation.ts @@ -1,9 +1,9 @@ -import { - IncrementalVerifierCallbacks, -} from "../../../harness/incrementalUtils"; import { LoggerWithInMemoryLogs, } from "../../../harness/tsserverLogger"; +import { + IncrementalVerifierCallbacks, +} from "../../../incrementalVerifier/verifier"; import * as ts from "../../_namespaces/ts"; import { jsonToReadableText, diff --git a/src/testRunner/unittests/tsserver/documentRegistry.ts b/src/testRunner/unittests/tsserver/documentRegistry.ts index 01f9dfc1242..4cc1ad73ff2 100644 --- a/src/testRunner/unittests/tsserver/documentRegistry.ts +++ b/src/testRunner/unittests/tsserver/documentRegistry.ts @@ -1,6 +1,6 @@ import { reportDocumentRegistryStats, -} from "../../../harness/incrementalUtils"; +} from "../../../incrementalVerifier/verifier"; import * as ts from "../../_namespaces/ts"; import { jsonToReadableText, diff --git a/src/testRunner/unittests/tsserver/session.ts b/src/testRunner/unittests/tsserver/session.ts index 6fb2fb4f4ed..44d298257f0 100644 --- a/src/testRunner/unittests/tsserver/session.ts +++ b/src/testRunner/unittests/tsserver/session.ts @@ -2,13 +2,13 @@ import { expect, } from "chai"; -import { - incrementalVerifier, -} from "../../../harness/incrementalUtils"; import { createHasErrorMessageLogger, nullLogger, } from "../../../harness/tsserverLogger"; +import { + incrementalVerifier, +} from "../../../incrementalVerifier/verifier"; import * as Harness from "../../_namespaces/Harness"; import * as ts from "../../_namespaces/ts"; diff --git a/src/tsconfig.json b/src/tsconfig.json index c585d3480f2..cd5c7d12a9f 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -7,6 +7,7 @@ { "path": "./deprecatedCompat" }, { "path": "./executeCommandLine" }, { "path": "./harness" }, + { "path": "./incrementalVerifier" }, { "path": "./jsTyping" }, { "path": "./server" }, { "path": "./services" }, diff --git a/src/tsserver/nodeServer.ts b/src/tsserver/nodeServer.ts index ce0a7e44e58..f453d89c7d9 100644 --- a/src/tsserver/nodeServer.ts +++ b/src/tsserver/nodeServer.ts @@ -8,6 +8,7 @@ import { FileWatcher, getDirectoryPath, getRootLength, + incrementalVerifier, LanguageServiceMode, MapLike, noop, @@ -30,7 +31,6 @@ import { StartInput, StartSessionOptions, } from "./common"; - interface LogOptions { file?: string; detailLevel?: ts.server.LogLevel; @@ -589,6 +589,7 @@ function startNodeSession(options: StartSessionOptions, logger: ts.server.Logger logger, canUseEvents: true, typesMapLocation, + incrementalVerifier: withIncrementalVerifier ? incrementalVerifier : undefined, }); this.eventPort = eventPort; @@ -689,6 +690,7 @@ function startNodeSession(options: StartSessionOptions, logger: ts.server.Logger const validateDefaultNpmLocation = ts.server.hasArgument(ts.server.Arguments.ValidateDefaultNpmLocation); const disableAutomaticTypingAcquisition = ts.server.hasArgument("--disableAutomaticTypingAcquisition"); const useNodeIpc = ts.server.hasArgument("--useNodeIpc"); + const withIncrementalVerifier = ts.server.hasArgument("--withIncrementalVerifier"); const telemetryEnabled = ts.server.hasArgument(ts.server.Arguments.EnableTelemetry); const commandLineTraceDir = ts.server.findArgument("--traceDirectory"); const traceDir = commandLineTraceDir diff --git a/src/typescript/_namespaces/ts.ts b/src/typescript/_namespaces/ts.ts index 3060a643787..a5579c21770 100644 --- a/src/typescript/_namespaces/ts.ts +++ b/src/typescript/_namespaces/ts.ts @@ -4,5 +4,6 @@ export * from "../../compiler/_namespaces/ts"; export * from "../../jsTyping/_namespaces/ts"; export * from "../../services/_namespaces/ts"; export * from "../../server/_namespaces/ts"; +export * from "../../incrementalVerifier/_namespaces/ts"; import * as server from "./ts.server"; export { server }; diff --git a/src/typescript/tsconfig.json b/src/typescript/tsconfig.json index 20b8306af53..dad822528cd 100644 --- a/src/typescript/tsconfig.json +++ b/src/typescript/tsconfig.json @@ -6,7 +6,8 @@ { "path": "../compiler" }, { "path": "../jsTyping" }, { "path": "../services" }, - { "path": "../server" } + { "path": "../server" }, + { "path": "../incrementalVerifier" } ], "include": ["**/*"] }