mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
add RuntimeServerHost as Omit<ServerHost, FileServerHost>
This commit is contained in:
@@ -918,7 +918,7 @@ namespace Harness.LanguageService {
|
||||
const proxy = makeDefaultProxy(info);
|
||||
proxy.getSemanticDiagnostics = filename => {
|
||||
const prev = info.languageService.getSemanticDiagnostics(filename);
|
||||
const sourceFile: ts.SourceFile = info.project.getSourceFile(ts.toPath(filename, /*basePath*/ undefined, ts.createGetCanonicalFileName(info.serverHost.useCaseSensitiveFileNames)))!;
|
||||
const sourceFile: ts.SourceFile = info.project.getSourceFile(ts.toPath(filename, /*basePath*/ undefined, ts.createGetCanonicalFileName(info.fsHost.useCaseSensitiveFileNames)))!;
|
||||
prev.push({
|
||||
category: ts.DiagnosticCategory.Warning,
|
||||
file: sourceFile,
|
||||
@@ -945,7 +945,7 @@ namespace Harness.LanguageService {
|
||||
const proxy = makeDefaultProxy(info);
|
||||
proxy.getSemanticDiagnostics = filename => {
|
||||
const prev = info.languageService.getSemanticDiagnostics(filename);
|
||||
const sourceFile: ts.SourceFile = info.project.getSourceFile(ts.toPath(filename, /*basePath*/ undefined, ts.createGetCanonicalFileName(info.serverHost.useCaseSensitiveFileNames)))!;
|
||||
const sourceFile: ts.SourceFile = info.project.getSourceFile(ts.toPath(filename, /*basePath*/ undefined, ts.createGetCanonicalFileName(info.fsHost.useCaseSensitiveFileNames)))!;
|
||||
prev.push({
|
||||
category: ts.DiagnosticCategory.Error,
|
||||
file: sourceFile,
|
||||
|
||||
@@ -760,7 +760,7 @@ namespace ts.server {
|
||||
readonly currentDirectory: NormalizedPath;
|
||||
readonly toCanonicalFileName: (f: string) => string;
|
||||
|
||||
public readonly host: ServerHost;
|
||||
public readonly host: RuntimeServerHost;
|
||||
public readonly fshost: FileServerHost;
|
||||
public readonly logger: Logger;
|
||||
public readonly cancellationToken: HostCancellationToken;
|
||||
@@ -808,7 +808,7 @@ namespace ts.server {
|
||||
|
||||
constructor(opts: ProjectServiceOptions) {
|
||||
this.host = opts.host;
|
||||
this.fshost = opts.fshost || this.host;
|
||||
this.fshost = opts.fshost || (this.host as ServerHost);
|
||||
this.logger = opts.logger;
|
||||
this.cancellationToken = opts.cancellationToken;
|
||||
this.useSingleInferredProject = opts.useSingleInferredProject;
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace ts.server {
|
||||
project: Project;
|
||||
languageService: LanguageService;
|
||||
languageServiceHost: LanguageServiceHost;
|
||||
serverHost: ServerHost;
|
||||
serverHost: RuntimeServerHost;
|
||||
fsHost: FileServerHost;
|
||||
session?: Session<unknown>;
|
||||
config: any;
|
||||
@@ -234,8 +234,8 @@ namespace ts.server {
|
||||
return hasOneOrMoreJsAndNoTsFiles(this);
|
||||
}
|
||||
|
||||
public static resolveModule(moduleName: string, initialDir: string, host: ServerHost, log: (message: string) => void, logErrors?: (message: string) => void): {} | undefined {
|
||||
const resolvedPath = normalizeSlashes(host.resolvePath(combinePaths(initialDir, "node_modules")));
|
||||
public static resolveModule(moduleName: string, initialDir: string, host: RuntimeServerHost, fshost: FileServerHost, log: (message: string) => void, logErrors?: (message: string) => void): {} | undefined {
|
||||
const resolvedPath = normalizeSlashes(fshost.resolvePath(combinePaths(initialDir, "node_modules")));
|
||||
log(`Loading ${moduleName} from ${initialDir} (resolved to ${resolvedPath})`);
|
||||
const result = host.require!(resolvedPath, moduleName); // TODO: GH#18217
|
||||
if (result.error) {
|
||||
@@ -381,7 +381,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
getNewLine() {
|
||||
return this.projectService.host.newLine;
|
||||
return this.projectService.fshost.newLine;
|
||||
}
|
||||
|
||||
getProjectVersion() {
|
||||
@@ -1608,7 +1608,7 @@ namespace ts.server {
|
||||
(errorLogs || (errorLogs = [])).push(message);
|
||||
};
|
||||
const resolvedModule = firstDefined(searchPaths, searchPath =>
|
||||
Project.resolveModule(pluginConfigEntry.name, searchPath, this.projectService.host, log, logError) as PluginModuleFactory | undefined);
|
||||
Project.resolveModule(pluginConfigEntry.name, searchPath, this.projectService.host, this.projectService.fshost, log, logError) as PluginModuleFactory | undefined);
|
||||
if (resolvedModule) {
|
||||
const configurationOverride = pluginConfigOverrides && pluginConfigOverrides.get(pluginConfigEntry.name);
|
||||
if (configurationOverride) {
|
||||
@@ -1998,7 +1998,7 @@ namespace ts.server {
|
||||
compilerOptions,
|
||||
/*compileOnSaveEnabled*/ false,
|
||||
/*watchOptions*/ undefined,
|
||||
projectService.host,
|
||||
projectService.fshost,
|
||||
/*currentDirectory*/ undefined);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,4 +23,5 @@ declare namespace ts.server {
|
||||
| "getDirectories" | "getCurrentDirectory" | "getExecutingFilePath" | "realpath" | "resolvePath"
|
||||
| "createDirectory" | "setModifiedTime" | "deleteFile" | "readDirectory" | "watchFile" | "watchDirectory"
|
||||
| "useCaseSensitiveFileNames" | "newLine">;
|
||||
export type RuntimeServerHost = Omit<ServerHost, keyof FileServerHost>
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace ts.server {
|
||||
export class ThrottledOperations {
|
||||
private readonly pendingTimeouts = new Map<string, any>();
|
||||
private readonly logger?: Logger | undefined;
|
||||
constructor(private readonly host: ServerHost, logger: Logger) {
|
||||
constructor(private readonly host: RuntimeServerHost, logger: Logger) {
|
||||
this.logger = logger.hasLevel(LogLevel.verbose) ? logger : undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace ts.projectSystem {
|
||||
const proxy = Harness.LanguageService.makeDefaultProxy(info);
|
||||
proxy.getSemanticDiagnostics = filename => {
|
||||
const prev = info.languageService.getSemanticDiagnostics(filename);
|
||||
const sourceFile: SourceFile = info.project.getSourceFile(toPath(filename, /*basePath*/ undefined, createGetCanonicalFileName(info.serverHost.useCaseSensitiveFileNames)))!;
|
||||
const sourceFile: SourceFile = info.project.getSourceFile(toPath(filename, /*basePath*/ undefined, createGetCanonicalFileName(info.fsHost.useCaseSensitiveFileNames)))!;
|
||||
prev.push({
|
||||
category: DiagnosticCategory.Warning,
|
||||
file: sourceFile,
|
||||
|
||||
+4
-3
@@ -6986,6 +6986,7 @@ declare namespace ts.server {
|
||||
require?(initialPath: string, moduleName: string): RequireResult;
|
||||
}
|
||||
type FileServerHost = Pick<ServerHost, "readFile" | "writeFile" | "fileExists" | "directoryExists" | "getFileSize" | "getModifiedTime" | "getDirectories" | "getCurrentDirectory" | "getExecutingFilePath" | "realpath" | "resolvePath" | "createDirectory" | "setModifiedTime" | "deleteFile" | "readDirectory" | "watchFile" | "watchDirectory" | "useCaseSensitiveFileNames" | "newLine">;
|
||||
type RuntimeServerHost = Omit<ServerHost, keyof FileServerHost>;
|
||||
}
|
||||
declare namespace ts.server {
|
||||
enum LogLevel {
|
||||
@@ -9991,7 +9992,7 @@ declare namespace ts.server {
|
||||
project: Project;
|
||||
languageService: LanguageService;
|
||||
languageServiceHost: LanguageServiceHost;
|
||||
serverHost: ServerHost;
|
||||
serverHost: RuntimeServerHost;
|
||||
fsHost: FileServerHost;
|
||||
session?: Session<unknown>;
|
||||
config: any;
|
||||
@@ -10057,7 +10058,7 @@ declare namespace ts.server {
|
||||
private readonly cancellationToken;
|
||||
isNonTsProject(): boolean;
|
||||
isJsOnlyProject(): boolean;
|
||||
static resolveModule(moduleName: string, initialDir: string, host: ServerHost, log: (message: string) => void, logErrors?: (message: string) => void): {} | undefined;
|
||||
static resolveModule(moduleName: string, initialDir: string, host: RuntimeServerHost, fshost: FileServerHost, log: (message: string) => void, logErrors?: (message: string) => void): {} | undefined;
|
||||
isKnownTypesPackageName(name: string): boolean;
|
||||
installPackage(options: InstallPackageOptions): Promise<ApplyCodeActionCommandResult>;
|
||||
private get typingsCache();
|
||||
@@ -10442,7 +10443,7 @@ declare namespace ts.server {
|
||||
private pendingProjectUpdates;
|
||||
readonly currentDirectory: NormalizedPath;
|
||||
readonly toCanonicalFileName: (f: string) => string;
|
||||
readonly host: ServerHost;
|
||||
readonly host: RuntimeServerHost;
|
||||
readonly fshost: FileServerHost;
|
||||
readonly logger: Logger;
|
||||
readonly cancellationToken: HostCancellationToken;
|
||||
|
||||
Reference in New Issue
Block a user