Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
".js"
],
"description": "An array of extensions to exclude from the relative path url (Useful for used with Webpack or when importing files of mixed types)"
},
"relativePath.removeLeadingDot": {
"type": "boolean",
"default": true,
"description": "Removes the leading ./ character when the path is pointing to a parent folder."
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class RelativePath {
const editor = window.activeTextEditor;
if (editor) {
const res = editor.document.uri;
const folder = workspace.getWorkspaceFolder(res)
return folder.uri.fsPath;
const folder = workspace.getWorkspaceFolder(res);
return folder.uri.fsPath.replace(/\\/g, "/");
}
}
// Purely updates the files
Expand Down Expand Up @@ -203,13 +203,11 @@ class RelativePath {
const currentItemPath = editor.document.fileName.replace(/\\/g, "/").replace(this._workspacePath, "");
let relativeUrl: string = path.relative(currentItemPath, targetPath).replace(".", "").replace(/\\/g, "/");

if (this._configuration.removeExtension) {
relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf("."));
} else if (this.excludeExtensionsFor(relativeUrl)) {
if (this._configuration.removeExtension || this.excludeExtensionsFor(relativeUrl)) {
relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf("."));
}

if (relativeUrl.startsWith("./../")) {
if (this._configuration.removeLeadingDot && relativeUrl.startsWith("./../")) {
relativeUrl = relativeUrl.substring(2, relativeUrl.length);
}

Expand Down