From 237225b01ac8a6df92eba312a05ad0a4f52ac3b6 Mon Sep 17 00:00:00 2001 From: steveluc Date: Thu, 26 Mar 2015 00:21:27 -0700 Subject: [PATCH] Fix bug stemming from use of tsc findConfigFile by server. Server needs its own version of this because tsc always starts from the current directory but the server must start from whatever directory contains the newly opened file. --- src/server/editorServices.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 034549ab464..e29dced0627 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -751,6 +751,26 @@ module ts.server { return info; } + // This is different from the method the compiler uses because + // the compiler can assume it will always start searching in the + // current directory (the directory in which tsc was invoked). + // The server must start searching from the directory containing + // the newly opened file. + findConfigFile(searchPath: string): string { + while (true) { + var fileName = ts.combinePaths(searchPath, "tsconfig.json"); + if (sys.fileExists(fileName)) { + return fileName; + } + var parentPath = ts.getDirectoryPath(searchPath); + if (parentPath === searchPath) { + break; + } + searchPath = parentPath; + } + return undefined; + } + /** * Open file whose contents is managed by the client * @param filename is absolute pathname @@ -758,7 +778,13 @@ module ts.server { openClientFile(fileName: string) { var searchPath = ts.normalizePath(getDirectoryPath(fileName)); - var configFileName = ts.findConfigFile(searchPath); + this.log("Search path: " + searchPath,"Info"); + var configFileName = this.findConfigFile(searchPath); + if (configFileName) { + this.log("Config file name: " + configFileName, "Info"); + } else { + this.log("no config file"); + } if (configFileName) { configFileName = getAbsolutePath(configFileName, searchPath); }