Skip to content

Commit a571731

Browse files
gecharoJakob Werner
authored andcommitted
removeLeadingDot option added (#24)
* config prop prefixPathWithCurrentDirectory implemented, _workspacePath fixed * prefixPathWithCurrentDirectory reanemed to removeLeadingDot as it as previosly called
1 parent b83dd74 commit a571731

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
".js"
6767
],
6868
"description": "An array of extensions to exclude from the relative path url (Useful for used with Webpack or when importing files of mixed types)"
69+
},
70+
"relativePath.removeLeadingDot": {
71+
"type": "boolean",
72+
"default": true,
73+
"description": "Removes the leading ./ character when the path is pointing to a parent folder."
6974
}
7075
}
7176
}

src/extension.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ class RelativePath {
8585
const editor = window.activeTextEditor;
8686
if (editor) {
8787
const res = editor.document.uri;
88-
const folder = workspace.getWorkspaceFolder(res)
89-
return folder.uri.fsPath;
88+
const folder = workspace.getWorkspaceFolder(res);
89+
return folder.uri.fsPath.replace(/\\/g, "/");
9090
}
9191
}
9292
// Purely updates the files
@@ -203,13 +203,11 @@ class RelativePath {
203203
const currentItemPath = editor.document.fileName.replace(/\\/g, "/").replace(this._workspacePath, "");
204204
let relativeUrl: string = path.relative(currentItemPath, targetPath).replace(".", "").replace(/\\/g, "/");
205205

206-
if (this._configuration.removeExtension) {
207-
relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf("."));
208-
} else if (this.excludeExtensionsFor(relativeUrl)) {
206+
if (this._configuration.removeExtension || this.excludeExtensionsFor(relativeUrl)) {
209207
relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf("."));
210208
}
211209

212-
if (relativeUrl.startsWith("./../")) {
210+
if (this._configuration.removeLeadingDot && relativeUrl.startsWith("./../")) {
213211
relativeUrl = relativeUrl.substring(2, relativeUrl.length);
214212
}
215213

0 commit comments

Comments
 (0)