Skip to content

Commit 83d8f28

Browse files
committed
labelService: handle workspace paths without .code-workspace extension
1 parent a721a6c commit 83d8f28

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/vs/editor/contrib/snippet/snippetVariables.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ITextModel } from 'vs/editor/common/model';
99
import { Selection } from 'vs/editor/common/core/selection';
1010
import { VariableResolver, Variable, Text } from 'vs/editor/contrib/snippet/snippetParser';
1111
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
12-
import { getLeadingWhitespace, commonPrefixLength, isFalsyOrWhitespace, pad } from 'vs/base/common/strings';
12+
import { getLeadingWhitespace, commonPrefixLength, isFalsyOrWhitespace, pad, endsWith } from 'vs/base/common/strings';
1313
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
1414
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
1515
import { isSingleFolderWorkspaceIdentifier, toWorkspaceIdentifier, WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
@@ -269,7 +269,10 @@ export class WorkspaceBasedVariableResolver implements VariableResolver {
269269
return basename(workspaceIdentifier.path);
270270
}
271271

272-
const filename = basename(workspaceIdentifier.configPath.path);
273-
return filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);
272+
let filename = basename(workspaceIdentifier.configPath.path);
273+
if (endsWith(filename, WORKSPACE_EXTENSION)) {
274+
filename = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);
275+
}
276+
return filename;
274277
}
275278
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
1111
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
1212
import { localize } from 'vs/nls';
1313
import { isEqualOrParent, basename } from 'vs/base/common/resources';
14+
import { endsWith } from 'vs/base/common/strings';
1415

1516
export interface ILabelService {
1617
_serviceBrand: any;
@@ -54,9 +55,11 @@ export function getSimpleWorkspaceLabel(workspace: IWorkspaceIdentifier | URI, w
5455
return localize('untitledWorkspace', "Untitled (Workspace)");
5556
}
5657

57-
const filename = basename(workspace.configPath);
58-
const workspaceName = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);
59-
return localize('workspaceName', "{0} (Workspace)", workspaceName);
58+
let filename = basename(workspace.configPath);
59+
if (endsWith(filename, WORKSPACE_EXTENSION)) {
60+
filename = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);
61+
}
62+
return localize('workspaceName', "{0} (Workspace)", filename);
6063
}
6164

6265

src/vs/workbench/services/label/common/labelService.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,15 @@ export class LabelService implements ILabelService {
182182
}
183183

184184
// Workspace: Saved
185-
const filename = basename(workspace.configPath);
186-
const workspaceName = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);
185+
let filename = basename(workspace.configPath);
186+
if (endsWith(filename, WORKSPACE_EXTENSION)) {
187+
filename = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);
188+
}
187189
let label;
188190
if (options && options.verbose) {
189-
label = localize('workspaceNameVerbose', "{0} (Workspace)", this.getUriLabel(joinPath(dirname(workspace.configPath), workspaceName)));
191+
label = localize('workspaceNameVerbose', "{0} (Workspace)", this.getUriLabel(joinPath(dirname(workspace.configPath), filename)));
190192
} else {
191-
label = localize('workspaceName', "{0} (Workspace)", workspaceName);
193+
label = localize('workspaceName', "{0} (Workspace)", filename);
192194
}
193195
return this.appendWorkspaceSuffix(label, workspace.configPath);
194196
}

0 commit comments

Comments
 (0)