diff --git a/packages/eslint/index.ts b/packages/eslint/index.ts index 2ad199eb..b59346de 100644 --- a/packages/eslint/index.ts +++ b/packages/eslint/index.ts @@ -18,7 +18,7 @@ export function create(resolveConfig?: (program: ts.Program) => Linter.Config): const eslint = getEslint(languageService.getProgram()!); const lintResult = await eslint.lintText( document.getText(), - { filePath: context.env.typescript.uriToFileName(document.uri) }, + { filePath: context.env.typescript!.uriToFileName(document.uri) }, ); uriToLintResult.set(document.uri, lintResult); const diagnostics: Diagnostic[] = []; diff --git a/packages/markdown/index.ts b/packages/markdown/index.ts index 905274fc..7e122bd3 100644 --- a/packages/markdown/index.ts +++ b/packages/markdown/index.ts @@ -146,11 +146,11 @@ export function create(options: CreateOptions): ServicePlugin { const sync = () => { - if (!context.typescript) { + if (!context.language.typescript) { return; } - const { languageServiceHost } = context.typescript; + const { languageServiceHost } = context.language.typescript; const newProjectVersion = languageServiceHost.getProjectVersion?.(); const shouldUpdate = newProjectVersion === undefined || newProjectVersion !== lastProjectVersion; if (!shouldUpdate) { @@ -162,7 +162,7 @@ export function create(options: CreateOptions): ServicePlugin { const newVersions = new Map(); for (const fileName of languageServiceHost.getScriptFileNames()) { - const uri = context.env.typescript.fileNameToUri(fileName); + const uri = context.env.typescript!.fileNameToUri(fileName); const [_, sourceFile] = context.documents.getVirtualCodeByUri(uri); if (sourceFile?.generated) { for (const virtualCode of forEachEmbeddedCode(sourceFile.generated.code)) { @@ -335,7 +335,7 @@ export function create(options: CreateOptions): ServicePlugin { return context.documents.get(uri, virtualCode.languageId, virtualCode.snapshot); } } - const sourceFile = context.files.get(uri); + const sourceFile = context.language.files.get(uri); if (sourceFile) { return context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot); } diff --git a/packages/tslint/index.ts b/packages/tslint/index.ts index e4528005..752551b0 100644 --- a/packages/tslint/index.ts +++ b/packages/tslint/index.ts @@ -13,7 +13,7 @@ export function create(rules: IRule[]): ServicePlugin { provideSemanticDiagnostics(document, token) { const languageService = context.inject('typescript/languageService'); - const fileName = context.env.typescript.uriToFileName(document.uri); + const fileName = context.env.typescript!.uriToFileName(document.uri); const sourceFile = languageService.getProgram()?.getSourceFile(fileName); if (!sourceFile) { return; diff --git a/packages/typescript-twoslash-queries/index.ts b/packages/typescript-twoslash-queries/index.ts index 7dc2fc90..dba28a6a 100644 --- a/packages/typescript-twoslash-queries/index.ts +++ b/packages/typescript-twoslash-queries/index.ts @@ -21,7 +21,7 @@ export function create(): ServicePlugin { character: pointerPosition.character, }); - const fileName = context.env.typescript.uriToFileName(document.uri); + const fileName = context.env.typescript!.uriToFileName(document.uri); const quickInfo = languageService.getQuickInfoAtPosition(fileName, hoverOffset); if (quickInfo) { inlayHints.push({ diff --git a/packages/typescript/index.ts b/packages/typescript/index.ts index c6b48d58..5538a0b0 100644 --- a/packages/typescript/index.ts +++ b/packages/typescript/index.ts @@ -218,11 +218,11 @@ export function create(ts: typeof import('typescript')): ServicePlugin { snapshot: ts.ScriptSnapshot.fromString(''), }; - if (!context.typescript) { + if (!context.language.typescript) { return syntacticService; } - const { sys, languageServiceHost } = context.typescript; + const { sys, languageServiceHost } = context.language.typescript; const created = tsFaster.createLanguageService( ts, sys, @@ -259,7 +259,7 @@ export function create(ts: typeof import('typescript')): ServicePlugin { updateSourceScriptFileNames(); } for (const change of params.changes) { - const fileName = context.env.typescript.uriToFileName(change.uri); + const fileName = context.env.typescript!.uriToFileName(change.uri); if (sourceScriptNames.has(normalizeFileName(fileName))) { created.projectUpdated?.(languageServiceHost.getCurrentDirectory()); } @@ -269,8 +269,8 @@ export function create(ts: typeof import('typescript')): ServicePlugin { function updateSourceScriptFileNames() { sourceScriptNames.clear(); for (const fileName of languageServiceHost.getScriptFileNames()) { - const uri = context.env.typescript.fileNameToUri(fileName); - const sourceFile = context.files.get(uri); + const uri = context.env.typescript!.fileNameToUri(fileName); + const sourceFile = context.language.files.get(uri); if (sourceFile?.generated) { const tsCode = sourceFile.generated.languagePlugin.typescript?.getScript(sourceFile.generated.code); if (tsCode) { @@ -292,15 +292,15 @@ export function create(ts: typeof import('typescript')): ServicePlugin { uriToFileName: uri => { const [_virtualCode, file] = context.documents.getVirtualCodeByUri(uri); if (file) { - return context.env.typescript.uriToFileName(file.id); + return context.env.typescript!.uriToFileName(file.id); } else { - return context.env.typescript.uriToFileName(uri); + return context.env.typescript!.uriToFileName(uri); } }, fileNameToUri: fileName => { - const uri = context.env.typescript.fileNameToUri(fileName); - const file = context.files.get(uri); + const uri = context.env.typescript!.fileNameToUri(fileName); + const file = context.language.files.get(uri); if (file?.generated) { const script = file.generated.languagePlugin.typescript?.getScript(file.generated.code); if (script) { @@ -314,7 +314,7 @@ export function create(ts: typeof import('typescript')): ServicePlugin { if (virtualCode) { return context.documents.get(uri, virtualCode.languageId, virtualCode.snapshot); } - const sourceFile = context.files.get(uri); + const sourceFile = context.language.files.get(uri); if (sourceFile) { return context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot); } diff --git a/packages/typescript/lib/features/diagnostics.ts b/packages/typescript/lib/features/diagnostics.ts index 5ba20a52..ceb4afb2 100644 --- a/packages/typescript/lib/features/diagnostics.ts +++ b/packages/typescript/lib/features/diagnostics.ts @@ -27,7 +27,7 @@ export function register(ctx: SharedContext) { const token: ts.CancellationToken = { isCancellationRequested() { - return ctx.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested() ?? false; + return ctx.language.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested() ?? false; }, throwIfCancellationRequested() { }, }; diff --git a/packages/typescript/lib/features/semanticTokens.ts b/packages/typescript/lib/features/semanticTokens.ts index 1412bb7f..5945e444 100644 --- a/packages/typescript/lib/features/semanticTokens.ts +++ b/packages/typescript/lib/features/semanticTokens.ts @@ -15,11 +15,11 @@ export function register(ctx: SharedContext) { const start = range ? document.offsetAt(range.start) : 0; const length = range ? (document.offsetAt(range.end) - start) : document.getText().length; - if (ctx.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested()) return; + if (ctx.language.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested()) return; const response2 = safeCall(() => ctx.languageService.getEncodedSyntacticClassifications(file, { start, length })); if (!response2) return; - if (ctx.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested()) return; + if (ctx.language.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested()) return; const response1 = safeCall(() => ctx.languageService.getEncodedSemanticClassifications(file, { start, length }, ts.SemanticClassificationFormat.TwentyTwenty)); if (!response1) return; diff --git a/packages/vetur/index.ts b/packages/vetur/index.ts index 7ee80f04..b6e700d3 100644 --- a/packages/vetur/index.ts +++ b/packages/vetur/index.ts @@ -135,7 +135,7 @@ export function create(): ServicePlugin { if (!packageJsonPath) { - let lastDirname = context.env.typescript.uriToFileName(document.uri); + let lastDirname = context.env.typescript!.uriToFileName(document.uri); while (true) {