提交 92a61b8d 编写于 作者: M Martin Aeschlimann

use path.normalize for extpath.normalize(.., true)

上级 ad209fbf
......@@ -30,10 +30,10 @@ export function toForwardSlashes(osPath: string) {
return osPath.replace(/[\\/]/g, '/');
}
export function normalize(path: undefined, toOSPath?: boolean): undefined;
export function normalize(path: null, toOSPath?: boolean): null;
export function normalize(path: string, toOSPath?: boolean): string;
export function normalize(path: string | null | undefined, toOSPath?: boolean): string | null | undefined {
export function normalize(path: undefined): undefined;
export function normalize(path: null): null;
export function normalize(path: string): string;
export function normalize(path: string | null | undefined): string | null | undefined {
if (path === null || path === undefined) {
return path;
......@@ -44,12 +44,11 @@ export function normalize(path: string | null | undefined, toOSPath?: boolean):
return '.';
}
const wantsBackslash = !!(isWindows && toOSPath);
if (_isNormal(path, wantsBackslash)) {
if (_isNormal(path, false)) {
return path;
}
const sep = wantsBackslash ? '\\' : '/';
const sep = '/';
const root = getRoot(path, sep);
// skip the root-portion of the path
......
......@@ -4,8 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { URI } from 'vs/base/common/uri';
import { normalize } from 'vs/base/common/extpath';
import { sep, posix } from 'vs/base/common/path';
import { sep, posix, normalize } from 'vs/base/common/path';
import { endsWith, ltrim, startsWithIgnoreCase, rtrim, startsWith } from 'vs/base/common/strings';
import { Schemas } from 'vs/base/common/network';
import { isLinux, isWindows, isMacintosh } from 'vs/base/common/platform';
......@@ -40,7 +39,8 @@ export function getPathLabel(resource: URI | string, userHomeProvider?: IUserHom
if (isEqual(baseResource.uri, resource, !isLinux)) {
pathLabel = ''; // no label if paths are identical
} else {
pathLabel = normalize(ltrim(resource.path.substr(baseResource.uri.path.length), posix.sep)!, true);
// TODO: isidor use resources.relative
pathLabel = normalize(ltrim(resource.path.substr(baseResource.uri.path.length), posix.sep)!);
}
if (hasMultipleRoots) {
......@@ -59,11 +59,11 @@ export function getPathLabel(resource: URI | string, userHomeProvider?: IUserHom
// convert c:\something => C:\something
if (hasDriveLetter(resource.fsPath)) {
return normalize(normalizeDriveLetter(resource.fsPath), true);
return normalize(normalizeDriveLetter(resource.fsPath));
}
// normalize and tildify (macOS, Linux only)
let res = normalize(resource.fsPath, true);
let res = normalize(resource.fsPath);
if (!isWindows && userHomeProvider) {
res = tildify(res, userHomeProvider.userHome);
}
......
......@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { normalize } from 'vs/base/common/extpath';
import { isWindows } from 'vs/base/common/platform';
......@@ -141,7 +140,6 @@ suite('URI', () => {
assert.equal(value.scheme, 'http');
assert.equal(value.authority, 'api');
assert.equal(value.path, '/files/test.me');
assert.equal(value.fsPath, normalize('/files/test.me', true));
assert.equal(value.query, 't=1234');
assert.equal(value.fragment, '');
......@@ -151,7 +149,7 @@ suite('URI', () => {
assert.equal(value.path, '/c:/test/me');
assert.equal(value.fragment, '');
assert.equal(value.query, '');
assert.equal(value.fsPath, normalize('c:/test/me', true));
assert.equal(value.fsPath, isWindows ? 'c:\\test\\me' : 'c:/test/me');
value = URI.parse('file://shares/files/c%23/p.cs');
assert.equal(value.scheme, 'file');
......@@ -159,7 +157,7 @@ suite('URI', () => {
assert.equal(value.path, '/files/c#/p.cs');
assert.equal(value.fragment, '');
assert.equal(value.query, '');
assert.equal(value.fsPath, normalize('//shares/files/c#/p.cs', true));
assert.equal(value.fsPath, isWindows ? '\\\\shares\\files\\c#\\p.cs' : '//shares/files/c#/p.cs');
value = URI.parse('file:///c:/Source/Z%C3%BCrich%20or%20Zurich%20(%CB%88zj%CA%8A%C9%99r%C9%AAk,/Code/resources/app/plugins/c%23/plugin.json');
assert.equal(value.scheme, 'file');
......@@ -360,7 +358,6 @@ suite('URI', () => {
test('correctFileUriToFilePath2', () => {
const test = (input: string, expected: string) => {
expected = normalize(expected, true);
const value = URI.parse(input);
assert.equal(value.fsPath, expected, 'Result for ' + input);
const value2 = URI.file(value.fsPath);
......@@ -368,10 +365,10 @@ suite('URI', () => {
assert.equal(value.toString(), value2.toString());
};
test('file:///c:/alex.txt', 'c:\\alex.txt');
test('file:///c:/Source/Z%C3%BCrich%20or%20Zurich%20(%CB%88zj%CA%8A%C9%99r%C9%AAk,/Code/resources/app/plugins', 'c:\\Source\\Zürich or Zurich (ˈzjʊərɪk,\\Code\\resources\\app\\plugins');
test('file://monacotools/folder/isi.txt', '\\\\monacotools\\folder\\isi.txt');
test('file://monacotools1/certificates/SSL/', '\\\\monacotools1\\certificates\\SSL\\');
test('file:///c:/alex.txt', isWindows ? 'c:\\alex.txt' : 'c:/alex.txt');
test('file:///c:/Source/Z%C3%BCrich%20or%20Zurich%20(%CB%88zj%CA%8A%C9%99r%C9%AAk,/Code/resources/app/plugins', isWindows ? 'c:\\Source\\Zürich or Zurich (ˈzjʊərɪk,\\Code\\resources\\app\\plugins' : 'c:/Source/Zürich or Zurich (ˈzjʊərɪk,/Code/resources/app/plugins');
test('file://monacotools/folder/isi.txt', isWindows ? '\\\\monacotools\\folder\\isi.txt' : '//monacotools/folder/isi.txt');
test('file://monacotools1/certificates/SSL/', isWindows ? '\\\\monacotools1\\certificates\\SSL\\' : '//monacotools1/certificates/SSL/');
});
test('URI - http, query & toString', function () {
......
......@@ -179,7 +179,7 @@ export function massageFolderPathForWorkspace(absoluteFolderPath: string, target
if (isWindows) {
if (isAbsolute(absoluteFolderPath)) {
if (shouldUseSlashForPath(existingFolders)) {
absoluteFolderPath = normalize(absoluteFolderPath, false /* do not use OS path separator */);
absoluteFolderPath = normalize(absoluteFolderPath /* do not use OS path separator */);
}
absoluteFolderPath = normalizeDriveLetter(absoluteFolderPath);
......
......@@ -8,7 +8,7 @@ import { CancellationTokenSource } from 'vs/base/common/cancellation';
import * as errors from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import { TernarySearchTree } from 'vs/base/common/map';
import * as extpath from 'vs/base/common/extpath';
import * as path from 'vs/base/common/path';
import * as platform from 'vs/base/common/platform';
import Severity from 'vs/base/common/severity';
import { URI } from 'vs/base/common/uri';
......@@ -866,7 +866,7 @@ class Extension<T> implements vscode.Extension<T> {
this._extensionService = extensionService;
this._identifier = description.identifier;
this.id = description.identifier.value;
this.extensionPath = extpath.normalize(originalFSPath(description.extensionLocation), true);
this.extensionPath = path.normalize(originalFSPath(description.extensionLocation));
this.packageJSON = description;
}
......
......@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as extpath from 'vs/base/common/extpath';
import * as path from 'vs/base/common/path';
import { Schemas } from 'vs/base/common/network';
import { URI, UriComponents } from 'vs/base/common/uri';
import { Event, Emitter } from 'vs/base/common/event';
......@@ -881,7 +881,7 @@ export class ExtHostVariableResolverService extends AbstractVariableResolverServ
if (activeEditor) {
const resource = activeEditor.document.uri;
if (resource.scheme === Schemas.file) {
return extpath.normalize(resource.fsPath, true);
return path.normalize(resource.fsPath);
}
}
return undefined;
......
......@@ -354,7 +354,7 @@ export class ExtHostWorkspaceProvider {
if (includeWorkspace) {
result = `${folder.name}/${result}`;
}
return normalize(result, true);
return normalize(result);
}
private trySetWorkspaceFolders(folders: vscode.WorkspaceFolder[]): void {
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { hasWorkspaceFileExtension, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
import { normalize } from 'vs/base/common/extpath';
import { normalize } from 'vs/base/common/path';
import { basename, basenameOrAuthority } from 'vs/base/common/resources';
import { IFileService } from 'vs/platform/files/common/files';
import { IWindowsService, IWindowService, IURIToOpen } from 'vs/platform/windows/common/windows';
......@@ -368,7 +368,7 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources:
// Text: allows to paste into text-capable areas
const lineDelimiter = isWindows ? '\r\n' : '\n';
event.dataTransfer.setData(DataTransfers.TEXT, sources.map(source => source.resource.scheme === Schemas.file ? normalize(normalizeDriveLetter(source.resource.fsPath), true) : source.resource.toString()).join(lineDelimiter));
event.dataTransfer.setData(DataTransfers.TEXT, sources.map(source => source.resource.scheme === Schemas.file ? normalize(normalizeDriveLetter(source.resource.fsPath)) : source.resource.toString()).join(lineDelimiter));
// Download URL: enables support to drag a tab as file to desktop (only single file supported)
if (firstSource.resource.scheme === Schemas.file) {
......
......@@ -6,7 +6,7 @@
import * as assert from 'assert';
import { URI as uri } from 'vs/base/common/uri';
import { Source } from 'vs/workbench/contrib/debug/common/debugSource';
import { normalize } from 'vs/base/common/extpath';
import { isWindows } from 'vs/base/common/platform';
suite('Debug - Source', () => {
......@@ -48,8 +48,8 @@ suite('Debug - Source', () => {
assert.equal(sessionId, expectedSessionId);
};
checkData(uri.file('a/b/c/d'), 'd', normalize('/a/b/c/d', true), undefined, undefined);
checkData(uri.from({ scheme: 'file', path: '/my/path/test.js', query: 'ref=1&session=2' }), 'test.js', normalize('/my/path/test.js', true), undefined, undefined);
checkData(uri.file('a/b/c/d'), 'd', isWindows ? '\\a\\b\\c\\d' : '/a/b/c/d', undefined, undefined);
checkData(uri.from({ scheme: 'file', path: '/my/path/test.js', query: 'ref=1&session=2' }), 'test.js', isWindows ? '\\my\\path\\test.js' : '/my/path/test.js', undefined, undefined);
checkData(uri.from({ scheme: 'http', authority: 'www.msft.com', path: '/my/path' }), 'path', 'http://www.msft.com/my/path', undefined, undefined);
checkData(uri.from({ scheme: 'debug', authority: 'www.msft.com', path: '/my/path', query: 'ref=100' }), 'path', '/my/path', 100, undefined);
......
......@@ -2520,14 +2520,14 @@ export class OpenExtensionsFolderAction extends Action {
}
run(): Promise<void> {
const extensionsHome = this.environmentService.extensionsPath;
const extensionsHome = URI.file(this.environmentService.extensionsPath);
return Promise.resolve(this.fileService.resolveFile(URI.file(extensionsHome))).then(file => {
return Promise.resolve(this.fileService.resolveFile(extensionsHome)).then(file => {
let itemToShow: string;
if (file.children && file.children.length > 0) {
itemToShow = file.children[0].resource.fsPath;
} else {
itemToShow = extpath.normalize(extensionsHome, true);
itemToShow = extensionsHome.fsPath;
}
return this.windowsService.showItemInFolder(itemToShow);
......
......@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import * as extpath from 'vs/base/common/extpath';
import { URI } from 'vs/base/common/uri';
import { toResource, IEditorCommandsContext } from 'vs/workbench/common/editor';
import { IWindowsService, IWindowService, IURIToOpen } from 'vs/platform/windows/common/windows';
......@@ -358,9 +357,9 @@ CommandsRegistry.registerCommand({
function revealResourcesInOS(resources: URI[], windowsService: IWindowsService, notificationService: INotificationService, workspaceContextService: IWorkspaceContextService): void {
if (resources.length) {
sequence(resources.map(r => () => windowsService.showItemInFolder(extpath.normalize(r.fsPath, true))));
sequence(resources.map(r => () => windowsService.showItemInFolder(r.fsPath)));
} else if (workspaceContextService.getWorkspace().folders.length) {
windowsService.showItemInFolder(extpath.normalize(workspaceContextService.getWorkspace().folders[0].uri.fsPath, true));
windowsService.showItemInFolder(workspaceContextService.getWorkspace().folders[0].uri.fsPath);
} else {
notificationService.info(nls.localize('openFileToReveal', "Open a file first to reveal"));
}
......
......@@ -26,7 +26,6 @@ import { localize } from 'vs/nls';
import { attachInputBoxStyler } from 'vs/platform/theme/common/styler';
import { once } from 'vs/base/common/functional';
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { normalize } from 'vs/base/common/extpath';
import { equals, deepClone } from 'vs/base/common/objects';
import * as path from 'vs/base/common/path';
import { ExplorerItem } from 'vs/workbench/contrib/files/common/explorerModel';
......@@ -313,7 +312,8 @@ export class FilesFilter implements ITreeFilter<ExplorerItem, FuzzyScore> {
// Hide those that match Hidden Patterns
const cached = this.hiddenExpressionPerRoot.get(stat.root.resource.toString());
if (cached && cached.parsed(normalize(path.relative(stat.root.resource.path, stat.resource.path), true), stat.name, name => !!stat.parent.getChild(name))) {
if (cached && cached.parsed(path.normalize(path.relative(stat.root.resource.path, stat.resource.path)), stat.name, name => !!stat.parent.getChild(name))) {
// review (isidor): is path.normalize necessary? path.relative already returns an os path
return false; // hidden through pattern
}
......
......@@ -8,6 +8,7 @@ import { ILink } from 'vs/editor/common/modes';
import { URI } from 'vs/base/common/uri';
import * as extpath from 'vs/base/common/extpath';
import * as resources from 'vs/base/common/resources';
import * as path from 'vs/base/common/path';
import * as strings from 'vs/base/common/strings';
import * as arrays from 'vs/base/common/arrays';
import { Range } from 'vs/editor/common/core/range';
......@@ -88,8 +89,8 @@ export class OutputLinkComputer {
const workspaceFolderPath = workspaceFolder.scheme === 'file' ? workspaceFolder.fsPath : workspaceFolder.path;
const workspaceFolderVariants = arrays.distinct([
extpath.normalize(workspaceFolderPath, true),
extpath.normalize(workspaceFolderPath, false)
path.normalize(workspaceFolderPath),
extpath.normalize(workspaceFolderPath)
]);
workspaceFolderVariants.forEach(workspaceFolderVariant => {
......
......@@ -9,7 +9,7 @@ import { INavigator } from 'vs/base/common/iterator';
import { createKeybinding, ResolvedKeybinding } from 'vs/base/common/keyCodes';
import { normalizeDriveLetter } from 'vs/base/common/labels';
import { Schemas } from 'vs/base/common/network';
import { normalize } from 'vs/base/common/extpath';
import { normalize } from 'vs/base/common/path';
import { isWindows, OS } from 'vs/base/common/platform';
import { repeat } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
......@@ -640,7 +640,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
}
function uriToClipboardString(resource: URI): string {
return resource.scheme === Schemas.file ? normalize(normalizeDriveLetter(resource.fsPath), true) : resource.toString();
return resource.scheme === Schemas.file ? normalize(normalizeDriveLetter(resource.fsPath)) : resource.toString();
}
export const copyPathCommand: ICommandHandler = (accessor, fileMatch: FileMatch | FolderMatch) => {
......
......@@ -5,7 +5,7 @@
import * as Collections from 'vs/base/common/collections';
import * as Objects from 'vs/base/common/objects';
import * as Extpath from 'vs/base/common/extpath';
import * as Path from 'vs/base/common/path';
import { CommandOptions, ErrorData, Source } from 'vs/base/common/processes';
import * as Strings from 'vs/base/common/strings';
import { LineData, LineProcess } from 'vs/base/node/processes';
......@@ -156,7 +156,7 @@ export class ProcessRunnerDetector {
this._workspaceRoot = workspaceFolder;
this._stderr = [];
this._stdout = [];
this._cwd = this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY ? Extpath.normalize(this._workspaceRoot.uri.fsPath, true) : '';
this._cwd = this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY ? Path.normalize(this._workspaceRoot.uri.fsPath) : '';
}
public get stderr(): string[] {
......
......@@ -5,7 +5,7 @@
import { URI as uri } from 'vs/base/common/uri';
import * as nls from 'vs/nls';
import * as extpath from 'vs/base/common/extpath';
import * as path from 'vs/base/common/path';
import * as platform from 'vs/base/common/platform';
import * as Types from 'vs/base/common/types';
import { Schemas } from 'vs/base/common/network';
......@@ -58,7 +58,7 @@ export class ConfigurationResolverService extends AbstractVariableResolverServic
if (!fileResource) {
return undefined;
}
return extpath.normalize(fileResource.fsPath, true);
return path.normalize(fileResource.fsPath);
},
getSelectedText: (): string | undefined => {
const activeTextEditorWidget = editorService.activeTextEditorWidget;
......
......@@ -6,7 +6,6 @@
import * as assert from 'assert';
import * as path from 'vs/base/common/path';
import { getPathFromAmdModule } from 'vs/base/common/amd';
import { join, normalize } from 'vs/base/common/extpath';
import * as platform from 'vs/base/common/platform';
import { joinPath } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
......@@ -188,7 +187,7 @@ suite('FileSearchEngine', () => {
const engine = new FileSearchEngine({
type: QueryType.File,
folderQueries: ROOT_FOLDER_QUERY,
filePattern: normalize(join('examples', 'com*'), true)
filePattern: path.join('examples', 'com*')
});
let count = 0;
......
......@@ -35,7 +35,7 @@ suite('ExtHostWorkspace', function () {
if (actual === expected) {
assert.ok(true);
} else {
assert.equal(actual, normalize(expected, true));
assert.equal(actual, normalize(expected));
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册