From 6ff91b84aba99fbf66ac8f4e1d63068794ca8dcd Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 28 Jun 2016 11:43:07 -0700 Subject: [PATCH 1/2] Add getCurrentDirectory to ServerHost --- src/compiler/program.ts | 18 ++++++++++++++++-- src/server/editorServices.ts | 1 + .../fourslash/server/typeReferenceOnServer.ts | 9 +++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/server/typeReferenceOnServer.ts diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 7593f4f5434f5..decbb835a8c9f 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -187,8 +187,22 @@ namespace ts { const typeReferenceExtensions = [".d.ts"]; function getEffectiveTypeRoots(options: CompilerOptions, host: ModuleResolutionHost) { - return options.typeRoots || - map(defaultTypeRoots, d => combinePaths(options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory(), d)); + if (options.typeRoots) { + return options.typeRoots; + } + + let currentDirectory: string; + if (options.configFilePath) { + currentDirectory = getDirectoryPath(options.configFilePath); + } + else if (host.getCurrentDirectory) { + currentDirectory = host.getCurrentDirectory(); + } + + if (!currentDirectory) { + return undefined; + } + return map(defaultTypeRoots, d => combinePaths(currentDirectory, d)); } /** diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index e48d61920177f..e4b989b0ca7bc 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -113,6 +113,7 @@ namespace ts.server { this.moduleResolutionHost = { fileExists: fileName => this.fileExists(fileName), readFile: fileName => this.host.readFile(fileName), + getCurrentDirectory: () => this.host.getCurrentDirectory(), directoryExists: directoryName => this.host.directoryExists(directoryName) }; } diff --git a/tests/cases/fourslash/server/typeReferenceOnServer.ts b/tests/cases/fourslash/server/typeReferenceOnServer.ts new file mode 100644 index 0000000000000..574ea6f60c46e --- /dev/null +++ b/tests/cases/fourslash/server/typeReferenceOnServer.ts @@ -0,0 +1,9 @@ +/// + +/////// +////var x: number; +////x./*1*/ + +goTo.marker("1"); +verify.not.completionListIsEmpty(); + From d5cad239e858ca71e89aa8963a7d875928652a65 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Tue, 28 Jun 2016 12:10:26 -0700 Subject: [PATCH 2/2] Add nullchecks for typeRoots, remove getCurrentDirectory from ServerHost as it is always the installation location --- src/compiler/program.ts | 10 ++++++---- src/server/editorServices.ts | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index decbb835a8c9f..fb74f1dcaab33 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -242,7 +242,7 @@ namespace ts { const failedLookupLocations: string[] = []; // Check primary library paths - if (typeRoots.length) { + if (typeRoots && typeRoots.length) { if (traceEnabled) { trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", ")); } @@ -1060,9 +1060,11 @@ namespace ts { let result: string[] = []; if (host.directoryExists && host.getDirectories) { const typeRoots = getEffectiveTypeRoots(options, host); - for (const root of typeRoots) { - if (host.directoryExists(root)) { - result = result.concat(host.getDirectories(root)); + if (typeRoots) { + for (const root of typeRoots) { + if (host.directoryExists(root)) { + result = result.concat(host.getDirectories(root)); + } } } } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index e4b989b0ca7bc..e48d61920177f 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -113,7 +113,6 @@ namespace ts.server { this.moduleResolutionHost = { fileExists: fileName => this.fileExists(fileName), readFile: fileName => this.host.readFile(fileName), - getCurrentDirectory: () => this.host.getCurrentDirectory(), directoryExists: directoryName => this.host.directoryExists(directoryName) }; }