From d18275bc6a18822c8b282b8c03426bef02383820 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Sun, 4 Jun 2017 17:46:50 +0200 Subject: [PATCH 1/2] Remove OS-specific behaviour --- src/project-manager.ts | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/src/project-manager.ts b/src/project-manager.ts index 6c647d5a8..f6fa14d1a 100644 --- a/src/project-manager.ts +++ b/src/project-manager.ts @@ -1,7 +1,6 @@ import { Observable, Subscription } from '@reactivex/rxjs'; import iterate from 'iterare'; import { Span } from 'opentracing'; -import * as os from 'os'; import * as path from 'path'; import * as ts from 'typescript'; import { Disposable } from './disposable'; @@ -113,7 +112,7 @@ export class ProjectManager implements Disposable { traceModuleResolution?: boolean, protected logger: Logger = new NoopLogger() ) { - this.rootPath = toUnixPath(rootPath); + this.rootPath = rootPath; this.updater = updater; this.inMemoryFs = inMemoryFileSystem; this.versions = new Map(); @@ -380,47 +379,32 @@ export class ProjectManager implements Disposable { if (observable) { return observable; } - // TypeScript works with file paths, not URIs - const filePath = uri2path(uri); observable = Observable.from(this.updater.ensure(uri)) .mergeMap(() => { - const config = this.getConfiguration(filePath); + const referencingFilePath = uri2path(uri); + const config = this.getConfiguration(referencingFilePath); config.ensureBasicFiles(span); const contents = this.inMemoryFs.getContent(uri); const info = ts.preProcessFile(contents, true, true); const compilerOpt = config.getHost().getCompilationSettings(); - // TODO remove platform-specific behavior here, the host OS is not coupled to the client OS - const resolver = !this.strict && os.platform() === 'win32' ? path : path.posix; + const pathResolver = referencingFilePath.includes('\\') ? path.win32 : path.posix; // Iterate imported files return Observable.merge( // References with `import` Observable.from(info.importedFiles) - .map(importedFile => ts.resolveModuleName(importedFile.fileName, toUnixPath(filePath), compilerOpt, this.inMemoryFs)) - // false means we didn't find a file defining the module. It - // could still exist as an ambient module, which is why we - // fetch global*.d.ts files. + .map(importedFile => ts.resolveModuleName(importedFile.fileName, toUnixPath(referencingFilePath), compilerOpt, this.inMemoryFs)) + // false means we didn't find a file defining the module. It could still + // exist as an ambient module, which is why we fetch global*.d.ts files. .filter(resolved => !!(resolved && resolved.resolvedModule)) .map(resolved => resolved.resolvedModule!.resolvedFileName), // References with `` Observable.from(info.referencedFiles) - // Resolve triple slash references relative to current file - // instead of using module resolution host because it behaves - // differently in "nodejs" mode - .map(referencedFile => resolver.resolve( - this.rootPath, - resolver.dirname(filePath), - toUnixPath(referencedFile.fileName) - )), + // Resolve triple slash references relative to current file instead of using + // module resolution host because it behaves differently in "nodejs" mode + .map(referencedFile => pathResolver.resolve(this.rootPath, pathResolver.dirname(referencingFilePath), toUnixPath(referencedFile.fileName))), // References with `` Observable.from(info.typeReferenceDirectives) - .map(typeReferenceDirective => - ts.resolveTypeReferenceDirective( - typeReferenceDirective.fileName, - filePath, - compilerOpt, - this.inMemoryFs - ) - ) + .map(typeReferenceDirective => ts.resolveTypeReferenceDirective(typeReferenceDirective.fileName, referencingFilePath, compilerOpt, this.inMemoryFs)) .filter(resolved => !!(resolved && resolved.resolvedTypeReferenceDirective && resolved.resolvedTypeReferenceDirective.resolvedFileName)) .map(resolved => resolved.resolvedTypeReferenceDirective!.resolvedFileName!) ); From d92be96463f5125f38d464e32f68c61b32026b17 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Sun, 4 Jun 2017 17:56:30 +0200 Subject: [PATCH 2/2] Remove ProjectManager.strict --- src/project-manager.ts | 8 -------- src/typescript-service.ts | 1 - 2 files changed, 9 deletions(-) diff --git a/src/project-manager.ts b/src/project-manager.ts index f6fa14d1a..3208e44bc 100644 --- a/src/project-manager.ts +++ b/src/project-manager.ts @@ -45,12 +45,6 @@ export class ProjectManager implements Disposable { ts: new Map() }; - /** - * When on, indicates that client is responsible to provide file content (VFS), - * otherwise we are working with a local file system - */ - private strict: boolean; - /** * Local side of file content provider which keeps cache of fetched files */ @@ -108,7 +102,6 @@ export class ProjectManager implements Disposable { rootPath: string, inMemoryFileSystem: InMemoryFileSystem, updater: FileSystemUpdater, - strict: boolean, traceModuleResolution?: boolean, protected logger: Logger = new NoopLogger() ) { @@ -116,7 +109,6 @@ export class ProjectManager implements Disposable { this.updater = updater; this.inMemoryFs = inMemoryFileSystem; this.versions = new Map(); - this.strict = strict; this.traceModuleResolution = traceModuleResolution || false; // Share DocumentRegistry between all ProjectConfigurations diff --git a/src/typescript-service.ts b/src/typescript-service.ts index f210c7fee..b898cf3b3 100644 --- a/src/typescript-service.ts +++ b/src/typescript-service.ts @@ -210,7 +210,6 @@ export class TypeScriptService { this.root, this.inMemoryFileSystem, this.updater, - !!this.options.strict, this.traceModuleResolution, this.logger );