diff --git a/src/vs/base/common/labels.ts b/src/vs/base/common/labels.ts index 348aa895d8e..1347e0ad35c 100644 --- a/src/vs/base/common/labels.ts +++ b/src/vs/base/common/labels.ts @@ -4,12 +4,12 @@ *--------------------------------------------------------------------------------------------*/ import { URI } from 'vs/base/common/uri'; -import { normalize, basename as pathsBasename } from 'vs/base/common/paths'; +import { normalize } from 'vs/base/common/paths'; import { sep, posix } from 'vs/base/common/paths.node'; 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'; -import { isEqual } from 'vs/base/common/resources'; +import { isEqual, basename } from 'vs/base/common/resources'; export interface IWorkspaceFolderProvider { getWorkspaceFolder(resource: URI): { uri: URI, name?: string } | null; @@ -44,7 +44,7 @@ export function getPathLabel(resource: URI | string, userHomeProvider?: IUserHom } if (hasMultipleRoots) { - const rootName = (baseResource && baseResource.name) ? baseResource.name : pathsBasename(baseResource.uri.fsPath); + const rootName = (baseResource && baseResource.name) ? baseResource.name : basename(baseResource.uri); pathLabel = pathLabel ? (rootName + ' • ' + pathLabel) : rootName; // always show root basename if there are multiple } @@ -82,7 +82,7 @@ export function getBaseLabel(resource: URI | string | undefined): string | undef resource = URI.file(resource); } - const base = pathsBasename(resource.path) || (resource.scheme === Schemas.file ? resource.fsPath : resource.path) /* can be empty string if '/' is passed in */; + const base = basename(resource) || (resource.scheme === Schemas.file ? resource.fsPath : resource.path) /* can be empty string if '/' is passed in */; // convert c: => C: if (hasDriveLetter(base)) { diff --git a/src/vs/base/common/paths.ts b/src/vs/base/common/paths.ts index aa4ccf94e7e..c8bf7a0a229 100644 --- a/src/vs/base/common/paths.ts +++ b/src/vs/base/common/paths.ts @@ -12,20 +12,6 @@ function isPathSeparator(code: number) { return code === CharCode.Slash || code === CharCode.Backslash; } -/** - * @returns the base name of a path. - */ -export function basename(path: string): string { - const idx = ~path.lastIndexOf('/') || ~path.lastIndexOf('\\'); - if (idx === 0) { - return path; - } else if (~idx === path.length - 1) { - return basename(path.substring(0, path.length - 1)); - } else { - return path.substr(~idx + 1); - } -} - const _posixBadPath = /(\/\.\.?\/)|(\/\.\.?)$|^(\.\.?\/)|(\/\/+)|(\\)/; const _winBadPath = /(\\\.\.?\\)|(\\\.\.?)$|^(\.\.?\\)|(\\\\+)|(\/)/; diff --git a/src/vs/editor/contrib/hover/modesContentHover.ts b/src/vs/editor/contrib/hover/modesContentHover.ts index 1d911e306e9..a83521453ea 100644 --- a/src/vs/editor/contrib/hover/modesContentHover.ts +++ b/src/vs/editor/contrib/hover/modesContentHover.ts @@ -25,7 +25,7 @@ import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { coalesce, isNonEmptyArray } from 'vs/base/common/arrays'; import { IMarker, IMarkerData } from 'vs/platform/markers/common/markers'; -import { basename } from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDecorationService'; import { onUnexpectedError } from 'vs/base/common/errors'; import { IOpenerService, NullOpenerService } from 'vs/platform/opener/common/opener'; @@ -488,7 +488,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget { for (const { message, resource, startLineNumber, startColumn } of relatedInformation) { const item = dom.append(listElement, $('li')); const a = dom.append(item, $('a')); - a.innerText = `${basename(resource.path)}(${startLineNumber}, ${startColumn})`; + a.innerText = `${basename(resource)}(${startLineNumber}, ${startColumn})`; a.style.cursor = 'pointer'; a.onclick = e => { e.stopPropagation(); diff --git a/src/vs/editor/contrib/referenceSearch/referencesModel.ts b/src/vs/editor/contrib/referenceSearch/referencesModel.ts index da7677a01d5..4243491a8b4 100644 --- a/src/vs/editor/contrib/referenceSearch/referencesModel.ts +++ b/src/vs/editor/contrib/referenceSearch/referencesModel.ts @@ -5,7 +5,7 @@ import { localize } from 'vs/nls'; import { Event, Emitter } from 'vs/base/common/event'; -import { basename } from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { IDisposable, dispose, IReference } from 'vs/base/common/lifecycle'; import * as strings from 'vs/base/common/strings'; import { URI } from 'vs/base/common/uri'; @@ -44,7 +44,7 @@ export class OneReference { getAriaMessage(): string { return localize( 'aria.oneReference', "symbol in {0} on line {1} at column {2}", - basename(this.uri.fsPath), this.range.startLineNumber, this.range.startColumn + basename(this.uri), this.range.startLineNumber, this.range.startColumn ); } } @@ -120,9 +120,9 @@ export class FileReferences implements IDisposable { getAriaMessage(): string { const len = this.children.length; if (len === 1) { - return localize('aria.fileReferences.1', "1 symbol in {0}, full path {1}", basename(this.uri.fsPath), this.uri.fsPath); + return localize('aria.fileReferences.1', "1 symbol in {0}, full path {1}", basename(this.uri), this.uri.fsPath); } else { - return localize('aria.fileReferences.N', "{0} symbols in {1}, full path {2}", len, basename(this.uri.fsPath), this.uri.fsPath); + return localize('aria.fileReferences.N', "{0} symbols in {1}, full path {2}", len, basename(this.uri), this.uri.fsPath); } } diff --git a/src/vs/editor/contrib/referenceSearch/referencesTree.ts b/src/vs/editor/contrib/referenceSearch/referencesTree.ts index 8866c65be81..b9434680146 100644 --- a/src/vs/editor/contrib/referenceSearch/referencesTree.ts +++ b/src/vs/editor/contrib/referenceSearch/referencesTree.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ - import { ReferencesModel, FileReferences, OneReference } from './referencesModel'; import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { ITreeRenderer, ITreeNode, IAsyncDataSource } from 'vs/base/browser/ui/tree/tree'; @@ -15,7 +14,7 @@ import { attachBadgeStyler } from 'vs/platform/theme/common/styler'; import * as dom from 'vs/base/browser/dom'; import { localize } from 'vs/nls'; import { getBaseLabel } from 'vs/base/common/labels'; -import { dirname } from 'vs/base/common/resources'; +import { dirname, basename } from 'vs/base/common/resources'; import { escape } from 'vs/base/common/strings'; import { Disposable } from 'vs/base/common/lifecycle'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -23,7 +22,6 @@ import { IAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget'; import { IListVirtualDelegate, IKeyboardNavigationLabelProvider, IIdentityProvider } from 'vs/base/browser/ui/list/list'; import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; -import { basename } from 'vs/base/common/paths'; import { FuzzyScore, createMatches, IMatch } from 'vs/base/common/filters'; //#region data source @@ -86,7 +84,7 @@ export class StringRepresentationProvider implements IKeyboardNavigationLabelPro getKeyboardNavigationLabel(element: TreeElement): { toString(): string; } { // todo@joao `OneReference` elements are lazy and their "real" label // isn't known yet - return basename(element.uri.path); + return basename(element.uri); } mightProducePrintableCharacter(event: IKeyboardEvent): boolean { diff --git a/src/vs/platform/dialogs/common/dialogs.ts b/src/vs/platform/dialogs/common/dialogs.ts index aa8193ec548..5f4ebaa0c83 100644 --- a/src/vs/platform/dialogs/common/dialogs.ts +++ b/src/vs/platform/dialogs/common/dialogs.ts @@ -6,7 +6,7 @@ import Severity from 'vs/base/common/severity'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { URI } from 'vs/base/common/uri'; -import { basename } from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { localize } from 'vs/nls'; import { FileFilter } from 'vs/platform/windows/common/windows'; import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry'; @@ -214,7 +214,7 @@ const MAX_CONFIRM_FILES = 10; export function getConfirmMessage(start: string, resourcesToConfirm: URI[]): string { const message = [start]; message.push(''); - message.push(...resourcesToConfirm.slice(0, MAX_CONFIRM_FILES).map(r => basename(r.fsPath))); + message.push(...resourcesToConfirm.slice(0, MAX_CONFIRM_FILES).map(r => basename(r))); if (resourcesToConfirm.length > MAX_CONFIRM_FILES) { if (resourcesToConfirm.length - MAX_CONFIRM_FILES === 1) { diff --git a/src/vs/workbench/api/node/extHostTreeViews.ts b/src/vs/workbench/api/node/extHostTreeViews.ts index 9d75a07dd02..73979ed52c9 100644 --- a/src/vs/workbench/api/node/extHostTreeViews.ts +++ b/src/vs/workbench/api/node/extHostTreeViews.ts @@ -5,7 +5,7 @@ import { localize } from 'vs/nls'; import * as vscode from 'vscode'; -import { basename } from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { URI } from 'vs/base/common/uri'; import { Emitter, Event } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; @@ -448,7 +448,7 @@ class ExtHostTreeView extends Disposable { const treeItemLabel = toTreeItemLabel(label, this.extension); const prefix: string = parent ? parent.item.handle : ExtHostTreeView.LABEL_HANDLE_PREFIX; - let elementId = treeItemLabel ? treeItemLabel.label : resourceUri ? basename(resourceUri.path) : ''; + let elementId = treeItemLabel ? treeItemLabel.label : resourceUri ? basename(resourceUri) : ''; elementId = elementId.indexOf('/') !== -1 ? elementId.replace('/', '//') : elementId; const existingHandle = this.nodes.has(element) ? this.nodes.get(element).item.handle : undefined; const childrenNodes = (this.getChildrenNodes(parent) || []); diff --git a/src/vs/workbench/browser/dnd.ts b/src/vs/workbench/browser/dnd.ts index 739f53af72a..f7aa4e8346b 100644 --- a/src/vs/workbench/browser/dnd.ts +++ b/src/vs/workbench/browser/dnd.ts @@ -4,7 +4,8 @@ *--------------------------------------------------------------------------------------------*/ import { hasWorkspaceFileExtension, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces'; -import { basename, normalize } from 'vs/base/common/paths'; +import { normalize } from 'vs/base/common/paths'; +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'; import { URI } from 'vs/base/common/uri'; @@ -26,7 +27,6 @@ import { coalesce } from 'vs/base/common/arrays'; import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { isCodeEditor } from 'vs/editor/browser/editorBrowser'; import { IEditorIdentifier, GroupIdentifier } from 'vs/workbench/common/editor'; -import { basenameOrAuthority } from 'vs/base/common/resources'; import { IEditorService, IResourceEditor } from 'vs/workbench/services/editor/common/editorService'; import { Disposable } from 'vs/base/common/lifecycle'; import { addDisposableListener, EventType } from 'vs/base/browser/dom'; @@ -372,7 +372,7 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources: // Download URL: enables support to drag a tab as file to desktop (only single file supported) if (firstSource.resource.scheme === Schemas.file) { - event.dataTransfer.setData(DataTransfers.DOWNLOAD_URL, [MIME_BINARY, basename(firstSource.resource.fsPath), firstSource.resource.toString()].join(':')); + event.dataTransfer.setData(DataTransfers.DOWNLOAD_URL, [MIME_BINARY, basename(firstSource.resource), firstSource.resource.toString()].join(':')); } // Resource URLs: allows to drop multiple resources to a target in VS Code (not directories) diff --git a/src/vs/workbench/browser/parts/views/customView.ts b/src/vs/workbench/browser/parts/views/customView.ts index 73cb594d7a8..1f0f1fd7c32 100644 --- a/src/vs/workbench/browser/parts/views/customView.ts +++ b/src/vs/workbench/browser/parts/views/customView.ts @@ -26,7 +26,7 @@ import { IDataSource, ITree, IRenderer, ContextMenuEvent } from 'vs/base/parts/t import { ResourceLabels, IResourceLabel } from 'vs/workbench/browser/labels'; import { ActionBar, IActionItemProvider, ActionItem } from 'vs/base/browser/ui/actionbar/actionbar'; import { URI } from 'vs/base/common/uri'; -import { basename } from 'vs/base/common/paths'; +import { dirname, basename } from 'vs/base/common/resources'; import { LIGHT, FileThemeIcon, FolderThemeIcon, registerThemingParticipant } from 'vs/platform/theme/common/themeService'; import { FileKind } from 'vs/platform/files/common/files'; import { WorkbenchTreeController } from 'vs/platform/list/browser/listService'; @@ -43,7 +43,6 @@ import { onUnexpectedError } from 'vs/base/common/errors'; import { IOpenerService } from 'vs/platform/opener/common/opener'; import { IMarkdownRenderResult } from 'vs/editor/contrib/markdown/markdownRenderer'; import { ILabelService } from 'vs/platform/label/common/label'; -import { dirname } from 'vs/base/common/resources'; export class CustomTreeViewPanel extends ViewletPanel { @@ -677,7 +676,7 @@ class TreeRenderer implements IRenderer { renderElement(tree: ITree, node: ITreeItem, templateId: string, templateData: ITreeExplorerTemplateData): void { const resource = node.resourceUri ? URI.revive(node.resourceUri) : null; - const treeItemLabel: ITreeItemLabel = node.label ? node.label : resource ? { label: basename(resource.path) } : undefined; + const treeItemLabel: ITreeItemLabel = node.label ? node.label : resource ? { label: basename(resource) } : undefined; const description = isString(node.description) ? node.description : resource && node.description === true ? this.labelService.getUriLabel(dirname(resource), { relative: true }) : undefined; const label = treeItemLabel ? treeItemLabel.label : undefined; const matches = treeItemLabel && treeItemLabel.highlights ? treeItemLabel.highlights.map(([start, end]) => ({ start, end })) : undefined; diff --git a/src/vs/workbench/common/editor/untitledEditorInput.ts b/src/vs/workbench/common/editor/untitledEditorInput.ts index 85daece3136..cca8dc7fc50 100644 --- a/src/vs/workbench/common/editor/untitledEditorInput.ts +++ b/src/vs/workbench/common/editor/untitledEditorInput.ts @@ -7,8 +7,8 @@ import { URI } from 'vs/base/common/uri'; import { suggestFilename } from 'vs/base/common/mime'; import { memoize } from 'vs/base/common/decorators'; import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry'; -import * as paths from 'vs/base/common/paths'; -import * as resources from 'vs/base/common/resources'; +import { basename } from 'vs/base/common/paths.node'; +import { basenameOrAuthority, dirname } from 'vs/base/common/resources'; import { EditorInput, IEncodingSupport, EncodingMode, ConfirmResult, Verbosity } from 'vs/workbench/common/editor'; import { UntitledEditorModel } from 'vs/workbench/common/editor/untitledEditorModel'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -72,22 +72,22 @@ export class UntitledEditorInput extends EditorInput implements IEncodingSupport } getName(): string { - return this.hasAssociatedFilePath ? resources.basenameOrAuthority(this.resource) : this.resource.path; + return this.hasAssociatedFilePath ? basenameOrAuthority(this.resource) : this.resource.path; } @memoize private get shortDescription(): string { - return paths.basename(this.labelService.getUriLabel(resources.dirname(this.resource))); + return basename(this.labelService.getUriLabel(dirname(this.resource))); } @memoize private get mediumDescription(): string { - return this.labelService.getUriLabel(resources.dirname(this.resource), { relative: true }); + return this.labelService.getUriLabel(dirname(this.resource), { relative: true }); } @memoize private get longDescription(): string { - return this.labelService.getUriLabel(resources.dirname(this.resource)); + return this.labelService.getUriLabel(dirname(this.resource)); } getDescription(verbosity: Verbosity = Verbosity.MEDIUM): string | null { diff --git a/src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts b/src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts index 6d840584a3b..064f562b483 100644 --- a/src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts +++ b/src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts @@ -6,7 +6,8 @@ import * as nls from 'vs/nls'; import { toErrorMessage } from 'vs/base/common/errorMessage'; import * as types from 'vs/base/common/types'; -import * as paths from 'vs/base/common/paths'; +import { isValidBasename } from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { Action } from 'vs/base/common/actions'; import { VIEWLET_ID, TEXT_FILE_EDITOR_ID, IExplorerService } from 'vs/workbench/contrib/files/common/files'; import { ITextFileEditorModel, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; @@ -181,7 +182,7 @@ export class TextFileEditor extends BaseTextEditor { } // Offer to create a file from the error if we have a file not found and the name is valid - if ((error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND && paths.isValidBasename(paths.basename(input.getResource().fsPath))) { + if ((error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND && isValidBasename(basename(input.getResource()))) { return Promise.reject(createErrorWithActions(toErrorMessage(error), { actions: [ new Action('workbench.files.action.createMissingFile', nls.localize('createFile', "Create File"), null, true, () => { diff --git a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts index 5d141dac753..496fc625a89 100644 --- a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts +++ b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts @@ -5,8 +5,8 @@ import { localize } from 'vs/nls'; import { memoize } from 'vs/base/common/decorators'; -import * as paths from 'vs/base/common/paths'; -import * as resources from 'vs/base/common/resources'; +import { basename } from 'vs/base/common/paths.node'; +import { basenameOrAuthority, dirname } from 'vs/base/common/resources'; import { URI } from 'vs/base/common/uri'; import { EncodingMode, ConfirmResult, EditorInput, IFileEditorInput, ITextEditorModel, Verbosity, IRevertOptions } from 'vs/workbench/common/editor'; import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel'; @@ -122,7 +122,7 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput { getName(): string { if (!this.name) { - this.name = resources.basenameOrAuthority(this.resource); + this.name = basenameOrAuthority(this.resource); } return this.decorateLabel(this.name); @@ -130,17 +130,17 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput { @memoize private get shortDescription(): string { - return paths.basename(this.labelService.getUriLabel(resources.dirname(this.resource))); + return basename(this.labelService.getUriLabel(dirname(this.resource))); } @memoize private get mediumDescription(): string { - return this.labelService.getUriLabel(resources.dirname(this.resource), { relative: true }); + return this.labelService.getUriLabel(dirname(this.resource), { relative: true }); } @memoize private get longDescription(): string { - return this.labelService.getUriLabel(resources.dirname(this.resource)); + return this.labelService.getUriLabel(dirname(this.resource)); } getDescription(verbosity: Verbosity = Verbosity.MEDIUM): string { diff --git a/src/vs/workbench/contrib/files/electron-browser/fileCommands.ts b/src/vs/workbench/contrib/files/electron-browser/fileCommands.ts index 77564393606..69e0d1f6592 100644 --- a/src/vs/workbench/contrib/files/electron-browser/fileCommands.ts +++ b/src/vs/workbench/contrib/files/electron-browser/fileCommands.ts @@ -39,6 +39,7 @@ import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/ import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { ILabelService } from 'vs/platform/label/common/label'; import { onUnexpectedError } from 'vs/base/common/errors'; +import { basename } from 'vs/base/common/resources'; // Commands @@ -245,7 +246,7 @@ CommandsRegistry.registerCommand({ if (resources.length) { return textFileService.revertAll(resources, { force: true }).then(undefined, error => { - notificationService.error(nls.localize('genericRevertError', "Failed to revert '{0}': {1}", resources.map(r => paths.basename(r.fsPath)).join(', '), toErrorMessage(error, false))); + notificationService.error(nls.localize('genericRevertError', "Failed to revert '{0}': {1}", resources.map(r => basename(r)).join(', '), toErrorMessage(error, false))); }); } @@ -300,7 +301,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ const uri = getResourceForCommand(resource, accessor.get(IListService), editorService); if (uri && uri.scheme === Schemas.file /* only files on disk supported for now */) { - const name = paths.basename(uri.fsPath); + const name = basename(uri); const editorLabel = nls.localize('modifiedLabel', "{0} (on disk) ↔ {1}", name, name); return editorService.openEditor({ leftResource: uri.with({ scheme: COMPARE_WITH_SAVED_SCHEMA }), rightResource: uri, label: editorLabel }).then(() => undefined); diff --git a/src/vs/workbench/contrib/files/electron-browser/saveErrorHandler.ts b/src/vs/workbench/contrib/files/electron-browser/saveErrorHandler.ts index c6ebe282cac..bc21d65f27a 100644 --- a/src/vs/workbench/contrib/files/electron-browser/saveErrorHandler.ts +++ b/src/vs/workbench/contrib/files/electron-browser/saveErrorHandler.ts @@ -5,7 +5,7 @@ import * as nls from 'vs/nls'; import { toErrorMessage } from 'vs/base/common/errorMessage'; -import * as paths from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { Action } from 'vs/base/common/actions'; import { URI } from 'vs/base/common/uri'; import { FileOperationError, FileOperationResult } from 'vs/platform/files/common/files'; @@ -124,7 +124,7 @@ export class SaveErrorHandler extends Disposable implements ISaveErrorHandler, I // Otherwise show the message that will lead the user into the save conflict editor. else { - message = nls.localize('staleSaveError', "Failed to save '{0}': The content on disk is newer. Please compare your version with the one on disk.", paths.basename(resource.fsPath)); + message = nls.localize('staleSaveError', "Failed to save '{0}': The content on disk is newer. Please compare your version with the one on disk.", basename(resource)); actions.primary.push(this.instantiationService.createInstance(ResolveSaveConflictAction, model)); } @@ -159,14 +159,14 @@ export class SaveErrorHandler extends Disposable implements ISaveErrorHandler, I if (isReadonly) { if (triedToMakeWriteable) { - message = isWindows ? nls.localize('readonlySaveErrorAdmin', "Failed to save '{0}': File is write protected. Select 'Overwrite as Admin' to retry as administrator.", paths.basename(resource.fsPath)) : nls.localize('readonlySaveErrorSudo', "Failed to save '{0}': File is write protected. Select 'Overwrite as Sudo' to retry as superuser.", paths.basename(resource.fsPath)); + message = isWindows ? nls.localize('readonlySaveErrorAdmin', "Failed to save '{0}': File is write protected. Select 'Overwrite as Admin' to retry as administrator.", basename(resource)) : nls.localize('readonlySaveErrorSudo', "Failed to save '{0}': File is write protected. Select 'Overwrite as Sudo' to retry as superuser.", basename(resource)); } else { - message = nls.localize('readonlySaveError', "Failed to save '{0}': File is write protected. Select 'Overwrite' to attempt to remove protection.", paths.basename(resource.fsPath)); + message = nls.localize('readonlySaveError', "Failed to save '{0}': File is write protected. Select 'Overwrite' to attempt to remove protection.", basename(resource)); } } else if (isPermissionDenied) { - message = isWindows ? nls.localize('permissionDeniedSaveError', "Failed to save '{0}': Insufficient permissions. Select 'Retry as Admin' to retry as administrator.", paths.basename(resource.fsPath)) : nls.localize('permissionDeniedSaveErrorSudo', "Failed to save '{0}': Insufficient permissions. Select 'Retry as Sudo' to retry as superuser.", paths.basename(resource.fsPath)); + message = isWindows ? nls.localize('permissionDeniedSaveError', "Failed to save '{0}': Insufficient permissions. Select 'Retry as Admin' to retry as administrator.", basename(resource)) : nls.localize('permissionDeniedSaveErrorSudo', "Failed to save '{0}': Insufficient permissions. Select 'Retry as Sudo' to retry as superuser.", basename(resource)); } else { - message = nls.localize('genericSaveError', "Failed to save '{0}': {1}", paths.basename(resource.fsPath), toErrorMessage(error, false)); + message = nls.localize('genericSaveError', "Failed to save '{0}': {1}", basename(resource), toErrorMessage(error, false)); } } @@ -237,7 +237,7 @@ class ResolveSaveConflictAction extends Action { run(): Promise { if (!this.model.isDisposed()) { const resource = this.model.getResource(); - const name = paths.basename(resource.fsPath); + const name = basename(resource); const editorLabel = nls.localize('saveConflictDiffLabel', "{0} (on disk) ↔ {1} (in {2}) - Resolve save conflict", name, name, this.environmentService.appNameLong); return this.editorService.openEditor( diff --git a/src/vs/workbench/contrib/markers/electron-browser/markersModel.ts b/src/vs/workbench/contrib/markers/electron-browser/markersModel.ts index cf207bf5e22..41522466990 100644 --- a/src/vs/workbench/contrib/markers/electron-browser/markersModel.ts +++ b/src/vs/workbench/contrib/markers/electron-browser/markersModel.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as paths from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { URI } from 'vs/base/common/uri'; import { Range, IRange } from 'vs/editor/common/core/range'; import { IMarker, MarkerSeverity, IRelatedInformation, IMarkerData } from 'vs/platform/markers/common/markers'; @@ -47,7 +47,7 @@ export class ResourceMarkers { get path(): string { return this.resource.fsPath; } @memoize - get name(): string { return paths.basename(this.resource.fsPath); } + get name(): string { return basename(this.resource); } @memoize get hash(): string { diff --git a/src/vs/workbench/contrib/markers/electron-browser/messages.ts b/src/vs/workbench/contrib/markers/electron-browser/messages.ts index 07b0ed7de14..e6b752e0574 100644 --- a/src/vs/workbench/contrib/markers/electron-browser/messages.ts +++ b/src/vs/workbench/contrib/markers/electron-browser/messages.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as nls from 'vs/nls'; -import * as paths from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { MarkerSeverity, IRelatedInformation } from 'vs/platform/markers/common/markers'; import { Marker } from './markersModel'; @@ -63,6 +63,6 @@ export default class Messages { : nls.localize('problems.tree.aria.label.marker.nosource', "Problem: {0} at line {1} and character {2}.{3}", marker.marker.message, marker.marker.startLineNumber, marker.marker.startColumn, relatedInformationMessage); } } - public static readonly MARKERS_TREE_ARIA_LABEL_RELATED_INFORMATION = (relatedInformation: IRelatedInformation): string => nls.localize('problems.tree.aria.label.relatedinfo.message', "{0} at line {1} and character {2} in {3}", relatedInformation.message, relatedInformation.startLineNumber, relatedInformation.startColumn, paths.basename(relatedInformation.resource.fsPath)); + public static readonly MARKERS_TREE_ARIA_LABEL_RELATED_INFORMATION = (relatedInformation: IRelatedInformation): string => nls.localize('problems.tree.aria.label.relatedinfo.message', "{0} at line {1} and character {2} in {3}", relatedInformation.message, relatedInformation.startLineNumber, relatedInformation.startColumn, basename(relatedInformation.resource)); public static SHOW_ERRORS_WARNINGS_ACTION_LABEL: string = nls.localize('errors.warnings.show.label', "Show Errors and Warnings"); } diff --git a/src/vs/workbench/contrib/performance/electron-browser/startupProfiler.ts b/src/vs/workbench/contrib/performance/electron-browser/startupProfiler.ts index c9ad9a6a401..aba02244f5d 100644 --- a/src/vs/workbench/contrib/performance/electron-browser/startupProfiler.ts +++ b/src/vs/workbench/contrib/performance/electron-browser/startupProfiler.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { dirname, join } from 'path'; -import { basename } from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/paths.node'; import { del, exists, readdir, readFile } from 'vs/base/node/pfs'; import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { localize } from 'vs/nls'; diff --git a/src/vs/workbench/contrib/scm/electron-browser/dirtydiffDecorator.ts b/src/vs/workbench/contrib/scm/electron-browser/dirtydiffDecorator.ts index 864b3c1d100..77f28716b69 100644 --- a/src/vs/workbench/contrib/scm/electron-browser/dirtydiffDecorator.ts +++ b/src/vs/workbench/contrib/scm/electron-browser/dirtydiffDecorator.ts @@ -37,7 +37,7 @@ import { IDiffEditorOptions } from 'vs/editor/common/config/editorOptions'; import { Action, IAction, ActionRunner } from 'vs/base/common/actions'; import { IActionBarOptions, ActionsOrientation, IActionItem } from 'vs/base/browser/ui/actionbar/actionbar'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; -import { basename } from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { MenuId, IMenuService, IMenu, MenuItemAction, MenuRegistry } from 'vs/platform/actions/common/actions'; import { MenuItemActionItem, fillInActionBarActions } from 'vs/platform/actions/browser/menuItemActionItem'; import { IChange, IEditorModel, ScrollType, IEditorContribution, IDiffEditorModel } from 'vs/editor/common/editorCommon'; @@ -208,7 +208,7 @@ class DirtyDiffWidget extends PeekViewWidget { this.create(); if (editor.hasModel()) { - this.title = basename(editor.getModel().uri.fsPath); + this.title = basename(editor.getModel().uri); } else { this.title = ''; } diff --git a/src/vs/workbench/contrib/scm/electron-browser/scmActivity.ts b/src/vs/workbench/contrib/scm/electron-browser/scmActivity.ts index df3d55c4e0e..2bbb403db14 100644 --- a/src/vs/workbench/contrib/scm/electron-browser/scmActivity.ts +++ b/src/vs/workbench/contrib/scm/electron-browser/scmActivity.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { localize } from 'vs/nls'; -import { basename } from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { IDisposable, dispose, Disposable, combinedDisposable } from 'vs/base/common/lifecycle'; import { Event } from 'vs/base/common/event'; import { VIEWLET_ID, ISCMService, ISCMRepository } from 'vs/workbench/contrib/scm/common/scm'; @@ -184,7 +184,7 @@ export class StatusBarController implements IWorkbenchContribution { const commands = repository.provider.statusBarCommands || []; const label = repository.provider.rootUri - ? `${basename(repository.provider.rootUri.fsPath)} (${repository.provider.label})` + ? `${basename(repository.provider.rootUri)} (${repository.provider.label})` : repository.provider.label; const disposables = commands.map(c => this.statusbarService.addEntry({ diff --git a/src/vs/workbench/contrib/scm/electron-browser/scmViewlet.ts b/src/vs/workbench/contrib/scm/electron-browser/scmViewlet.ts index 5ed9de8e244..562b1d32798 100644 --- a/src/vs/workbench/contrib/scm/electron-browser/scmViewlet.ts +++ b/src/vs/workbench/contrib/scm/electron-browser/scmViewlet.ts @@ -7,7 +7,7 @@ import 'vs/css!./media/scmViewlet'; import { localize } from 'vs/nls'; import { Event, Emitter } from 'vs/base/common/event'; import { domEvent, stop } from 'vs/base/browser/event'; -import { basename } from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { IDisposable, dispose, combinedDisposable, Disposable, toDisposable } from 'vs/base/common/lifecycle'; import { PanelViewlet, ViewletPanel, IViewletPanelOptions } from 'vs/workbench/browser/parts/views/panelViewlet'; import { append, $, addClass, toggleClass, trackFocus, Dimension, addDisposableListener, removeClass } from 'vs/base/browser/dom'; @@ -170,7 +170,7 @@ class ProviderRenderer implements IListRenderer { getKeyboardNavigationLabel(e: ISCMResourceGroup | ISCMResource) { if (isSCMResource(e)) { - return basename(e.sourceUri.fsPath); + return basename(e.sourceUri); } else { return e.label; } @@ -773,7 +773,7 @@ export class RepositoryPanel extends ViewletPanel { let type: string; if (this.repository.provider.rootUri) { - title = basename(this.repository.provider.rootUri.fsPath); + title = basename(this.repository.provider.rootUri); type = this.repository.provider.label; } else { title = this.repository.provider.label; diff --git a/src/vs/workbench/contrib/search/browser/openSymbolHandler.ts b/src/vs/workbench/contrib/search/browser/openSymbolHandler.ts index a5e2a7e7b59..d53e63d5fe6 100644 --- a/src/vs/workbench/contrib/search/browser/openSymbolHandler.ts +++ b/src/vs/workbench/contrib/search/browser/openSymbolHandler.ts @@ -19,7 +19,7 @@ import { IResourceInput } from 'vs/platform/editor/common/editor'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IWorkspaceSymbolProvider, getWorkspaceSymbols, IWorkspaceSymbol } from 'vs/workbench/contrib/search/common/search'; -import { basename } from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { ILabelService } from 'vs/platform/label/common/label'; import { CancellationToken } from 'vs/base/common/cancellation'; @@ -52,7 +52,7 @@ class SymbolEntry extends EditorQuickOpenEntry { const containerName = this.bearing.containerName; if (this.bearing.location.uri) { if (containerName) { - return `${containerName} — ${basename(this.bearing.location.uri.fsPath)}`; + return `${containerName} — ${basename(this.bearing.location.uri)}`; } return this.labelService.getUriLabel(this.bearing.location.uri, { relative: true }); diff --git a/src/vs/workbench/contrib/terminal/electron-browser/terminalInstance.ts b/src/vs/workbench/contrib/terminal/electron-browser/terminalInstance.ts index 0a38e48b7fd..7a24563dc91 100644 --- a/src/vs/workbench/contrib/terminal/electron-browser/terminalInstance.ts +++ b/src/vs/workbench/contrib/terminal/electron-browser/terminalInstance.ts @@ -13,7 +13,7 @@ import { debounce } from 'vs/base/common/decorators'; import { Emitter, Event } from 'vs/base/common/event'; import { KeyCode } from 'vs/base/common/keyCodes'; import * as lifecycle from 'vs/base/common/lifecycle'; -import * as paths from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/paths.node'; import * as platform from 'vs/base/common/platform'; import { TabFocus } from 'vs/editor/common/config/commonEditorConfig'; import * as nls from 'vs/nls'; @@ -1245,7 +1245,7 @@ export class TerminalInstance implements ITerminalInstance { return; } if (eventFromProcess) { - title = paths.basename(title); + title = basename(title); if (platform.isWindows) { // Remove the .exe extension title = title.split('.exe')[0]; diff --git a/src/vs/workbench/contrib/themes/test/electron-browser/themes.test.contribution.ts b/src/vs/workbench/contrib/themes/test/electron-browser/themes.test.contribution.ts index 89c17efaa79..8f4f67eee2e 100644 --- a/src/vs/workbench/contrib/themes/test/electron-browser/themes.test.contribution.ts +++ b/src/vs/workbench/contrib/themes/test/electron-browser/themes.test.contribution.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as paths from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/paths.node'; import { URI } from 'vs/base/common/uri'; import { IModeService } from 'vs/editor/common/services/modeService'; import * as pfs from 'vs/base/node/pfs'; @@ -231,7 +231,7 @@ CommandsRegistry.registerCommand('_workbench.captureSyntaxTokens', function (acc let process = (resource: URI) => { let filePath = resource.fsPath; - let fileName = paths.basename(filePath); + let fileName = basename(filePath); let snapper = accessor.get(IInstantiationService).createInstance(Snapper); return pfs.readFile(filePath).then(content => { diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index 693779a1efa..260cdc084bd 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -15,7 +15,7 @@ import { IFileService } from 'vs/platform/files/common/files'; import { Schemas } from 'vs/base/common/network'; import { Event, Emitter } from 'vs/base/common/event'; import { URI } from 'vs/base/common/uri'; -import { basename } from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/resources'; import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; import { localize } from 'vs/nls'; import { IEditorGroupsService, IEditorGroup, GroupsOrder, IEditorReplacement, GroupChangeKind, preferredSideBySideGroupDirection } from 'vs/workbench/services/editor/common/editorGroupsService'; @@ -531,7 +531,7 @@ export class EditorService extends Disposable implements EditorServiceImpl { if (resourceInput.resource instanceof URI) { let label = resourceInput.label; if (!label && resourceInput.resource.scheme !== Schemas.data) { - label = basename(resourceInput.resource.fsPath); // derive the label from the path (but not for data URIs) + label = basename(resourceInput.resource); // derive the label from the path (but not for data URIs) } return this.createOrGet(resourceInput.resource, this.instantiationService, label, resourceInput.description, resourceInput.encoding, resourceInput.forceFile) as EditorInput; diff --git a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts index 96d724c7fae..188c127fa1b 100644 --- a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts +++ b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts @@ -29,7 +29,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati import { isLinux } from 'vs/base/common/platform'; import { IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { ILogService } from 'vs/platform/log/common/log'; -import { isEqual, isEqualOrParent, extname } from 'vs/base/common/resources'; +import { isEqual, isEqualOrParent, extname, basename } from 'vs/base/common/resources'; import { onUnexpectedError } from 'vs/base/common/errors'; /** @@ -268,7 +268,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil if (!!backup) { const content: IRawTextContent = { resource: this.resource, - name: path.basename(this.resource.fsPath), + name: basename(this.resource), mtime: Date.now(), etag: undefined, value: createTextBufferFactory(''), /* will be filled later from backup */ @@ -797,7 +797,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil const folders = this.contextService.getWorkspace().folders; for (const folder of folders) { if (isEqualOrParent(this.resource, folder.toResource('.vscode'))) { - const filename = path.basename(this.resource.fsPath); + const filename = basename(this.resource); if (TextFileEditorModel.WHITELIST_WORKSPACE_JSON.indexOf(filename) > -1) { return `.vscode/${filename}`; } @@ -809,7 +809,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil private getTelemetryData(reason: number): Object { const ext = extname(this.resource); - const fileName = path.basename(this.resource.fsPath); + const fileName = basename(this.resource); const telemetryData = { mimeType: guessMimeTypes(this.resource.fsPath).join(', '), ext, @@ -1129,6 +1129,6 @@ class DefaultSaveErrorHandler implements ISaveErrorHandler { constructor(@INotificationService private readonly notificationService: INotificationService) { } onSaveError(error: any, model: TextFileEditorModel): void { - this.notificationService.error(nls.localize('genericSaveError', "Failed to save '{0}': {1}", path.basename(model.getResource().fsPath), toErrorMessage(error, false))); + this.notificationService.error(nls.localize('genericSaveError', "Failed to save '{0}': {1}", basename(model.getResource()), toErrorMessage(error, false))); } } diff --git a/src/vs/workbench/services/themes/electron-browser/colorThemeData.ts b/src/vs/workbench/services/themes/electron-browser/colorThemeData.ts index b0f8f48be13..5071c7ee5bb 100644 --- a/src/vs/workbench/services/themes/electron-browser/colorThemeData.ts +++ b/src/vs/workbench/services/themes/electron-browser/colorThemeData.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as Paths from 'vs/base/common/paths'; +import { basename } from 'vs/base/common/paths.node'; import * as Json from 'vs/base/common/json'; import { Color } from 'vs/base/common/color'; import { ExtensionData, ITokenColorCustomizations, ITokenColorizationRule, IColorTheme, IColorMap, IThemeExtensionPoint, VS_LIGHT_THEME, VS_HC_THEME } from 'vs/workbench/services/themes/common/workbenchThemeService'; @@ -261,7 +262,7 @@ export class ColorThemeData implements IColorTheme { let themeSelector = toCSSSelector(extensionData.extensionId + '-' + Paths.normalize(theme.path)); let themeData = new ColorThemeData(); themeData.id = `${baseTheme} ${themeSelector}`; - themeData.label = theme.label || Paths.basename(theme.path); + themeData.label = theme.label || basename(theme.path); themeData.settingsId = theme.id || themeData.label; themeData.description = theme.description; themeData.watch = theme._watch === true; @@ -272,8 +273,6 @@ export class ColorThemeData implements IColorTheme { } } - - function toCSSSelector(str: string) { str = str.replace(/[^_\-a-zA-Z0-9]/g, '-'); if (str.charAt(0).match(/[0-9\-]/)) { diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index cd64deb76e8..fbad68aae23 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -818,7 +818,7 @@ export class TestFileService implements IFileService { encoding: 'utf8', mtime: Date.now(), isDirectory: false, - name: paths.basename(resource.fsPath) + name: resources.basename(resource) }); } @@ -837,7 +837,7 @@ export class TestFileService implements IFileService { etag: 'index.txt', encoding: 'utf8', mtime: Date.now(), - name: paths.basename(resource.fsPath) + name: resources.basename(resource) }); } @@ -857,7 +857,7 @@ export class TestFileService implements IFileService { etag: 'index.txt', encoding: 'utf8', mtime: Date.now(), - name: paths.basename(resource.fsPath) + name: resources.basename(resource) }); } @@ -868,7 +868,7 @@ export class TestFileService implements IFileService { encoding: 'utf8', mtime: Date.now(), isDirectory: false, - name: paths.basename(resource.fsPath) + name: resources.basename(resource) })); }