diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 74de308b1c0..50fe2efe1f6 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -738,6 +738,18 @@ export function createApiFactory( }; } +/** + * Returns the original fs path (using the original casing for the drive letter) + */ +export function originalFSPath(uri: URI): string { + const result = uri.fsPath; + if (/^[a-zA-Z]:/.test(result) && uri.path.charAt(1).toLowerCase() === result.charAt(0)) { + // Restore original drive letter casing + return uri.path.charAt(1) + result.substr(1); + } + return result; +} + class Extension implements vscode.Extension { private _extensionService: ExtHostExtensionService; @@ -749,7 +761,7 @@ class Extension implements vscode.Extension { constructor(extensionService: ExtHostExtensionService, description: IExtensionDescription) { this._extensionService = extensionService; this.id = description.id; - this.extensionPath = paths.normalize(description.extensionLocation.fsPath, true); + this.extensionPath = paths.normalize(originalFSPath(description.extensionLocation), true); this.packageJSON = description; } diff --git a/src/vs/workbench/test/electron-browser/api/extHost.api.impl.test.ts b/src/vs/workbench/test/electron-browser/api/extHost.api.impl.test.ts new file mode 100644 index 00000000000..12cbffb4ccf --- /dev/null +++ b/src/vs/workbench/test/electron-browser/api/extHost.api.impl.test.ts @@ -0,0 +1,20 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import * as assert from 'assert'; +import URI from 'vs/base/common/uri'; +import { originalFSPath } from 'vs/workbench/api/node/extHost.api.impl'; + +suite('ExtHost API', function () { + test('issue #51387: originalFSPath', function () { + assert.equal(originalFSPath(URI.file('C:\\test')).charAt(0), 'C'); + assert.equal(originalFSPath(URI.file('c:\\test')).charAt(0), 'c'); + + assert.equal(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('C:\\test'))))).charAt(0), 'C'); + assert.equal(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('c:\\test'))))).charAt(0), 'c'); + }); +});