From a7ab56d7d8836b0ce8ca8c0313716489e1cde886 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 26 Apr 2017 18:11:00 +0200 Subject: [PATCH] Try loading referenced files --- index.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/index.ts b/index.ts index c7c8229..11261a6 100644 --- a/index.ts +++ b/index.ts @@ -82,28 +82,25 @@ namespace tss { getScriptSnapshot: (fileName) => { let file = this.files[fileName]; if (!file) { - // default lib - let defaultLibPath = path.join(this.getTypeScriptBinDir(), fileName); - if (fs.existsSync(defaultLibPath)) { - file = this.files[fileName] = {version: 0, text: fs.readFileSync(defaultLibPath).toString()}; - } + [fileName, path.join(this.getTypeScriptBinDir(), fileName)].some((filePath) => { + if (fs.existsSync(filePath)) { + file = this.files[fileName] = { version: 0, text: fs.readFileSync(filePath, 'utf8') }; + return true; + } + return false; + }); } - if (file) { - return { + return file ? { getText: (start, end) => file.text.substring(start, end), getLength: () => file.text.length, - getLineStartPositions: (): number[] => [], + getLineStartPositions: () => [], getChangeRange: (oldSnapshot) => undefined - }; - } else { - // This is some reference import - return { + } : { getText: (start, end) => '', getLength: () => 0, - getLineStartPositions: (): number[] => [], + getLineStartPositions: () => [], getChangeRange: (oldSnapshot) => undefined }; - } }, getCurrentDirectory: () => process.cwd(), getCompilationSettings: () => this.options,