|
3 | 3 | // The module 'vscode' contains the VS Code extensibility API
|
4 | 4 | // Import the module and reference it with the alias vscode in your code below
|
5 | 5 | import * as vscode from 'vscode';
|
6 |
| -import {join, basename} from 'path'; |
| 6 | +import * as path from 'path'; |
7 | 7 |
|
8 | 8 | var plist = require('plist');
|
9 | 9 | var json = require('format-json');
|
@@ -91,7 +91,7 @@ class FileConverter{
|
91 | 91 | return;
|
92 | 92 | }
|
93 | 93 | let doc = editor.document;
|
94 |
| - var filename = doc.fileName.split("\\").pop().split('.').shift(); |
| 94 | + var parsedFilePath = path.parse(doc.fileName); |
95 | 95 |
|
96 | 96 | try{
|
97 | 97 | var extension: string;
|
@@ -120,18 +120,18 @@ class FileConverter{
|
120 | 120 | var sourceLanguage = doc.languageId;
|
121 | 121 |
|
122 | 122 | // check to see if file already exists
|
123 |
| - vscode.workspace.findFiles(filename + "*." + extension, "ABC").then(matchingFiles => { |
| 123 | + vscode.workspace.findFiles(parsedFilePath.name + "*." + extension, "ABC").then(matchingFiles => { |
124 | 124 | var paths = matchingFiles.map(p => p.fsPath);
|
125 | 125 |
|
126 |
| - var path = join(vscode.workspace.rootPath, './' + filename + '.' + extension); |
| 126 | + var newFilePath = path.join(parsedFilePath.dir, './' + parsedFilePath.name + '.' + extension); |
127 | 127 | if (matchingFiles.length != 0){
|
128 | 128 | var counter = 1;
|
129 |
| - while (paths.indexOf(path) >= 0){ |
130 |
| - path = join(vscode.workspace.rootPath, './' + filename + '(' + counter +').' + extension); |
| 129 | + while (paths.indexOf(newFilePath) >= 0){ |
| 130 | + newFilePath = path.join(parsedFilePath.dir, './' + parsedFilePath.name + '(' + counter +').' + extension); |
131 | 131 | counter++;
|
132 | 132 | }
|
133 | 133 | }
|
134 |
| - this.OpenTextDocument(sourceLanguage, destinationLanguage, documentText, path); |
| 134 | + this.OpenTextDocument(sourceLanguage, destinationLanguage, documentText, newFilePath); |
135 | 135 | });
|
136 | 136 | } catch(err) {
|
137 | 137 | console.log(err);
|
@@ -178,6 +178,6 @@ class FileConverter{
|
178 | 178 | }
|
179 | 179 |
|
180 | 180 | dispose() {
|
181 |
| - //this._statusBarItem.dispose(); |
| 181 | + |
182 | 182 | }
|
183 | 183 | }
|
0 commit comments