Skip to content

Commit 35f7e49

Browse files
kristofferrembackJakob Werner
authored andcommitted
Add excludeExtensions (#14)
* Add excludedExtensions to config
1 parent 6288023 commit 35f7e49

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@
6464
"type": "boolean",
6565
"default": false,
6666
"description": "Removes the leading ./ character when the path is pointing to a parent folder."
67+
},
68+
"relativePath.excludedExtensions": {
69+
"type": "array",
70+
"default": [
71+
".js"
72+
],
73+
"description": "An array of extensions to exclude from the relative path url (Useful for used with Webpack or when importing files of mixed types)"
6774
}
6875
}
6976
}

src/extension.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// The module 'vscode' contains the VS Code extensibility API
22
// Import the module and reference it with the alias vscode in your code below
3-
import {window, workspace, commands, Disposable,
4-
ExtensionContext, StatusBarAlignment, StatusBarItem,
3+
import {window, workspace, commands, Disposable,
4+
ExtensionContext, StatusBarAlignment, StatusBarItem,
55
TextDocument, QuickPickItem, FileSystemWatcher, Uri,
66
TextEditorEdit, TextEditor, Position} from 'vscode';
77
import * as path from "path";
@@ -129,6 +129,18 @@ class RelativePath {
129129
}
130130
}
131131

132+
// Check if the current extension should be excluded
133+
private excludeExtensionsFor(relativeUrl: string) {
134+
const currentExtension = path.extname(relativeUrl)
135+
if (currentExtension === '') {
136+
return false;
137+
}
138+
139+
return this._configuration.excludedExtensions.some((ext: string) => {
140+
return (ext.startsWith('.') ? ext : `.${ext}`).toLowerCase() === currentExtension.toLowerCase();
141+
})
142+
}
143+
132144
// Get the picked item
133145
private returnRelativeLink(item: QuickPickItem, editor: TextEditor): void {
134146
if (item) {
@@ -138,6 +150,8 @@ class RelativePath {
138150

139151
if (this._configuration.removeExtension) {
140152
relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf("."));
153+
} else if (this.excludeExtensionsFor(relativeUrl)) {
154+
relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf("."));
141155
}
142156
if (this._configuration.removeLeadingDot && relativeUrl.startsWith("./../")) {
143157
relativeUrl = relativeUrl.substring(2, relativeUrl.length);

0 commit comments

Comments
 (0)