Skip to content

Commit 6ff91b8

Browse files
author
zhengbli
committed
Add getCurrentDirectory to ServerHost
1 parent 6be7d9c commit 6ff91b8

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/compiler/program.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,22 @@ namespace ts {
187187
const typeReferenceExtensions = [".d.ts"];
188188

189189
function getEffectiveTypeRoots(options: CompilerOptions, host: ModuleResolutionHost) {
190-
return options.typeRoots ||
191-
map(defaultTypeRoots, d => combinePaths(options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory(), d));
190+
if (options.typeRoots) {
191+
return options.typeRoots;
192+
}
193+
194+
let currentDirectory: string;
195+
if (options.configFilePath) {
196+
currentDirectory = getDirectoryPath(options.configFilePath);
197+
}
198+
else if (host.getCurrentDirectory) {
199+
currentDirectory = host.getCurrentDirectory();
200+
}
201+
202+
if (!currentDirectory) {
203+
return undefined;
204+
}
205+
return map(defaultTypeRoots, d => combinePaths(currentDirectory, d));
192206
}
193207

194208
/**

src/server/editorServices.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ namespace ts.server {
113113
this.moduleResolutionHost = {
114114
fileExists: fileName => this.fileExists(fileName),
115115
readFile: fileName => this.host.readFile(fileName),
116+
getCurrentDirectory: () => this.host.getCurrentDirectory(),
116117
directoryExists: directoryName => this.host.directoryExists(directoryName)
117118
};
118119
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path='../fourslash.ts' />
2+
3+
/////// <reference types="foo" />
4+
////var x: number;
5+
////x./*1*/
6+
7+
goTo.marker("1");
8+
verify.not.completionListIsEmpty();
9+

0 commit comments

Comments
 (0)