mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-20 02:08:47 +00:00
Fixes #270408 Trying to move some of the monaco related checks/tconfigs off of `moduleResolution: classic`. This legacy config is causing a lot of pain while trying to update the trusted-types typings, which is itself blocking picking up the latest dompurify I initially tried a more scoped change but just could not get it working. So instead I ended up trying to rework our `LanguageServiceHost` to be more standard
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import ts from 'typescript';
|
|
import fs from 'node:fs';
|
|
// import path from 'node:path';
|
|
|
|
export type IFileMap = Map</*fileName*/ string, string>;
|
|
|
|
/**
|
|
* A TypeScript language service host
|
|
*/
|
|
export class TypeScriptLanguageServiceHost implements ts.LanguageServiceHost {
|
|
|
|
constructor(
|
|
private readonly ts: typeof import('typescript'),
|
|
private readonly topLevelFiles: IFileMap,
|
|
private readonly compilerOptions: ts.CompilerOptions,
|
|
) { }
|
|
|
|
// --- language service host ---------------
|
|
getCompilationSettings(): ts.CompilerOptions {
|
|
return this.compilerOptions;
|
|
}
|
|
getScriptFileNames(): string[] {
|
|
return [
|
|
...this.topLevelFiles.keys(),
|
|
this.ts.getDefaultLibFilePath(this.compilerOptions)
|
|
];
|
|
}
|
|
getScriptVersion(_fileName: string): string {
|
|
return '1';
|
|
}
|
|
getProjectVersion(): string {
|
|
return '1';
|
|
}
|
|
getScriptSnapshot(fileName: string): ts.IScriptSnapshot {
|
|
if (this.topLevelFiles.has(fileName)) {
|
|
return this.ts.ScriptSnapshot.fromString(this.topLevelFiles.get(fileName)!);
|
|
} else {
|
|
return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString());
|
|
}
|
|
}
|
|
getScriptKind(_fileName: string): ts.ScriptKind {
|
|
return this.ts.ScriptKind.TS;
|
|
}
|
|
getCurrentDirectory(): string {
|
|
return '';
|
|
}
|
|
getDefaultLibFileName(_options: ts.CompilerOptions): string {
|
|
return this.ts.getDefaultLibFilePath(_options);
|
|
}
|
|
readFile(path: string, _encoding?: string): string | undefined {
|
|
if (this.topLevelFiles.get(path)) {
|
|
return this.topLevelFiles.get(path);
|
|
}
|
|
return ts.sys.readFile(path, _encoding);
|
|
}
|
|
fileExists(path: string): boolean {
|
|
if (this.topLevelFiles.has(path)) {
|
|
return true;
|
|
}
|
|
return ts.sys.fileExists(path);
|
|
}
|
|
}
|