|
1 | 1 | import { Observable, Subscription } from '@reactivex/rxjs'; |
2 | 2 | import iterate from 'iterare'; |
3 | 3 | import { Span } from 'opentracing'; |
4 | | -import * as os from 'os'; |
5 | 4 | import * as path from 'path'; |
6 | 5 | import * as ts from 'typescript'; |
7 | 6 | import { Disposable } from './disposable'; |
@@ -46,12 +45,6 @@ export class ProjectManager implements Disposable { |
46 | 45 | ts: new Map<string, ProjectConfiguration>() |
47 | 46 | }; |
48 | 47 |
|
49 | | - /** |
50 | | - * When on, indicates that client is responsible to provide file content (VFS), |
51 | | - * otherwise we are working with a local file system |
52 | | - */ |
53 | | - private strict: boolean; |
54 | | - |
55 | 48 | /** |
56 | 49 | * Local side of file content provider which keeps cache of fetched files |
57 | 50 | */ |
@@ -109,15 +102,13 @@ export class ProjectManager implements Disposable { |
109 | 102 | rootPath: string, |
110 | 103 | inMemoryFileSystem: InMemoryFileSystem, |
111 | 104 | updater: FileSystemUpdater, |
112 | | - strict: boolean, |
113 | 105 | traceModuleResolution?: boolean, |
114 | 106 | protected logger: Logger = new NoopLogger() |
115 | 107 | ) { |
116 | | - this.rootPath = toUnixPath(rootPath); |
| 108 | + this.rootPath = rootPath; |
117 | 109 | this.updater = updater; |
118 | 110 | this.inMemoryFs = inMemoryFileSystem; |
119 | 111 | this.versions = new Map<string, number>(); |
120 | | - this.strict = strict; |
121 | 112 | this.traceModuleResolution = traceModuleResolution || false; |
122 | 113 |
|
123 | 114 | // Share DocumentRegistry between all ProjectConfigurations |
@@ -380,47 +371,32 @@ export class ProjectManager implements Disposable { |
380 | 371 | if (observable) { |
381 | 372 | return observable; |
382 | 373 | } |
383 | | - // TypeScript works with file paths, not URIs |
384 | | - const filePath = uri2path(uri); |
385 | 374 | observable = Observable.from(this.updater.ensure(uri)) |
386 | 375 | .mergeMap(() => { |
387 | | - const config = this.getConfiguration(filePath); |
| 376 | + const referencingFilePath = uri2path(uri); |
| 377 | + const config = this.getConfiguration(referencingFilePath); |
388 | 378 | config.ensureBasicFiles(span); |
389 | 379 | const contents = this.inMemoryFs.getContent(uri); |
390 | 380 | const info = ts.preProcessFile(contents, true, true); |
391 | 381 | const compilerOpt = config.getHost().getCompilationSettings(); |
392 | | - // TODO remove platform-specific behavior here, the host OS is not coupled to the client OS |
393 | | - const resolver = !this.strict && os.platform() === 'win32' ? path : path.posix; |
| 382 | + const pathResolver = referencingFilePath.includes('\\') ? path.win32 : path.posix; |
394 | 383 | // Iterate imported files |
395 | 384 | return Observable.merge( |
396 | 385 | // References with `import` |
397 | 386 | Observable.from(info.importedFiles) |
398 | | - .map(importedFile => ts.resolveModuleName(importedFile.fileName, toUnixPath(filePath), compilerOpt, this.inMemoryFs)) |
399 | | - // false means we didn't find a file defining the module. It |
400 | | - // could still exist as an ambient module, which is why we |
401 | | - // fetch global*.d.ts files. |
| 387 | + .map(importedFile => ts.resolveModuleName(importedFile.fileName, toUnixPath(referencingFilePath), compilerOpt, this.inMemoryFs)) |
| 388 | + // false means we didn't find a file defining the module. It could still |
| 389 | + // exist as an ambient module, which is why we fetch global*.d.ts files. |
402 | 390 | .filter(resolved => !!(resolved && resolved.resolvedModule)) |
403 | 391 | .map(resolved => resolved.resolvedModule!.resolvedFileName), |
404 | 392 | // References with `<reference path="..."/>` |
405 | 393 | Observable.from(info.referencedFiles) |
406 | | - // Resolve triple slash references relative to current file |
407 | | - // instead of using module resolution host because it behaves |
408 | | - // differently in "nodejs" mode |
409 | | - .map(referencedFile => resolver.resolve( |
410 | | - this.rootPath, |
411 | | - resolver.dirname(filePath), |
412 | | - toUnixPath(referencedFile.fileName) |
413 | | - )), |
| 394 | + // Resolve triple slash references relative to current file instead of using |
| 395 | + // module resolution host because it behaves differently in "nodejs" mode |
| 396 | + .map(referencedFile => pathResolver.resolve(this.rootPath, pathResolver.dirname(referencingFilePath), toUnixPath(referencedFile.fileName))), |
414 | 397 | // References with `<reference types="..."/>` |
415 | 398 | Observable.from(info.typeReferenceDirectives) |
416 | | - .map(typeReferenceDirective => |
417 | | - ts.resolveTypeReferenceDirective( |
418 | | - typeReferenceDirective.fileName, |
419 | | - filePath, |
420 | | - compilerOpt, |
421 | | - this.inMemoryFs |
422 | | - ) |
423 | | - ) |
| 399 | + .map(typeReferenceDirective => ts.resolveTypeReferenceDirective(typeReferenceDirective.fileName, referencingFilePath, compilerOpt, this.inMemoryFs)) |
424 | 400 | .filter(resolved => !!(resolved && resolved.resolvedTypeReferenceDirective && resolved.resolvedTypeReferenceDirective.resolvedFileName)) |
425 | 401 | .map(resolved => resolved.resolvedTypeReferenceDirective!.resolvedFileName!) |
426 | 402 | ); |
|
0 commit comments