Skip to content

Commit

Permalink
add proposed API for short and long variant of `LanguageStatusItem#te…
Browse files Browse the repository at this point in the history
…xt` (microsoft#195141)

* add proposed API for short and long variant of `LanguageStatusItem#text`

microsoft#192880

* add new proposal to allow list
  • Loading branch information
jrieken authored and Alex0007 committed Oct 26, 2023
1 parent bac1482 commit 58ef38f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
3 changes: 2 additions & 1 deletion extensions/vscode-api-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"portsAttributes",
"quickPickSortByLabel",
"readonlyMessage",
"languageStatusText",
"resolvers",
"saveEditor",
"scmActionButton",
Expand All @@ -44,7 +45,7 @@
"textSearchProvider",
"timeline",
"tokenInformation",
"treeViewActiveItem",
"treeViewActiveItem",
"treeViewReveal",
"workspaceTrust",
"telemetry",
Expand Down
12 changes: 11 additions & 1 deletion src/vs/workbench/api/common/extHostLanguages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { CommandsConverter } from 'vs/workbench/api/common/extHostCommands';
import { IURITransformer } from 'vs/base/common/uriIpc';
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';

export class ExtHostLanguages implements ExtHostLanguagesShape {

Expand Down Expand Up @@ -90,7 +91,7 @@ export class ExtHostLanguages implements ExtHostLanguagesShape {
}
ids.add(fullyQualifiedId);

const data: Omit<vscode.LanguageStatusItem, 'dispose'> = {
const data: Omit<vscode.LanguageStatusItem, 'dispose' | 'text2'> = {
selector,
id,
name: extension.displayName ?? extension.name,
Expand Down Expand Up @@ -160,6 +161,15 @@ export class ExtHostLanguages implements ExtHostLanguagesShape {
data.text = value;
updateAsync();
},
set text2(value) {
checkProposedApiEnabled(extension, 'languageStatusText');
data.text = value;
updateAsync();
},
get text2() {
checkProposedApiEnabled(extension, 'languageStatusText');
return data.text;
},
get detail() {
return data.detail;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { URI } from 'vs/base/common/uri';
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
import { IAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility';

class LanguageStatusViewModel {

Expand Down Expand Up @@ -182,7 +183,7 @@ class EditorStatusContribution implements IWorkbenchContribution {
for (const status of model.combined) {
const isPinned = model.dedicated.includes(status);
element.appendChild(this._renderStatus(status, showSeverity, isPinned, this._renderDisposables));
ariaLabels.push(this._asAriaLabel(status));
ariaLabels.push(EditorStatusContribution._accessibilityInformation(status).label);
isOneBusy = isOneBusy || (!isPinned && status.busy); // unpinned items contribute to the busy-indicator of the composite status item
}
const props: IStatusbarEntry = {
Expand Down Expand Up @@ -275,7 +276,8 @@ class EditorStatusContribution implements IWorkbenchContribution {

const label = document.createElement('span');
label.classList.add('label');
dom.append(label, ...renderLabelWithIcons(status.busy ? `$(sync~spin)\u00A0\u00A0${status.label}` : status.label));
const labelValue = typeof status.label === 'string' ? status.label : status.label.value;
dom.append(label, ...renderLabelWithIcons(status.busy ? `$(sync~spin)\u00A0\u00A0${labelValue}` : labelValue));
left.appendChild(label);

const detail = document.createElement('span');
Expand Down Expand Up @@ -351,13 +353,15 @@ class EditorStatusContribution implements IWorkbenchContribution {
}
}

private _asAriaLabel(status: ILanguageStatus): string {
private static _accessibilityInformation(status: ILanguageStatus): IAccessibilityInformation {
if (status.accessibilityInfo) {
return status.accessibilityInfo.label;
} else if (status.detail) {
return localize('aria.1', '{0}, {1}', status.label, status.detail);
return status.accessibilityInfo;
}
const textValue = typeof status.label === 'string' ? status.label : status.label.value;
if (status.detail) {
return { label: localize('aria.1', '{0}, {1}', textValue, status.detail) };
} else {
return localize('aria.2', '{0}', status.label);
return { label: localize('aria.2', '{0}', textValue) };
}
}

Expand All @@ -372,10 +376,12 @@ class EditorStatusContribution implements IWorkbenchContribution {
kind = 'error';
}

const textValue = typeof item.label === 'string' ? item.label : item.label.shortValue;

return {
name: localize('name.pattern', '{0} (Language Status)', item.name),
text: item.busy ? `${item.label}\u00A0\u00A0$(sync~spin)` : item.label,
ariaLabel: item.accessibilityInfo?.label ?? item.label,
text: item.busy ? `${textValue}\u00A0\u00A0$(sync~spin)` : textValue,
ariaLabel: EditorStatusContribution._accessibilityInformation(item).label,
role: item.accessibilityInfo?.role,
tooltip: item.command?.tooltip || new MarkdownString(item.detail, { isTrusted: true, supportThemeIcons: true }),
kind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const allApiProposals = Object.freeze({
interactiveUserActions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactiveUserActions.d.ts',
interactiveWindow: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactiveWindow.d.ts',
ipc: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.ipc.d.ts',
languageStatusText: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.languageStatusText.d.ts',
mappedEditsProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.mappedEditsProvider.d.ts',
notebookCellExecutionState: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookCellExecutionState.d.ts',
notebookControllerAffinityHidden: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookControllerAffinityHidden.d.ts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface ILanguageStatus {
readonly name: string;
readonly selector: LanguageSelector;
readonly severity: Severity;
readonly label: string;
readonly label: string | { value: string; shortValue: string };
readonly detail: string;
readonly busy: boolean;
readonly source: string;
Expand Down
12 changes: 12 additions & 0 deletions src/vscode-dts/vscode.proposed.languageStatusText.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

declare module 'vscode' {

export interface LanguageStatusItem {

text2: string | { value: string; shortValue: string };
}
}

0 comments on commit 58ef38f

Please sign in to comment.