From 790ce1b2ea0e2a6db4cc9b2fab3dcffda7bdb68e Mon Sep 17 00:00:00 2001 From: elwyn Date: Tue, 29 Dec 2015 16:55:32 +1300 Subject: [PATCH 1/3] Removed hardcoded path relative root The generated paths always had a hardcoded `./` prefix. This resulted in paths like this: `import IWow from './../foo/bar/IWow';` While technically correct, the initial `./` is redundant, and looks a bit silly. I've removed the hardcoded `./` and added a check for the first character of the relative path being a `.`. This means it will not be added, unless the import is for a file in the same directory as the source file, in which case it will result in `./IWow` --- lib/typescript-import.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/typescript-import.coffee b/lib/typescript-import.coffee index e6bcdef..da652b1 100644 --- a/lib/typescript-import.coffee +++ b/lib/typescript-import.coffee @@ -89,7 +89,9 @@ module.exports = TypescriptImport = if symbolLocation && selection fileFolder = path.resolve(filePath + '/..') relative = path.relative(fileFolder, symbolLocation).replace(/\.(js|ts)$/, ''); - importClause = "import #{selection} from './#{relative}';\n" + if relative[0] !== '.' + relative = './' + relative + importClause = "import #{selection} from '#{relative}';\n" @addImportStatement(importClause) # editor.insertText(selection + "\nimport #{selection} from './#{relative}'") else From 0e1b847536aca0594802cbe19f1933d50bf42dc3 Mon Sep 17 00:00:00 2001 From: elwyn Date: Tue, 29 Dec 2015 16:58:01 +1300 Subject: [PATCH 2/3] Fixed typo --- lib/typescript-import.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/typescript-import.coffee b/lib/typescript-import.coffee index da652b1..61c4981 100644 --- a/lib/typescript-import.coffee +++ b/lib/typescript-import.coffee @@ -89,7 +89,7 @@ module.exports = TypescriptImport = if symbolLocation && selection fileFolder = path.resolve(filePath + '/..') relative = path.relative(fileFolder, symbolLocation).replace(/\.(js|ts)$/, ''); - if relative[0] !== '.' + if relative[0] != '.' relative = './' + relative importClause = "import #{selection} from '#{relative}';\n" @addImportStatement(importClause) From 7ee74730662e45cb17b5f304948125f191f07a27 Mon Sep 17 00:00:00 2001 From: elwyn Date: Tue, 29 Dec 2015 16:59:15 +1300 Subject: [PATCH 3/3] Fixed bad whitespace --- lib/typescript-import.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/typescript-import.coffee b/lib/typescript-import.coffee index 61c4981..34d8bfc 100644 --- a/lib/typescript-import.coffee +++ b/lib/typescript-import.coffee @@ -89,8 +89,8 @@ module.exports = TypescriptImport = if symbolLocation && selection fileFolder = path.resolve(filePath + '/..') relative = path.relative(fileFolder, symbolLocation).replace(/\.(js|ts)$/, ''); - if relative[0] != '.' - relative = './' + relative + if relative[0] != '.' + relative = './' + relative importClause = "import #{selection} from '#{relative}';\n" @addImportStatement(importClause) # editor.insertText(selection + "\nimport #{selection} from './#{relative}'")