Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 11 additions & 35 deletions src/project-manager.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -46,12 +45,6 @@ export class ProjectManager implements Disposable {
ts: new Map<string, ProjectConfiguration>()
};

/**
* 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
*/
Expand Down Expand Up @@ -109,15 +102,13 @@ export class ProjectManager implements Disposable {
rootPath: string,
inMemoryFileSystem: InMemoryFileSystem,
updater: FileSystemUpdater,
strict: boolean,
traceModuleResolution?: boolean,
protected logger: Logger = new NoopLogger()
) {
this.rootPath = toUnixPath(rootPath);
this.rootPath = rootPath;
this.updater = updater;
this.inMemoryFs = inMemoryFileSystem;
this.versions = new Map<string, number>();
this.strict = strict;
this.traceModuleResolution = traceModuleResolution || false;

// Share DocumentRegistry between all ProjectConfigurations
Expand Down Expand Up @@ -380,47 +371,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 `<reference path="..."/>`
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 `<reference types="..."/>`
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!)
);
Expand Down
1 change: 0 additions & 1 deletion src/typescript-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ export class TypeScriptService {
this.root,
this.inMemoryFileSystem,
this.updater,
!!this.options.strict,
this.traceModuleResolution,
this.logger
);
Expand Down