Skip to content

Commit a06dbfc

Browse files
committed
rename extpath.normalize to extpath.normalizeWithSlash
1 parent 92a61b8 commit a06dbfc

12 files changed

Lines changed: 87 additions & 103 deletions

File tree

src/vs/base/common/extpath.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ function _isNormal(path: string, win: boolean): boolean {
2626
* This should only be done for OS paths from Windows (or user provided paths potentially from Windows).
2727
* Using it on a Linux or MaxOS path might change it.
2828
*/
29-
export function toForwardSlashes(osPath: string) {
29+
export function toSlashes(osPath: string) {
3030
return osPath.replace(/[\\/]/g, '/');
3131
}
3232

33-
export function normalize(path: undefined): undefined;
34-
export function normalize(path: null): null;
35-
export function normalize(path: string): string;
36-
export function normalize(path: string | null | undefined): string | null | undefined {
33+
export function normalizeWithSlashes(path: undefined): undefined;
34+
export function normalizeWithSlashes(path: null): null;
35+
export function normalizeWithSlashes(path: string): string;
36+
export function normalizeWithSlashes(path: string | null | undefined): string | null | undefined {
3737

3838
if (path === null || path === undefined) {
3939
return path;
@@ -115,7 +115,7 @@ export const join: (...parts: string[]) => string = function () {
115115
value += part;
116116
}
117117

118-
return normalize(value);
118+
return normalizeWithSlashes(value);
119119
};
120120

121121

src/vs/base/common/resources.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export function relativePath(from: URI, to: URI): string | undefined {
204204
}
205205
if (from.scheme === Schemas.file) {
206206
const relativePath = paths.relative(from.path, to.path);
207-
return isWindows ? extpath.toForwardSlashes(relativePath) : relativePath;
207+
return isWindows ? extpath.toSlashes(relativePath) : relativePath;
208208
}
209209
return paths.posix.relative(from.path || '/', to.path || '/');
210210
}

src/vs/base/test/common/extpath.test.ts

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,54 @@ import * as platform from 'vs/base/common/platform';
99
suite('Paths', () => {
1010

1111
test('toForwardSlashes', () => {
12-
assert.equal(extpath.toForwardSlashes('\\\\server\\share\\some\\path'), '//server/share/some/path');
13-
assert.equal(extpath.toForwardSlashes('c:\\test'), 'c:/test');
14-
assert.equal(extpath.toForwardSlashes('foo\\bar'), 'foo/bar');
15-
assert.equal(extpath.toForwardSlashes('/user/far'), '/user/far');
12+
assert.equal(extpath.toSlashes('\\\\server\\share\\some\\path'), '//server/share/some/path');
13+
assert.equal(extpath.toSlashes('c:\\test'), 'c:/test');
14+
assert.equal(extpath.toSlashes('foo\\bar'), 'foo/bar');
15+
assert.equal(extpath.toSlashes('/user/far'), '/user/far');
1616
});
1717

1818

1919
test('normalize', () => {
20-
assert.equal(extpath.normalize(''), '.');
21-
assert.equal(extpath.normalize('.'), '.');
22-
assert.equal(extpath.normalize('.'), '.');
23-
assert.equal(extpath.normalize('../../far'), '../../far');
24-
assert.equal(extpath.normalize('../bar'), '../bar');
25-
assert.equal(extpath.normalize('../far'), '../far');
26-
assert.equal(extpath.normalize('./'), './');
27-
assert.equal(extpath.normalize('./././'), './');
28-
assert.equal(extpath.normalize('./ff/./'), 'ff/');
29-
assert.equal(extpath.normalize('./foo'), 'foo');
30-
assert.equal(extpath.normalize('/'), '/');
31-
assert.equal(extpath.normalize('/..'), '/');
32-
assert.equal(extpath.normalize('///'), '/');
33-
assert.equal(extpath.normalize('//foo'), '/foo');
34-
assert.equal(extpath.normalize('//foo//'), '/foo/');
35-
assert.equal(extpath.normalize('/foo'), '/foo');
36-
assert.equal(extpath.normalize('/foo/bar.test'), '/foo/bar.test');
37-
assert.equal(extpath.normalize('\\\\\\'), '/');
38-
assert.equal(extpath.normalize('c:/../ff'), 'c:/ff');
39-
assert.equal(extpath.normalize('c:\\./'), 'c:/');
40-
assert.equal(extpath.normalize('foo/'), 'foo/');
41-
assert.equal(extpath.normalize('foo/../../bar'), '../bar');
42-
assert.equal(extpath.normalize('foo/./'), 'foo/');
43-
assert.equal(extpath.normalize('foo/./bar'), 'foo/bar');
44-
assert.equal(extpath.normalize('foo//'), 'foo/');
45-
assert.equal(extpath.normalize('foo//'), 'foo/');
46-
assert.equal(extpath.normalize('foo//bar'), 'foo/bar');
47-
assert.equal(extpath.normalize('foo//bar/far'), 'foo/bar/far');
48-
assert.equal(extpath.normalize('foo/bar/../../far'), 'far');
49-
assert.equal(extpath.normalize('foo/bar/../far'), 'foo/far');
50-
assert.equal(extpath.normalize('foo/far/../../bar'), 'bar');
51-
assert.equal(extpath.normalize('foo/far/../../bar'), 'bar');
52-
assert.equal(extpath.normalize('foo/xxx/..'), 'foo');
53-
assert.equal(extpath.normalize('foo/xxx/../bar'), 'foo/bar');
54-
assert.equal(extpath.normalize('foo/xxx/./..'), 'foo');
55-
assert.equal(extpath.normalize('foo/xxx/./../bar'), 'foo/bar');
56-
assert.equal(extpath.normalize('foo/xxx/./bar'), 'foo/xxx/bar');
57-
assert.equal(extpath.normalize('foo\\bar'), 'foo/bar');
58-
assert.equal(extpath.normalize(null), null);
59-
assert.equal(extpath.normalize(undefined), undefined);
20+
assert.equal(extpath.normalizeWithSlashes(''), '.');
21+
assert.equal(extpath.normalizeWithSlashes('.'), '.');
22+
assert.equal(extpath.normalizeWithSlashes('.'), '.');
23+
assert.equal(extpath.normalizeWithSlashes('../../far'), '../../far');
24+
assert.equal(extpath.normalizeWithSlashes('../bar'), '../bar');
25+
assert.equal(extpath.normalizeWithSlashes('../far'), '../far');
26+
assert.equal(extpath.normalizeWithSlashes('./'), './');
27+
assert.equal(extpath.normalizeWithSlashes('./././'), './');
28+
assert.equal(extpath.normalizeWithSlashes('./ff/./'), 'ff/');
29+
assert.equal(extpath.normalizeWithSlashes('./foo'), 'foo');
30+
assert.equal(extpath.normalizeWithSlashes('/'), '/');
31+
assert.equal(extpath.normalizeWithSlashes('/..'), '/');
32+
assert.equal(extpath.normalizeWithSlashes('///'), '/');
33+
assert.equal(extpath.normalizeWithSlashes('//foo'), '/foo');
34+
assert.equal(extpath.normalizeWithSlashes('//foo//'), '/foo/');
35+
assert.equal(extpath.normalizeWithSlashes('/foo'), '/foo');
36+
assert.equal(extpath.normalizeWithSlashes('/foo/bar.test'), '/foo/bar.test');
37+
assert.equal(extpath.normalizeWithSlashes('\\\\\\'), '/');
38+
assert.equal(extpath.normalizeWithSlashes('c:/../ff'), 'c:/ff');
39+
assert.equal(extpath.normalizeWithSlashes('c:\\./'), 'c:/');
40+
assert.equal(extpath.normalizeWithSlashes('foo/'), 'foo/');
41+
assert.equal(extpath.normalizeWithSlashes('foo/../../bar'), '../bar');
42+
assert.equal(extpath.normalizeWithSlashes('foo/./'), 'foo/');
43+
assert.equal(extpath.normalizeWithSlashes('foo/./bar'), 'foo/bar');
44+
assert.equal(extpath.normalizeWithSlashes('foo//'), 'foo/');
45+
assert.equal(extpath.normalizeWithSlashes('foo//'), 'foo/');
46+
assert.equal(extpath.normalizeWithSlashes('foo//bar'), 'foo/bar');
47+
assert.equal(extpath.normalizeWithSlashes('foo//bar/far'), 'foo/bar/far');
48+
assert.equal(extpath.normalizeWithSlashes('foo/bar/../../far'), 'far');
49+
assert.equal(extpath.normalizeWithSlashes('foo/bar/../far'), 'foo/far');
50+
assert.equal(extpath.normalizeWithSlashes('foo/far/../../bar'), 'bar');
51+
assert.equal(extpath.normalizeWithSlashes('foo/far/../../bar'), 'bar');
52+
assert.equal(extpath.normalizeWithSlashes('foo/xxx/..'), 'foo');
53+
assert.equal(extpath.normalizeWithSlashes('foo/xxx/../bar'), 'foo/bar');
54+
assert.equal(extpath.normalizeWithSlashes('foo/xxx/./..'), 'foo');
55+
assert.equal(extpath.normalizeWithSlashes('foo/xxx/./../bar'), 'foo/bar');
56+
assert.equal(extpath.normalizeWithSlashes('foo/xxx/./bar'), 'foo/xxx/bar');
57+
assert.equal(extpath.normalizeWithSlashes('foo\\bar'), 'foo/bar');
58+
assert.equal(extpath.normalizeWithSlashes(null), null);
59+
assert.equal(extpath.normalizeWithSlashes(undefined), undefined);
6060

6161
// https://github.com/Microsoft/vscode/issues/7234
6262
assert.equal(extpath.join('/home/aeschli/workspaces/vscode/extensions/css', './syntaxes/css.plist'), '/home/aeschli/workspaces/vscode/extensions/css/syntaxes/css.plist');

src/vs/platform/workspaces/common/workspaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { localize } from 'vs/nls';
88
import { Event } from 'vs/base/common/event';
99
import { IWorkspaceFolder, IWorkspace } from 'vs/platform/workspace/common/workspace';
1010
import { URI, UriComponents } from 'vs/base/common/uri';
11-
import { isEqualOrParent, normalize } from 'vs/base/common/extpath';
11+
import { isEqualOrParent, normalizeWithSlashes } from 'vs/base/common/extpath';
1212
import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform';
1313
import { isAbsolute, relative, posix, resolve, extname } from 'vs/base/common/path';
1414
import { normalizeDriveLetter } from 'vs/base/common/labels';
@@ -179,7 +179,7 @@ export function massageFolderPathForWorkspace(absoluteFolderPath: string, target
179179
if (isWindows) {
180180
if (isAbsolute(absoluteFolderPath)) {
181181
if (shouldUseSlashForPath(existingFolders)) {
182-
absoluteFolderPath = normalize(absoluteFolderPath /* do not use OS path separator */);
182+
absoluteFolderPath = normalizeWithSlashes(absoluteFolderPath /* do not use OS path separator */);
183183
}
184184

185185
absoluteFolderPath = normalizeDriveLetter(absoluteFolderPath);

src/vs/workbench/api/node/extHostWorkspace.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { join, relative } from 'vs/base/common/path';
6+
import { join } from 'vs/base/common/path';
77
import { delta as arrayDelta, mapArrayOrNot } from 'vs/base/common/arrays';
88
import { CancellationToken } from 'vs/base/common/cancellation';
99
import { Emitter, Event } from 'vs/base/common/event';
1010
import { TernarySearchTree } from 'vs/base/common/map';
1111
import { Counter } from 'vs/base/common/numbers';
12-
import { normalize } from 'vs/base/common/extpath';
1312
import { isLinux } from 'vs/base/common/platform';
14-
import { basenameOrAuthority, dirname, isEqual } from 'vs/base/common/resources';
13+
import { basenameOrAuthority, dirname, isEqual, relativePath } from 'vs/base/common/resources';
1514
import { compare } from 'vs/base/common/strings';
1615
import { URI } from 'vs/base/common/uri';
1716
import { localize } from 'vs/nls';
@@ -326,35 +325,35 @@ export class ExtHostWorkspaceProvider {
326325

327326
getRelativePath(pathOrUri: string | vscode.Uri, includeWorkspace?: boolean): string | undefined {
328327

329-
let path: string | undefined;
328+
let resource: URI | undefined;
330329
if (typeof pathOrUri === 'string') {
331-
path = pathOrUri;
330+
resource = URI.file(pathOrUri);
332331
} else if (typeof pathOrUri !== 'undefined') {
333-
path = pathOrUri.fsPath;
332+
resource = pathOrUri;
334333
}
335334

336-
if (!path) {
337-
return path;
335+
if (!resource) {
336+
return undefined;
338337
}
339338

340339
const folder = this.getWorkspaceFolder(
341-
typeof pathOrUri === 'string' ? URI.file(pathOrUri) : pathOrUri,
340+
resource,
342341
true
343342
);
344343

345344
if (!folder) {
346-
return path;
345+
return resource.fsPath;
347346
}
348347

349348
if (typeof includeWorkspace === 'undefined' && this._actualWorkspace) {
350349
includeWorkspace = this._actualWorkspace.folders.length > 1;
351350
}
352351

353-
let result = relative(folder.uri.fsPath, path);
354-
if (includeWorkspace) {
352+
let result = relativePath(folder.uri, resource);
353+
if (includeWorkspace && folder.name) {
355354
result = `${folder.name}/${result}`;
356355
}
357-
return normalize(result);
356+
return result;
358357
}
359358

360359
private trySetWorkspaceFolders(folders: vscode.WorkspaceFolder[]): void {

src/vs/workbench/common/resources.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { URI } from 'vs/base/common/uri';
7-
import * as extpath from 'vs/base/common/extpath';
87
import * as objects from 'vs/base/common/objects';
98
import { Event, Emitter } from 'vs/base/common/event';
10-
import { relative } from 'vs/base/common/path';
11-
import { basename, extname } from 'vs/base/common/resources';
9+
import { basename, extname, relativePath } from 'vs/base/common/resources';
1210
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
1311
import { IModeService } from 'vs/editor/common/services/modeService';
1412
import { IFileService } from 'vs/platform/files/common/files';
@@ -197,9 +195,9 @@ export class ResourceGlobMatcher extends Disposable {
197195
// but can match on "src/file.txt"
198196
let resourcePathToMatch: string;
199197
if (folder) {
200-
resourcePathToMatch = extpath.normalize(relative(folder.uri.fsPath, resource.fsPath));
198+
resourcePathToMatch = relativePath(folder.uri, resource); // always uses forward slashes
201199
} else {
202-
resourcePathToMatch = resource.fsPath;
200+
resourcePathToMatch = resource.fsPath; // TODO@isidor: support non-file URIs
203201
}
204202

205203
return !!expressionForRoot(resourcePathToMatch);

src/vs/workbench/contrib/output/common/outputLinkComputer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class OutputLinkComputer {
9090
const workspaceFolderPath = workspaceFolder.scheme === 'file' ? workspaceFolder.fsPath : workspaceFolder.path;
9191
const workspaceFolderVariants = arrays.distinct([
9292
path.normalize(workspaceFolderPath),
93-
extpath.normalize(workspaceFolderPath)
93+
extpath.normalizeWithSlashes(workspaceFolderPath)
9494
]);
9595

9696
workspaceFolderVariants.forEach(workspaceFolderVariant => {

src/vs/workbench/contrib/search/browser/search.contribution.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import 'vs/css!./media/search.contribution';
77

8-
import { relative } from 'vs/base/common/path';
98
import { Action } from 'vs/base/common/actions';
109
import { distinct } from 'vs/base/common/arrays';
1110
import { illegalArgument } from 'vs/base/common/errors';
@@ -358,7 +357,7 @@ const searchInFolderCommand: ICommandHandler = (accessor, resource?: URI) => {
358357
}
359358
});
360359

361-
searchView.searchInFolders(distinct(folders, folder => folder.toString()), (from, to) => relative(from, to));
360+
searchView.searchInFolders(distinct(folders, folder => folder.toString()));
362361
});
363362
}
364363

@@ -394,7 +393,7 @@ CommandsRegistry.registerCommand({
394393
id: FIND_IN_WORKSPACE_ID,
395394
handler: (accessor) => {
396395
return openSearchView(accessor.get(IViewletService), accessor.get(IPanelService), true).then(searchView => {
397-
searchView.searchInFolders(null, (from, to) => relative(from, to));
396+
searchView.searchInFolders(null);
398397
});
399398
}
400399
});

src/vs/workbench/contrib/search/browser/searchView.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { Emitter, Event } from 'vs/base/common/event';
1717
import { Iterator } from 'vs/base/common/iterator';
1818
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
1919
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
20-
import * as extpath from 'vs/base/common/extpath';
2120
import * as env from 'vs/base/common/platform';
2221
import * as strings from 'vs/base/common/strings';
2322
import { URI } from 'vs/base/common/uri';
@@ -62,6 +61,7 @@ import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editor
6261
import { IPartService } from 'vs/workbench/services/part/common/partService';
6362
import { IPreferencesService, ISettingsEditorOptions } from 'vs/workbench/services/preferences/common/preferences';
6463
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
64+
import { relativePath } from 'vs/base/common/resources';
6565

6666
const $ = dom.$;
6767

@@ -1076,7 +1076,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
10761076
}
10771077
}
10781078

1079-
searchInFolders(resources: URI[], pathToRelative: (from: string, to: string) => string): void {
1079+
searchInFolders(resources: URI[]): void {
10801080
const folderPaths: string[] = [];
10811081
const workspace = this.contextService.getWorkspace();
10821082

@@ -1085,7 +1085,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
10851085
let folderPath: string | undefined;
10861086
if (this.contextService.getWorkbenchState() === WorkbenchState.FOLDER) {
10871087
// Show relative path from the root for single-root mode
1088-
folderPath = extpath.normalize(pathToRelative(workspace.folders[0].uri.fsPath, resource.fsPath));
1088+
folderPath = relativePath(workspace.folders[0].uri, resource); // always uses forward slashes
10891089
if (folderPath && folderPath !== '.') {
10901090
folderPath = './' + folderPath;
10911091
}
@@ -1097,14 +1097,14 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
10971097
// If this root is the only one with its basename, use a relative ./ path. If there is another, use an absolute path
10981098
const isUniqueFolder = workspace.folders.filter(folder => folder.name === owningRootName).length === 1;
10991099
if (isUniqueFolder) {
1100-
const relativePath = extpath.normalize(pathToRelative(owningFolder.uri.fsPath, resource.fsPath));
1101-
if (relativePath === '.') {
1100+
const relPath = relativePath(owningFolder.uri, resource); // always uses forward slashes
1101+
if (relPath === '') {
11021102
folderPath = `./${owningFolder.name}`;
11031103
} else {
11041104
folderPath = `./${owningFolder.name}/${relativePath}`;
11051105
}
11061106
} else {
1107-
folderPath = resource.fsPath;
1107+
folderPath = resource.fsPath; // TODO rob: handle on-file URIs
11081108
}
11091109
}
11101110
}

src/vs/workbench/services/configuration/node/configuration.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import * as collections from 'vs/base/common/collections';
1414
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
1515
import { RunOnceScheduler, Delayer } from 'vs/base/common/async';
1616
import { FileChangeType, FileChangesEvent, IContent, IFileService } from 'vs/platform/files/common/files';
17-
import { isLinux } from 'vs/base/common/platform';
1817
import { ConfigurationModel } from 'vs/platform/configuration/common/configurationModels';
1918
import { WorkspaceConfigurationModelParser, FolderSettingsModelParser, StandaloneConfigurationModelParser } from 'vs/workbench/services/configuration/common/configurationModels';
2019
import { FOLDER_SETTINGS_PATH, TASKS_CONFIGURATION_KEY, FOLDER_SETTINGS_NAME, LAUNCH_CONFIGURATION_KEY } from 'vs/workbench/services/configuration/common/configuration';
@@ -23,7 +22,7 @@ import * as extfs from 'vs/base/node/extfs';
2322
import { JSONEditingService } from 'vs/workbench/services/configuration/node/jsonEditingService';
2423
import { WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
2524
import { ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
26-
import { relative, extname } from 'vs/base/common/path';
25+
import { extname } from 'vs/base/common/path';
2726
import { equals } from 'vs/base/common/objects';
2827
import { Schemas } from 'vs/base/common/network';
2928
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
@@ -530,14 +529,8 @@ export class FileServiceBasedFolderConfiguration extends AbstractFolderConfigura
530529
}
531530

532531
private toFolderRelativePath(resource: URI): string | null {
533-
if (resource.scheme === Schemas.file) {
534-
if (extpath.isEqualOrParent(resource.fsPath, this.folderConfigurationPath.fsPath, !isLinux /* ignorecase */)) {
535-
return extpath.normalize(relative(this.folderConfigurationPath.fsPath, resource.fsPath));
536-
}
537-
} else {
538-
if (resources.isEqualOrParent(resource, this.folderConfigurationPath)) {
539-
return extpath.normalize(relative(this.folderConfigurationPath.path, resource.path));
540-
}
532+
if (resources.isEqualOrParent(resource, this.folderConfigurationPath)) {
533+
return resources.relativePath(this.folderConfigurationPath, resource);
541534
}
542535
return null;
543536
}

0 commit comments

Comments
 (0)