Skip to content

Commit 210fa42

Browse files
author
Benjamin Pasero
committed
paths - adopt basename()
1 parent cb7261f commit 210fa42

27 files changed

Lines changed: 78 additions & 94 deletions

File tree

src/vs/base/common/labels.ts

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

66
import { URI } from 'vs/base/common/uri';
7-
import { normalize, basename as pathsBasename } from 'vs/base/common/paths';
7+
import { normalize } from 'vs/base/common/paths';
88
import { sep, posix } from 'vs/base/common/paths.node';
99
import { endsWith, ltrim, startsWithIgnoreCase, rtrim, startsWith } from 'vs/base/common/strings';
1010
import { Schemas } from 'vs/base/common/network';
1111
import { isLinux, isWindows, isMacintosh } from 'vs/base/common/platform';
12-
import { isEqual } from 'vs/base/common/resources';
12+
import { isEqual, basename } from 'vs/base/common/resources';
1313

1414
export interface IWorkspaceFolderProvider {
1515
getWorkspaceFolder(resource: URI): { uri: URI, name?: string } | null;
@@ -44,7 +44,7 @@ export function getPathLabel(resource: URI | string, userHomeProvider?: IUserHom
4444
}
4545

4646
if (hasMultipleRoots) {
47-
const rootName = (baseResource && baseResource.name) ? baseResource.name : pathsBasename(baseResource.uri.fsPath);
47+
const rootName = (baseResource && baseResource.name) ? baseResource.name : basename(baseResource.uri);
4848
pathLabel = pathLabel ? (rootName + ' • ' + pathLabel) : rootName; // always show root basename if there are multiple
4949
}
5050

@@ -82,7 +82,7 @@ export function getBaseLabel(resource: URI | string | undefined): string | undef
8282
resource = URI.file(resource);
8383
}
8484

85-
const base = pathsBasename(resource.path) || (resource.scheme === Schemas.file ? resource.fsPath : resource.path) /* can be empty string if '/' is passed in */;
85+
const base = basename(resource) || (resource.scheme === Schemas.file ? resource.fsPath : resource.path) /* can be empty string if '/' is passed in */;
8686

8787
// convert c: => C:
8888
if (hasDriveLetter(base)) {

src/vs/base/common/paths.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@ function isPathSeparator(code: number) {
1212
return code === CharCode.Slash || code === CharCode.Backslash;
1313
}
1414

15-
/**
16-
* @returns the base name of a path.
17-
*/
18-
export function basename(path: string): string {
19-
const idx = ~path.lastIndexOf('/') || ~path.lastIndexOf('\\');
20-
if (idx === 0) {
21-
return path;
22-
} else if (~idx === path.length - 1) {
23-
return basename(path.substring(0, path.length - 1));
24-
} else {
25-
return path.substr(~idx + 1);
26-
}
27-
}
28-
2915
const _posixBadPath = /(\/\.\.?\/)|(\/\.\.?)$|^(\.\.?\/)|(\/\/+)|(\\)/;
3016
const _winBadPath = /(\\\.\.?\\)|(\\\.\.?)$|^(\.\.?\\)|(\\\\+)|(\/)/;
3117

src/vs/editor/contrib/hover/modesContentHover.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer';
2525
import { IThemeService } from 'vs/platform/theme/common/themeService';
2626
import { coalesce, isNonEmptyArray } from 'vs/base/common/arrays';
2727
import { IMarker, IMarkerData } from 'vs/platform/markers/common/markers';
28-
import { basename } from 'vs/base/common/paths';
28+
import { basename } from 'vs/base/common/resources';
2929
import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDecorationService';
3030
import { onUnexpectedError } from 'vs/base/common/errors';
3131
import { IOpenerService, NullOpenerService } from 'vs/platform/opener/common/opener';
@@ -488,7 +488,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget {
488488
for (const { message, resource, startLineNumber, startColumn } of relatedInformation) {
489489
const item = dom.append(listElement, $('li'));
490490
const a = dom.append(item, $('a'));
491-
a.innerText = `${basename(resource.path)}(${startLineNumber}, ${startColumn})`;
491+
a.innerText = `${basename(resource)}(${startLineNumber}, ${startColumn})`;
492492
a.style.cursor = 'pointer';
493493
a.onclick = e => {
494494
e.stopPropagation();

src/vs/editor/contrib/referenceSearch/referencesModel.ts

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

66
import { localize } from 'vs/nls';
77
import { Event, Emitter } from 'vs/base/common/event';
8-
import { basename } from 'vs/base/common/paths';
8+
import { basename } from 'vs/base/common/resources';
99
import { IDisposable, dispose, IReference } from 'vs/base/common/lifecycle';
1010
import * as strings from 'vs/base/common/strings';
1111
import { URI } from 'vs/base/common/uri';
@@ -44,7 +44,7 @@ export class OneReference {
4444
getAriaMessage(): string {
4545
return localize(
4646
'aria.oneReference', "symbol in {0} on line {1} at column {2}",
47-
basename(this.uri.fsPath), this.range.startLineNumber, this.range.startColumn
47+
basename(this.uri), this.range.startLineNumber, this.range.startColumn
4848
);
4949
}
5050
}
@@ -120,9 +120,9 @@ export class FileReferences implements IDisposable {
120120
getAriaMessage(): string {
121121
const len = this.children.length;
122122
if (len === 1) {
123-
return localize('aria.fileReferences.1', "1 symbol in {0}, full path {1}", basename(this.uri.fsPath), this.uri.fsPath);
123+
return localize('aria.fileReferences.1', "1 symbol in {0}, full path {1}", basename(this.uri), this.uri.fsPath);
124124
} else {
125-
return localize('aria.fileReferences.N', "{0} symbols in {1}, full path {2}", len, basename(this.uri.fsPath), this.uri.fsPath);
125+
return localize('aria.fileReferences.N', "{0} symbols in {1}, full path {2}", len, basename(this.uri), this.uri.fsPath);
126126
}
127127
}
128128

src/vs/editor/contrib/referenceSearch/referencesTree.ts

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

6-
76
import { ReferencesModel, FileReferences, OneReference } from './referencesModel';
87
import { ITextModelService } from 'vs/editor/common/services/resolverService';
98
import { ITreeRenderer, ITreeNode, IAsyncDataSource } from 'vs/base/browser/ui/tree/tree';
@@ -15,15 +14,14 @@ import { attachBadgeStyler } from 'vs/platform/theme/common/styler';
1514
import * as dom from 'vs/base/browser/dom';
1615
import { localize } from 'vs/nls';
1716
import { getBaseLabel } from 'vs/base/common/labels';
18-
import { dirname } from 'vs/base/common/resources';
17+
import { dirname, basename } from 'vs/base/common/resources';
1918
import { escape } from 'vs/base/common/strings';
2019
import { Disposable } from 'vs/base/common/lifecycle';
2120
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2221
import { IAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
2322
import { IListVirtualDelegate, IKeyboardNavigationLabelProvider, IIdentityProvider } from 'vs/base/browser/ui/list/list';
2423
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
2524
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
26-
import { basename } from 'vs/base/common/paths';
2725
import { FuzzyScore, createMatches, IMatch } from 'vs/base/common/filters';
2826

2927
//#region data source
@@ -86,7 +84,7 @@ export class StringRepresentationProvider implements IKeyboardNavigationLabelPro
8684
getKeyboardNavigationLabel(element: TreeElement): { toString(): string; } {
8785
// todo@joao `OneReference` elements are lazy and their "real" label
8886
// isn't known yet
89-
return basename(element.uri.path);
87+
return basename(element.uri);
9088
}
9189

9290
mightProducePrintableCharacter(event: IKeyboardEvent): boolean {

src/vs/platform/dialogs/common/dialogs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import Severity from 'vs/base/common/severity';
77
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
88
import { URI } from 'vs/base/common/uri';
9-
import { basename } from 'vs/base/common/paths';
9+
import { basename } from 'vs/base/common/resources';
1010
import { localize } from 'vs/nls';
1111
import { FileFilter } from 'vs/platform/windows/common/windows';
1212
import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
@@ -214,7 +214,7 @@ const MAX_CONFIRM_FILES = 10;
214214
export function getConfirmMessage(start: string, resourcesToConfirm: URI[]): string {
215215
const message = [start];
216216
message.push('');
217-
message.push(...resourcesToConfirm.slice(0, MAX_CONFIRM_FILES).map(r => basename(r.fsPath)));
217+
message.push(...resourcesToConfirm.slice(0, MAX_CONFIRM_FILES).map(r => basename(r)));
218218

219219
if (resourcesToConfirm.length > MAX_CONFIRM_FILES) {
220220
if (resourcesToConfirm.length - MAX_CONFIRM_FILES === 1) {

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

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

66
import { localize } from 'vs/nls';
77
import * as vscode from 'vscode';
8-
import { basename } from 'vs/base/common/paths';
8+
import { basename } from 'vs/base/common/resources';
99
import { URI } from 'vs/base/common/uri';
1010
import { Emitter, Event } from 'vs/base/common/event';
1111
import { Disposable } from 'vs/base/common/lifecycle';
@@ -448,7 +448,7 @@ class ExtHostTreeView<T> extends Disposable {
448448

449449
const treeItemLabel = toTreeItemLabel(label, this.extension);
450450
const prefix: string = parent ? parent.item.handle : ExtHostTreeView.LABEL_HANDLE_PREFIX;
451-
let elementId = treeItemLabel ? treeItemLabel.label : resourceUri ? basename(resourceUri.path) : '';
451+
let elementId = treeItemLabel ? treeItemLabel.label : resourceUri ? basename(resourceUri) : '';
452452
elementId = elementId.indexOf('/') !== -1 ? elementId.replace('/', '//') : elementId;
453453
const existingHandle = this.nodes.has(element) ? this.nodes.get(element).item.handle : undefined;
454454
const childrenNodes = (this.getChildrenNodes(parent) || []);

src/vs/workbench/browser/dnd.ts

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

66
import { hasWorkspaceFileExtension, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
7-
import { basename, normalize } from 'vs/base/common/paths';
7+
import { normalize } from 'vs/base/common/paths';
8+
import { basename, basenameOrAuthority } from 'vs/base/common/resources';
89
import { IFileService } from 'vs/platform/files/common/files';
910
import { IWindowsService, IWindowService, IURIToOpen } from 'vs/platform/windows/common/windows';
1011
import { URI } from 'vs/base/common/uri';
@@ -26,7 +27,6 @@ import { coalesce } from 'vs/base/common/arrays';
2627
import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2728
import { isCodeEditor } from 'vs/editor/browser/editorBrowser';
2829
import { IEditorIdentifier, GroupIdentifier } from 'vs/workbench/common/editor';
29-
import { basenameOrAuthority } from 'vs/base/common/resources';
3030
import { IEditorService, IResourceEditor } from 'vs/workbench/services/editor/common/editorService';
3131
import { Disposable } from 'vs/base/common/lifecycle';
3232
import { addDisposableListener, EventType } from 'vs/base/browser/dom';
@@ -372,7 +372,7 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources:
372372

373373
// Download URL: enables support to drag a tab as file to desktop (only single file supported)
374374
if (firstSource.resource.scheme === Schemas.file) {
375-
event.dataTransfer.setData(DataTransfers.DOWNLOAD_URL, [MIME_BINARY, basename(firstSource.resource.fsPath), firstSource.resource.toString()].join(':'));
375+
event.dataTransfer.setData(DataTransfers.DOWNLOAD_URL, [MIME_BINARY, basename(firstSource.resource), firstSource.resource.toString()].join(':'));
376376
}
377377

378378
// Resource URLs: allows to drop multiple resources to a target in VS Code (not directories)

src/vs/workbench/browser/parts/views/customView.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { IDataSource, ITree, IRenderer, ContextMenuEvent } from 'vs/base/parts/t
2626
import { ResourceLabels, IResourceLabel } from 'vs/workbench/browser/labels';
2727
import { ActionBar, IActionItemProvider, ActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
2828
import { URI } from 'vs/base/common/uri';
29-
import { basename } from 'vs/base/common/paths';
29+
import { dirname, basename } from 'vs/base/common/resources';
3030
import { LIGHT, FileThemeIcon, FolderThemeIcon, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
3131
import { FileKind } from 'vs/platform/files/common/files';
3232
import { WorkbenchTreeController } from 'vs/platform/list/browser/listService';
@@ -43,7 +43,6 @@ import { onUnexpectedError } from 'vs/base/common/errors';
4343
import { IOpenerService } from 'vs/platform/opener/common/opener';
4444
import { IMarkdownRenderResult } from 'vs/editor/contrib/markdown/markdownRenderer';
4545
import { ILabelService } from 'vs/platform/label/common/label';
46-
import { dirname } from 'vs/base/common/resources';
4746

4847
export class CustomTreeViewPanel extends ViewletPanel {
4948

@@ -677,7 +676,7 @@ class TreeRenderer implements IRenderer {
677676

678677
renderElement(tree: ITree, node: ITreeItem, templateId: string, templateData: ITreeExplorerTemplateData): void {
679678
const resource = node.resourceUri ? URI.revive(node.resourceUri) : null;
680-
const treeItemLabel: ITreeItemLabel = node.label ? node.label : resource ? { label: basename(resource.path) } : undefined;
679+
const treeItemLabel: ITreeItemLabel = node.label ? node.label : resource ? { label: basename(resource) } : undefined;
681680
const description = isString(node.description) ? node.description : resource && node.description === true ? this.labelService.getUriLabel(dirname(resource), { relative: true }) : undefined;
682681
const label = treeItemLabel ? treeItemLabel.label : undefined;
683682
const matches = treeItemLabel && treeItemLabel.highlights ? treeItemLabel.highlights.map(([start, end]) => ({ start, end })) : undefined;

src/vs/workbench/common/editor/untitledEditorInput.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { URI } from 'vs/base/common/uri';
77
import { suggestFilename } from 'vs/base/common/mime';
88
import { memoize } from 'vs/base/common/decorators';
99
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
10-
import * as paths from 'vs/base/common/paths';
11-
import * as resources from 'vs/base/common/resources';
10+
import { basename } from 'vs/base/common/paths.node';
11+
import { basenameOrAuthority, dirname } from 'vs/base/common/resources';
1212
import { EditorInput, IEncodingSupport, EncodingMode, ConfirmResult, Verbosity } from 'vs/workbench/common/editor';
1313
import { UntitledEditorModel } from 'vs/workbench/common/editor/untitledEditorModel';
1414
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -72,22 +72,22 @@ export class UntitledEditorInput extends EditorInput implements IEncodingSupport
7272
}
7373

7474
getName(): string {
75-
return this.hasAssociatedFilePath ? resources.basenameOrAuthority(this.resource) : this.resource.path;
75+
return this.hasAssociatedFilePath ? basenameOrAuthority(this.resource) : this.resource.path;
7676
}
7777

7878
@memoize
7979
private get shortDescription(): string {
80-
return paths.basename(this.labelService.getUriLabel(resources.dirname(this.resource)));
80+
return basename(this.labelService.getUriLabel(dirname(this.resource)));
8181
}
8282

8383
@memoize
8484
private get mediumDescription(): string {
85-
return this.labelService.getUriLabel(resources.dirname(this.resource), { relative: true });
85+
return this.labelService.getUriLabel(dirname(this.resource), { relative: true });
8686
}
8787

8888
@memoize
8989
private get longDescription(): string {
90-
return this.labelService.getUriLabel(resources.dirname(this.resource));
90+
return this.labelService.getUriLabel(dirname(this.resource));
9191
}
9292

9393
getDescription(verbosity: Verbosity = Verbosity.MEDIUM): string | null {

0 commit comments

Comments
 (0)