Skip to content

Commit faa6d4a

Browse files
isidornalexdima
authored andcommitted
Enhance LabelService
1 parent e146b7a commit faa6d4a

5 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/vs/code/electron-main/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function createServices(args: ParsedArgs, bufferLogService: BufferLogService): I
5757
const environmentService = new EnvironmentService(args, process.execPath);
5858
const consoleLogService = new ConsoleLogMainService(getLogLevel(environmentService));
5959
const logService = new MultiplexLogService([consoleLogService, bufferLogService]);
60-
const labelService = new LabelService(environmentService, undefined);
60+
const labelService = new LabelService(environmentService, undefined, undefined);
6161

6262
process.once('exit', () => logService.dispose());
6363

src/vs/editor/standalone/browser/simpleServices.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,4 +617,8 @@ export class SimpleUriLabelService implements ILabelService {
617617
public registerFormatter(selector: string, formatter: LabelRules): IDisposable {
618618
throw new Error('Not implemented');
619619
}
620+
621+
public getHostLabel(): string {
622+
return '';
623+
}
620624
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { localize } from 'vs/nls';
1818
import { isParent } from 'vs/platform/files/common/files';
1919
import { basename, dirname, join } from 'vs/base/common/paths';
2020
import { Schemas } from 'vs/base/common/network';
21+
import { IWindowService } from 'vs/platform/windows/common/windows';
22+
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
2123

2224
export interface RegisterFormatterEvent {
2325
selector: string;
@@ -33,6 +35,7 @@ export interface ILabelService {
3335
*/
3436
getUriLabel(resource: URI, options?: { relative?: boolean, noPrefix?: boolean }): string;
3537
getWorkspaceLabel(workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | IWorkspace), options?: { verbose: boolean }): string;
38+
getHostLabel(): string;
3639
registerFormatter(selector: string, formatter: LabelRules): IDisposable;
3740
onDidRegisterFormatter: Event<RegisterFormatterEvent>;
3841
}
@@ -66,7 +69,8 @@ export class LabelService implements ILabelService {
6669

6770
constructor(
6871
@IEnvironmentService private environmentService: IEnvironmentService,
69-
@IWorkspaceContextService private contextService: IWorkspaceContextService
72+
@IWorkspaceContextService private contextService: IWorkspaceContextService,
73+
@IWindowService private windowService: IWindowService
7074
) { }
7175

7276
get onDidRegisterFormatter(): Event<RegisterFormatterEvent> {
@@ -155,6 +159,19 @@ export class LabelService implements ILabelService {
155159
return localize('workspaceName', "{0} (Workspace)", workspaceName);
156160
}
157161

162+
getHostLabel(): string {
163+
if (this.windowService) {
164+
const authority = this.windowService.getConfiguration().remoteAuthority;
165+
if (authority) {
166+
const formatter = this.findFormatter(URI.from({ scheme: REMOTE_HOST_SCHEME, authority }));
167+
if (formatter && formatter.workspace) {
168+
return formatter.workspace.suffix;
169+
}
170+
}
171+
}
172+
return '';
173+
}
174+
158175
registerFormatter(selector: string, formatter: LabelRules): IDisposable {
159176
this.formatters[selector] = formatter;
160177
this._onDidRegisterFormatter.fire({ selector, formatter });

src/vs/platform/label/test/label.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as assert from 'assert';
77
import { LabelService } from 'vs/platform/label/common/label';
8-
import { TestEnvironmentService, TestContextService } from 'vs/workbench/test/workbenchTestServices';
8+
import { TestEnvironmentService, TestContextService, TestWindowService } from 'vs/workbench/test/workbenchTestServices';
99
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
1010
import { URI } from 'vs/base/common/uri';
1111
import { nativeSep } from 'vs/base/common/paths';
@@ -16,7 +16,7 @@ suite('URI Label', () => {
1616
let labelService: LabelService;
1717

1818
setup(() => {
19-
labelService = new LabelService(TestEnvironmentService, new TestContextService());
19+
labelService = new LabelService(TestEnvironmentService, new TestContextService(), new TestWindowService());
2020
});
2121

2222
test('file scheme', function () {

src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Range } from 'vs/editor/common/core/range';
1919
import { Position } from 'vs/editor/common/core/position';
2020
import { IModelService } from 'vs/editor/common/services/modelService';
2121
import { EditOperation } from 'vs/editor/common/core/editOperation';
22-
import { TestFileService, TestEditorService, TestEditorGroupsService, TestEnvironmentService, TestContextService, TestTextResourcePropertiesService } from 'vs/workbench/test/workbenchTestServices';
22+
import { TestFileService, TestEditorService, TestEditorGroupsService, TestEnvironmentService, TestContextService, TestTextResourcePropertiesService, TestWindowService } from 'vs/workbench/test/workbenchTestServices';
2323
import { ResourceTextEdit } from 'vs/editor/common/modes';
2424
import { BulkEditService } from 'vs/workbench/services/bulkEdit/electron-browser/bulkEditService';
2525
import { NullLogService } from 'vs/platform/log/common/log';
@@ -82,7 +82,7 @@ suite('MainThreadEditors', () => {
8282
}
8383
};
8484

85-
const bulkEditService = new BulkEditService(new NullLogService(), modelService, new TestEditorService(), textModelService, new TestFileService(), textFileService, new LabelService(TestEnvironmentService, new TestContextService()), configService);
85+
const bulkEditService = new BulkEditService(new NullLogService(), modelService, new TestEditorService(), textModelService, new TestFileService(), textFileService, new LabelService(TestEnvironmentService, new TestContextService(), new TestWindowService()), configService);
8686

8787
const rpcProtocol = new TestRPCProtocol();
8888
rpcProtocol.set(ExtHostContext.ExtHostDocuments, new class extends mock<ExtHostDocumentsShape>() {

0 commit comments

Comments
 (0)