Skip to content

Commit e0f506e

Browse files
committed
labelService getUriLabel noPrefix option
fixes microsoft#58504
1 parent 2a263ba commit e0f506e

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/vs/platform/label/common/label.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ export interface RegisterFormatterEvent {
2626

2727
export interface ILabelService {
2828
_serviceBrand: any;
29-
getUriLabel(resource: URI, options?: { relative?: boolean, forceNoTildify?: boolean }): string;
29+
/**
30+
* Gets the human readable label for a uri.
31+
* If relative is passed returns a label relative to the workspace root that the uri belongs to.
32+
* If noPrefix is passed does not tildify the label and also does not prepand the root name for relative labels in a multi root scenario.
33+
*/
34+
getUriLabel(resource: URI, options?: { relative?: boolean, noPrefix?: boolean }): string;
3035
getWorkspaceLabel(workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IWorkspace), options?: { verbose: boolean }): string;
3136
registerFormatter(schema: string, formatter: LabelRules): IDisposable;
3237
onDidRegisterFormatter: Event<RegisterFormatterEvent>;
@@ -67,7 +72,7 @@ export class LabelService implements ILabelService {
6772
return this._onDidRegisterFormatter.event;
6873
}
6974

70-
getUriLabel(resource: URI, options: { relative?: boolean, forceNoTildify?: boolean } = {}): string {
75+
getUriLabel(resource: URI, options: { relative?: boolean, noPrefix?: boolean } = {}): string {
7176
if (!resource) {
7277
return undefined;
7378
}
@@ -83,12 +88,12 @@ export class LabelService implements ILabelService {
8388
if (isEqual(baseResource.uri, resource, !isLinux)) {
8489
relativeLabel = ''; // no label if resources are identical
8590
} else {
86-
const baseResourceLabel = this.formatUri(baseResource.uri, formatter, options.forceNoTildify);
87-
relativeLabel = ltrim(this.formatUri(resource, formatter, options.forceNoTildify).substring(baseResourceLabel.length), formatter.uri.separator);
91+
const baseResourceLabel = this.formatUri(baseResource.uri, formatter, options.noPrefix);
92+
relativeLabel = ltrim(this.formatUri(resource, formatter, options.noPrefix).substring(baseResourceLabel.length), formatter.uri.separator);
8893
}
8994

9095
const hasMultipleRoots = this.contextService.getWorkspace().folders.length > 1;
91-
if (hasMultipleRoots) {
96+
if (hasMultipleRoots && !options.noPrefix) {
9297
const rootName = (baseResource && baseResource.name) ? baseResource.name : basenameOrAuthority(baseResource.uri);
9398
relativeLabel = relativeLabel ? (rootName + ' • ' + relativeLabel) : rootName; // always show root basename if there are multiple
9499
}
@@ -97,7 +102,7 @@ export class LabelService implements ILabelService {
97102
}
98103
}
99104

100-
return this.formatUri(resource, formatter, options.forceNoTildify);
105+
return this.formatUri(resource, formatter, options.noPrefix);
101106
}
102107

103108
getWorkspaceLabel(workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IWorkspace), options?: { verbose: boolean }): string {

src/vs/workbench/parts/files/electron-browser/fileCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ function resourcesToClipboard(resources: URI[], relative: boolean, clipboardServ
392392
if (resources.length) {
393393
const lineDelimiter = isWindows ? '\r\n' : '\n';
394394

395-
const text = resources.map(resource => labelService.getUriLabel(resource, { relative, forceNoTildify: true }))
395+
const text = resources.map(resource => labelService.getUriLabel(resource, { relative, noPrefix: true }))
396396
.join(lineDelimiter);
397397
clipboardService.writeText(text);
398398
} else {

0 commit comments

Comments
 (0)