From f1d221f23209a0482a8f933cf7fd27b5291a567d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20=C3=96stlund?= Date: Thu, 15 Dec 2016 10:18:27 +0100 Subject: [PATCH 1/2] Add excludeExtensions --- package.json | 7 +++++++ src/extension.ts | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bd1a1d2..7787e88 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,13 @@ "type": "boolean", "default": false, "description": "Removes the leading ./ character when the path is pointing to a parent folder." + }, + "relativePath.excludExtensions": { + "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)" } } } diff --git a/src/extension.ts b/src/extension.ts index fc218f7..1f067f6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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"; @@ -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.excludExtensions.some((ext: string) => { + return (ext.startsWith('.') ? ext : `.${ext}`).toLowerCase() === currentExtension.toLowerCase(); + }) + } + // Get the picked item private returnRelativeLink(item: QuickPickItem, editor: TextEditor): void { if (item) { @@ -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); From d868de68fa65bdf71caff6f3be54608f79ecc6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20=C3=96stlund?= Date: Thu, 15 Dec 2016 10:31:15 +0100 Subject: [PATCH 2/2] Fix spelling in config item --- package.json | 2 +- src/extension.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7787e88..508e6b3 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "default": false, "description": "Removes the leading ./ character when the path is pointing to a parent folder." }, - "relativePath.excludExtensions": { + "relativePath.excludedExtensions": { "type": "array", "default": [ ".js" diff --git a/src/extension.ts b/src/extension.ts index 1f067f6..6b00d45 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -136,7 +136,7 @@ class RelativePath { return false; } - return this._configuration.excludExtensions.some((ext: string) => { + return this._configuration.excludedExtensions.some((ext: string) => { return (ext.startsWith('.') ? ext : `.${ext}`).toLowerCase() === currentExtension.toLowerCase(); }) }