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
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
"type": "boolean",
"default": false,
"description": "Removes the leading ./ character when the path is pointing to a parent folder."
},
"relativePath.excludedExtensions": {
"type": "array",
"default": [
".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)"
}
}
}
Expand Down
18 changes: 16 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import {window, workspace, commands, Disposable,
ExtensionContext, StatusBarAlignment, StatusBarItem,
import {window, workspace, commands, Disposable,
ExtensionContext, StatusBarAlignment, StatusBarItem,
TextDocument, QuickPickItem, FileSystemWatcher, Uri,
TextEditorEdit, TextEditor, Position} from 'vscode';
import * as path from "path";
Expand Down Expand Up @@ -129,6 +129,18 @@ class RelativePath {
}
}

// Check if the current extension should be excluded
private excludeExtensionsFor(relativeUrl: string) {
const currentExtension = path.extname(relativeUrl)
if (currentExtension === '') {
return false;
}

return this._configuration.excludedExtensions.some((ext: string) => {
return (ext.startsWith('.') ? ext : `.${ext}`).toLowerCase() === currentExtension.toLowerCase();
})
}

// Get the picked item
private returnRelativeLink(item: QuickPickItem, editor: TextEditor): void {
if (item) {
Expand All @@ -138,6 +150,8 @@ class RelativePath {

if (this._configuration.removeExtension) {
relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf("."));
} else if (this.excludeExtensionsFor(relativeUrl)) {
relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf("."));
}
if (this._configuration.removeLeadingDot && relativeUrl.startsWith("./../")) {
relativeUrl = relativeUrl.substring(2, relativeUrl.length);
Expand Down