Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Commit 465b330

Browse files
committed
Fixed file path bug
Fixed splitting file name from path when generating new file New files will now be generated in the same directory as the source file, instead of the root solution directory. Bumped version number
1 parent 6f3c5f6 commit 465b330

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "tmlanguage",
33
"displayName": "TextMate Languages",
44
"description": "Syntax highlighter and snippets for JSON/YAML derivitives of TextMate language definition",
5-
"version": "0.0.7",
5+
"version": "0.7.1",
66
"publisher": "Togusa09",
77
"license": "MIT",
88
"engines": {

src/extension.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// The module 'vscode' contains the VS Code extensibility API
44
// Import the module and reference it with the alias vscode in your code below
55
import * as vscode from 'vscode';
6-
import {join, basename} from 'path';
6+
import * as path from 'path';
77

88
var plist = require('plist');
99
var json = require('format-json');
@@ -91,7 +91,7 @@ class FileConverter{
9191
return;
9292
}
9393
let doc = editor.document;
94-
var filename = doc.fileName.split("\\").pop().split('.').shift();
94+
var parsedFilePath = path.parse(doc.fileName);
9595

9696
try{
9797
var extension: string;
@@ -120,18 +120,18 @@ class FileConverter{
120120
var sourceLanguage = doc.languageId;
121121

122122
// 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 => {
124124
var paths = matchingFiles.map(p => p.fsPath);
125125

126-
var path = join(vscode.workspace.rootPath, './' + filename + '.' + extension);
126+
var newFilePath = path.join(parsedFilePath.dir, './' + parsedFilePath.name + '.' + extension);
127127
if (matchingFiles.length != 0){
128128
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);
131131
counter++;
132132
}
133133
}
134-
this.OpenTextDocument(sourceLanguage, destinationLanguage, documentText, path);
134+
this.OpenTextDocument(sourceLanguage, destinationLanguage, documentText, newFilePath);
135135
});
136136
} catch(err) {
137137
console.log(err);
@@ -178,6 +178,6 @@ class FileConverter{
178178
}
179179

180180
dispose() {
181-
//this._statusBarItem.dispose();
181+
182182
}
183183
}

0 commit comments

Comments
 (0)