mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-16 17:59:49 -06:00
* Run our build scripts directly as typescript #277567 Follow up on #276864 For #277526 * Remove a few more ts-node references * Fix linux and script reference * Remove `_build-script` ref * Fix script missing closing quote * use type only import * Fix export * Make sure to run copy-policy-dto * Make sure we run the copy-policy-dto script * Enable `verbatimModuleSyntax` * Pipelines fixes * Try adding explicit ext to path * Fix bad edit * Revert extra `--` --------- Co-authored-by: João Moreno <joaomoreno@users.noreply.github.com>
65 lines
2.2 KiB
TypeScript
65 lines
2.2 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 path from 'path';
|
|
|
|
export class StaticLanguageServiceHost implements ts.LanguageServiceHost {
|
|
|
|
private readonly _cmdLine: ts.ParsedCommandLine;
|
|
private readonly _scriptSnapshots: Map<string, ts.IScriptSnapshot> = new Map();
|
|
readonly projectPath: string;
|
|
|
|
constructor(projectPath: string) {
|
|
this.projectPath = projectPath;
|
|
const existingOptions: Partial<ts.CompilerOptions> = {};
|
|
const parsed = ts.readConfigFile(projectPath, ts.sys.readFile);
|
|
if (parsed.error) {
|
|
throw parsed.error;
|
|
}
|
|
this._cmdLine = ts.parseJsonConfigFileContent(parsed.config, ts.sys, path.dirname(projectPath), existingOptions);
|
|
if (this._cmdLine.errors.length > 0) {
|
|
throw parsed.error;
|
|
}
|
|
}
|
|
getCompilationSettings(): ts.CompilerOptions {
|
|
return this._cmdLine.options;
|
|
}
|
|
getScriptFileNames(): string[] {
|
|
return this._cmdLine.fileNames;
|
|
}
|
|
getScriptVersion(_fileName: string): string {
|
|
return '1';
|
|
}
|
|
getProjectVersion(): string {
|
|
return '1';
|
|
}
|
|
getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined {
|
|
let result: ts.IScriptSnapshot | undefined = this._scriptSnapshots.get(fileName);
|
|
if (result === undefined) {
|
|
const content = ts.sys.readFile(fileName);
|
|
if (content === undefined) {
|
|
return undefined;
|
|
}
|
|
result = ts.ScriptSnapshot.fromString(content);
|
|
this._scriptSnapshots.set(fileName, result);
|
|
}
|
|
return result;
|
|
}
|
|
getCurrentDirectory(): string {
|
|
return path.dirname(this.projectPath);
|
|
}
|
|
getDefaultLibFileName(options: ts.CompilerOptions): string {
|
|
return ts.getDefaultLibFilePath(options);
|
|
}
|
|
directoryExists = ts.sys.directoryExists;
|
|
getDirectories = ts.sys.getDirectories;
|
|
fileExists = ts.sys.fileExists;
|
|
readFile = ts.sys.readFile;
|
|
readDirectory = ts.sys.readDirectory;
|
|
// this is necessary to make source references work.
|
|
realpath = ts.sys.realpath;
|
|
}
|