Skip to content

Commit a9a9195

Browse files
committed
file labels: show root name separated by •. Also absolute paths only for file schema
microsoft#51446
1 parent d901821 commit a9a9195

3 files changed

Lines changed: 27 additions & 17 deletions

File tree

src/vs/base/common/labels.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@
55
'use strict';
66

77
import URI from 'vs/base/common/uri';
8-
import { nativeSep, normalize, basename as pathsBasename, join, sep } from 'vs/base/common/paths';
9-
import { endsWith, ltrim, equalsIgnoreCase, startsWithIgnoreCase, rtrim, startsWith } from 'vs/base/common/strings';
8+
import { nativeSep, normalize, basename as pathsBasename, sep } from 'vs/base/common/paths';
9+
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';
1213

1314
export interface IWorkspaceFolderProvider {
14-
getWorkspaceFolder(resource: URI): { uri: URI };
15+
getWorkspaceFolder(resource: URI): { uri: URI, name?: string };
1516
getWorkspace(): {
16-
folders: { uri: URI }[];
17+
folders: { uri: URI, name?: string }[];
1718
};
1819
}
1920

2021
export interface IUserHomeProvider {
2122
userHome: string;
2223
}
2324

25+
/**
26+
* @param resource for which to compute the path label
27+
* @param userHomeProvider if a resource has a file schema userHomeProvider is used for tildifiying the label
28+
* @param rootProvider only passed in if the label should be relative to the workspace root
29+
*/
2430
export function getPathLabel(resource: URI | string, userHomeProvider: IUserHomeProvider, rootProvider?: IWorkspaceFolderProvider): string {
2531
if (!resource) {
2632
return null;
@@ -30,31 +36,31 @@ export function getPathLabel(resource: URI | string, userHomeProvider: IUserHome
3036
resource = URI.file(resource);
3137
}
3238

33-
// return early if the resource is neither file:// nor untitled://
34-
if (resource.scheme !== Schemas.file && resource.scheme !== Schemas.untitled) {
35-
return resource.with({ query: null, fragment: null }).toString(true);
36-
}
37-
3839
// return early if we can resolve a relative path label from the root
3940
const baseResource = rootProvider ? rootProvider.getWorkspaceFolder(resource) : null;
4041
if (baseResource) {
4142
const hasMultipleRoots = rootProvider.getWorkspace().folders.length > 1;
4243

4344
let pathLabel: string;
44-
if (isLinux ? baseResource.uri.fsPath === resource.fsPath : equalsIgnoreCase(baseResource.uri.fsPath, resource.fsPath)) {
45-
pathLabel = ''; // no label if pathes are identical
45+
if (isEqual(baseResource.uri, resource, !isLinux)) {
46+
pathLabel = ''; // no label if paths are identical
4647
} else {
47-
pathLabel = normalize(ltrim(resource.fsPath.substr(baseResource.uri.fsPath.length), nativeSep), true);
48+
pathLabel = normalize(ltrim(resource.toString().substr(baseResource.uri.toString().length), nativeSep), true);
4849
}
4950

5051
if (hasMultipleRoots) {
51-
const rootName = pathsBasename(baseResource.uri.fsPath);
52-
pathLabel = pathLabel ? join(rootName, pathLabel) : rootName; // always show root basename if there are multiple
52+
const rootName = (baseResource && baseResource.name) ? baseResource.name : pathsBasename(baseResource.uri.fsPath);
53+
pathLabel = pathLabel ? (rootName + ' • ' + pathLabel) : rootName; // always show root basename if there are multiple
5354
}
5455

5556
return pathLabel;
5657
}
5758

59+
// return if the resource is neither file:// nor untitled:// and no baseResource was provided
60+
if (resource.scheme !== Schemas.file && resource.scheme !== Schemas.untitled) {
61+
return resource.with({ query: null, fragment: null }).toString(true);
62+
}
63+
5864
// convert c:\something => C:\something
5965
if (hasDriveLetter(resource.fsPath)) {
6066
return normalize(normalizeDriveLetter(resource.fsPath), true);

src/vs/workbench/browser/labels.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ export class ResourceLabel extends IconLabel {
196196
iconLabelOptions.title = this.options.title;
197197
} else if (resource && resource.scheme !== Schemas.data /* do not accidentally inline Data URIs */) {
198198
if (!this.computedPathLabel) {
199-
this.computedPathLabel = getPathLabel(resource, this.environmentService);
199+
const rootProvider = resource.scheme !== Schemas.file ? this.contextService : undefined;
200+
this.computedPathLabel = getPathLabel(resource, this.environmentService, rootProvider);
200201
}
201202

202203
iconLabelOptions.title = this.computedPathLabel;

src/vs/workbench/parts/files/common/editors/fileEditorInput.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
2424
import { ITextModelService } from 'vs/editor/common/services/resolverService';
2525
import { IHashService } from 'vs/workbench/services/hash/common/hashService';
2626
import { FILE_EDITOR_INPUT_ID, TEXT_FILE_EDITOR_ID, BINARY_FILE_EDITOR_ID } from 'vs/workbench/parts/files/common/files';
27+
import { Schemas } from 'vs/base/common/network';
2728

2829
/**
2930
* A file editor input is the input type for the file editor of file system resources.
@@ -148,7 +149,8 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
148149

149150
@memoize
150151
private get longDescription(): string {
151-
return labels.getPathLabel(resources.dirname(this.resource), this.environmentService);
152+
const rootProvider = this.resource.scheme !== Schemas.file ? this.contextService : undefined;
153+
return labels.getPathLabel(resources.dirname(this.resource), this.environmentService, rootProvider);
152154
}
153155

154156
public getDescription(verbosity: Verbosity = Verbosity.MEDIUM): string {
@@ -181,7 +183,8 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
181183

182184
@memoize
183185
private get longTitle(): string {
184-
return labels.getPathLabel(this.resource, this.environmentService);
186+
const rootProvider = this.resource.scheme !== Schemas.file ? this.contextService : undefined;
187+
return labels.getPathLabel(this.resource, this.environmentService, rootProvider);
185188
}
186189

187190
public getTitle(verbosity: Verbosity): string {

0 commit comments

Comments
 (0)