Change:
Issue Type: <bBug</bI have a multi-root workspace with this config: When I open search results in an editor, the part is incorrectly shown as part of the path: And while this looks like just a cosmetic issue , it also breaks opening the file via F12/doubleclick, since the now gets duplicated in the actual path is tries to open. VS Code version: Code - Insiders 1.47.0-insider (, 2020-06-23T09:03:35.861Z) OS version: WindowsNT x64 10.0. Remote OS version: Linux x64 4.14.83-gentoo Remote OS version: Linux x64 4.14.83-gentoo Remote OS version: Linux x64 5.4.28-gentoo Remote OS version: Linux x64 4.14.83-gentoo <details<summarySystem Info</summary </details<details<summaryExtensions (32)</summaryExtensionVersion ------ systemd-unit-file1.0.6 udev-rules1.0.0 viml0.1.7 tmux0.1.0 remote-containers0.123.0 remote-ssh0.51.0 remote-ssh-edit0.51.0 remote-wsl0.44.4 vscode-remote-extensionpack0.20.0 jinjahtml0.13.0 gitconfig2.0.1 mako0.2.0 vscode-icons10.1.1 overtype0.2.0 vscode-module-templates1.3.0 vscode-postgres1.1.11 quick-open-prefill-selection0.0.1 vscode-eslint2.1.5 gitlens10.2.2 EditorConfig0.15.1 prettier-vscode5.1.0 Go0.14.4 search-editor-apply-changes0.1.1 vsc-python-indent1.10.1 restructuredtext128.0.0 MagicPython1.1.0 vscode-github-actions3.0.0 vscode-docker1.3.1 python2020.7.-dev puppet-vscode0.27.3 vscode-yaml0.8.0 vscode-stylelint0.84.0 (1 theme extensions excluded) </details<!-- generated by issue reporter --
Thanks for submitting this! Should be fixed in the next insiders.

Discussion:
import { Registry } from 'vs/platform/registry/common/platform'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IWorkspaceContextService, IWorkspace } from 'vs/platform/workspace/common/workspace'; <del> import { isEqual, basenameOrAuthority, basename, joinPath, dirname } from 'vs/base/common/resources'; </del> <ins> import { basenameOrAuthority, basename, joinPath, dirname } from 'vs/base/common/resources'; </ins> import { tildify, getPathLabel } from 'vs/base/common/labels'; import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, WORKSPACE_EXTENSION, toWorkspaceIdentifier, isWorkspaceIdentifier, isUntitledWorkspace } from 'vs/platform/workspaces/common/workspaces'; import { ILabelService, ResourceLabelFormatter, ResourceLabelFormatting, IFormatterChangeEvent } from 'vs/platform/label/common/label';

const baseResource = this.contextService?.getWorkspaceFolder(resource); if (options.relative && baseResource) { <del> const rootName = baseResource?.name ?? basenameOrAuthority(baseResource.uri); </del> <ins> const baseResourceLabel = this.formatUri(baseResource.uri, formatting, options.noPrefix); let relativeLabel = this.formatUri(resource, formatting, options.noPrefix); </ins> <del> let relativeLabel: string; if (isEqual(baseResource.uri, resource)) { relativeLabel = ''; // no label if resources are identical } else { const baseResourceLabel = this.formatUri(baseResource.uri, formatting, options.noPrefix); relativeLabel = this.formatUri(resource, formatting, options.noPrefix).substring(baseResourceLabel.lastIndexOf(formatting.separator) + 1); if (relativeLabel.startsWith(rootName)) { relativeLabel = relativeLabel.substring(rootName.length + (relativeLabel[rootName.length] === formatting.separator ? 1 : 0)); } </del> <ins> let overlap = 0; while (relativeLabel[overlap] && relativeLabel[overlap] === baseResourceLabel[overlap]) { overlap++; } if (!relativeLabel[overlap] || relativeLabel[overlap] === formatting.separator) { relativeLabel = relativeLabel.substring(1 + overlap); </ins> } const hasMultipleRoots = this.contextService.getWorkspace().folders.length > 1; if (hasMultipleRoots && !options.noPrefix) { <ins> const rootName = baseResource?.name ?? basenameOrAuthority(baseResource.uri); </ins> relativeLabel = relativeLabel ? (rootName + ' • ' + relativeLabel) : rootName; // always show root basename if there are multiple }

*  Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ <ins> import * as resources from 'vs/base/common/resources'; </ins> import * as assert from 'assert'; import { TestEnvironmentService, TestPathService } from 'vs/workbench/test/browser/workbenchTestServices'; import { URI } from 'vs/base/common/uri'; import { LabelService } from 'vs/workbench/services/label/common/labelService'; import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices'; <ins> import { Workspace, WorkspaceFolder } from 'vs/platform/workspace/common/workspace'; </ins> suite('URI Label', () => { let labelService: LabelService; setup(() => {

assert.equal(labelService.getUriLabel(uri1, { relative: false }), 'LABEL: /END'); }); }); <ins> suite('multi-root worksapce', () => { let labelService: LabelService; setup(() => { const sources = URI.file('folder1/src'); const tests = URI.file('folder1/test'); const other = URI.file('folder2'); labelService = new LabelService( TestEnvironmentService, new TestContextService( new Workspace('test-workspaace', [ new WorkspaceFolder({ uri: sources, index: 0, name: 'Sources' }, { uri: sources.toString() }), new WorkspaceFolder({ uri: tests, index: 1, name: 'Tests' }, { uri: tests.toString() }), new WorkspaceFolder({ uri: other, index: 2, name: resources.basename(other) }, { uri: other.toString() }), ])), new TestPathService()); }); test('labels of files in multiroot workspaces are the foldername folloed by offset from the folder', () => { labelService.registerFormatter({ scheme: 'file', formatting: { label: '${authority}${path}', separator: '/', tildify: false, normalizeDriveLetter: false, authorityPrefix: '//', workspaceSuffix: '' } }); const tests = { 'folder1/src/file': 'Sources • file', 'folder1/src/folder/file': 'Sources • folder/file', 'folder1/src': 'Sources', 'folder1/other': '/folder1/other', 'folder2/other': 'folder2 • other', }; Object.entries(tests).forEach(([path, label]) => { const generated = labelService.getUriLabel(URI.file(path), { relative: true }); assert.equal(generated, label); }); }); test('labels with context after path', () => { labelService.registerFormatter({ scheme: 'file', formatting: { label: '${path} (${scheme})', separator: '/', } }); const tests = { 'folder1/src/file': 'Sources • file (file)', 'folder1/src/folder/file': 'Sources • folder/file (file)', 'folder1/src': 'Sources', 'folder1/other': '/folder1/other (file)', 'folder2/other': 'folder2 • other (file)', }; Object.entries(tests).forEach(([path, label]) => { const generated = labelService.getUriLabel(URI.file(path), { relative: true }); assert.equal(generated, label, path); }); }); }); </ins>