Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to strip starting separators in formatted ${path} substitutions #103595

Merged
merged 1 commit into from Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vs/platform/label/common/label.ts
Expand Up @@ -49,4 +49,5 @@ export interface ResourceLabelFormatting {
normalizeDriveLetter?: boolean;
workspaceSuffix?: string;
authorityPrefix?: string;
stripPathStartingSeparator?: boolean;
}
1 change: 1 addition & 0 deletions src/vs/vscode.proposed.d.ts
Expand Up @@ -258,6 +258,7 @@ declare module 'vscode' {
normalizeDriveLetter?: boolean;
workspaceSuffix?: string;
authorityPrefix?: string;
stripPathStartingSeparator?: boolean;
}

export namespace workspace {
Expand Down
9 changes: 8 additions & 1 deletion src/vs/workbench/services/label/common/labelService.ts
Expand Up @@ -51,6 +51,10 @@ const resourceLabelFormattersExtPoint = ExtensionsRegistry.registerExtensionPoin
type: 'string',
description: localize('vscode.extension.contributes.resourceLabelFormatters.separator', "Separator to be used in the uri label display. '/' or '\' as an example.")
},
stripPathStartingSeparator: {
type: 'boolean',
description: localize('vscode.extension.contributes.resourceLabelFormatters.stripPathStartingSeparator', "Controls whether `${path}` substitutions should have starting separator characters stripped.")
},
tildify: {
type: 'boolean',
description: localize('vscode.extension.contributes.resourceLabelFormatters.tildify', "Controls if the start of the uri label should be tildified when possible.")
Expand Down Expand Up @@ -244,7 +248,10 @@ export class LabelService extends Disposable implements ILabelService {
switch (token) {
case 'scheme': return resource.scheme;
case 'authority': return resource.authority;
case 'path': return resource.path;
case 'path':
return formatting.stripPathStartingSeparator
? resource.path.slice(resource.path[0] === formatting.separator ? 1 : 0)
: resource.path;
default: {
if (qsToken === 'query') {
const { query } = resource;
Expand Down
20 changes: 20 additions & 0 deletions src/vs/workbench/services/label/test/browser/label.test.ts
Expand Up @@ -226,6 +226,26 @@ suite('multi-root worksapce', () => {
const generated = labelService.getUriLabel(URI.file(path), { relative: true });
assert.equal(generated, label, path);
});
});

test('stripPathStartingSeparator', () => {
labelService.registerFormatter({
scheme: 'file',
formatting: {
label: '${path}',
separator: '/',
stripPathStartingSeparator: true
}
});

const tests = {
'folder1/src/file': 'Sources • file',
'other/blah': 'other/blah',
};

Object.entries(tests).forEach(([path, label]) => {
const generated = labelService.getUriLabel(URI.file(path), { relative: true });
assert.equal(generated, label, path);
});
});
});