Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API proposal for markdown tree message #188661

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/vs/workbench/api/browser/mainThreadTreeViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { createStringDataTransferItem, VSDataTransfer } from 'vs/base/common/dat
import { VSBuffer } from 'vs/base/common/buffer';
import { DataTransferFileCache } from 'vs/workbench/api/common/shared/dataTransferCache';
import * as typeConvert from 'vs/workbench/api/common/extHostTypeConverters';
import { IMarkdownString } from 'vs/base/common/htmlContent';

@extHostNamedCustomer(MainContext.MainThreadTreeViews)
export class MainThreadTreeViews extends Disposable implements MainThreadTreeViewsShape {
Expand Down Expand Up @@ -90,8 +91,8 @@ export class MainThreadTreeViews extends Disposable implements MainThreadTreeVie
return Promise.resolve();
}

$setMessage(treeViewId: string, message: string): void {
this.logService.trace('MainThreadTreeViews#$setMessage', treeViewId, message);
$setMessage(treeViewId: string, message: string | IMarkdownString): void {
this.logService.trace('MainThreadTreeViews#$setMessage', treeViewId, message.toString());

const viewer = this.getTreeView(treeViewId);
if (viewer) {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export interface MainThreadTreeViewsShape extends IDisposable {
$registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean; canSelectMany: boolean; dropMimeTypes: readonly string[]; dragMimeTypes: readonly string[]; hasHandleDrag: boolean; hasHandleDrop: boolean; manuallyManageCheckboxes: boolean }): Promise<void>;
$refresh(treeViewId: string, itemsToRefresh?: { [treeItemHandle: string]: ITreeItem }): Promise<void>;
$reveal(treeViewId: string, itemInfo: { item: ITreeItem; parentChain: ITreeItem[] } | undefined, options: IRevealOptions): Promise<void>;
$setMessage(treeViewId: string, message: string): void;
$setMessage(treeViewId: string, message: string | IMarkdownString): void;
$setTitle(treeViewId: string, title: string, description: string | undefined): void;
$setBadge(treeViewId: string, badge: IViewBadge | undefined): void;
$resolveDropFileData(destinationViewId: string, requestId: number, dataItemId: string): Promise<VSBuffer>;
Expand Down
18 changes: 11 additions & 7 deletions src/vs/workbench/api/common/extHostTreeViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { equals, coalesce } from 'vs/base/common/arrays';
import { ILogService } from 'vs/platform/log/common/log';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { MarkdownString, ViewBadge, DataTransfer } from 'vs/workbench/api/common/extHostTypeConverters';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { IMarkdownString, isMarkdownString } from 'vs/base/common/htmlContent';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { ITreeViewsDnDService, TreeViewsDnDService } from 'vs/editor/common/services/treeViewsDnd';
import { IAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility';
Expand Down Expand Up @@ -95,7 +95,7 @@ export class ExtHostTreeViews implements ExtHostTreeViewsShape {
const treeView = this.createExtHostTreeView(viewId, options, extension);
const proxyOptions = { showCollapseAll: !!options.showCollapseAll, canSelectMany: !!options.canSelectMany, dropMimeTypes, dragMimeTypes, hasHandleDrag, hasHandleDrop, manuallyManageCheckboxes: !!options.manageCheckboxStateManually };
const registerPromise = this._proxy.$registerTreeViewDataProvider(viewId, proxyOptions);
return {
const view = {
get onDidCollapseElement() { return treeView.onDidCollapseElement; },
get onDidExpandElement() { return treeView.onDidExpandElement; },
get selection() { return treeView.selectedElements; },
Expand All @@ -114,7 +114,10 @@ export class ExtHostTreeViews implements ExtHostTreeViewsShape {
return treeView.onDidChangeCheckboxState;
},
get message() { return treeView.message; },
set message(message: string) {
set message(message: string | vscode.MarkdownString) {
if (isMarkdownString(message)) {
checkProposedApiEnabled(extension, 'treeViewMarkdownMessage');
}
treeView.message = message;
},
get title() { return treeView.title; },
Expand Down Expand Up @@ -150,6 +153,7 @@ export class ExtHostTreeViews implements ExtHostTreeViewsShape {
treeView.dispose();
}
};
return view as vscode.TreeView<T>;
}

$getChildren(treeViewId: string, treeItemHandle?: string): Promise<ITreeItem[] | undefined> {
Expand Down Expand Up @@ -382,7 +386,7 @@ class ExtHostTreeView<T> extends Disposable {
});
}
if (message) {
this.proxy.$setMessage(this.viewId, this._message);
this.proxy.$setMessage(this.viewId, MarkdownString.fromStrict(this._message) ?? '');
}
}));
}
Expand Down Expand Up @@ -427,12 +431,12 @@ class ExtHostTreeView<T> extends Disposable {
}
}

private _message: string = '';
get message(): string {
private _message: string | vscode.MarkdownString = '';
get message(): string | vscode.MarkdownString {
return this._message;
}

set message(message: string) {
set message(message: string | vscode.MarkdownString) {
this._message = message;
this._onDidChangeData.fire({ message: true, element: false });
}
Expand Down
4 changes: 4 additions & 0 deletions src/vs/workbench/browser/parts/views/media/views.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
padding-left: 24px;
}

.monaco-workbench .tree-explorer-viewlet-tree-view .message a {
color: var(--vscode-textLink-foreground);
}

.monaco-workbench .tree-explorer-viewlet-tree-view .message.hide {
display: none;
}
Expand Down
30 changes: 22 additions & 8 deletions src/vs/workbench/browser/parts/views/treeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Codicon } from 'vs/base/common/codicons';
import { isCancellationError } from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import { createMatches, FuzzyScore } from 'vs/base/common/filters';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { IMarkdownString, isMarkdownString } from 'vs/base/common/htmlContent';
import { Disposable, DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { Mimes } from 'vs/base/common/mime';
import { Schemas } from 'vs/base/common/network';
Expand Down Expand Up @@ -72,6 +72,7 @@ import { AriaRole } from 'vs/base/browser/ui/aria/aria';
import { TelemetryTrustedValue } from 'vs/platform/telemetry/common/telemetryUtils';
import { ITreeViewsDnDService } from 'vs/editor/common/services/treeViewsDndService';
import { DraggedTreeItemsIdentifier } from 'vs/editor/common/services/treeViewsDnd';
import { IMarkdownRenderResult, MarkdownRenderer } from 'vs/editor/contrib/markdownRenderer/browser/markdownRenderer';

export class TreeViewPane extends ViewPane {

Expand Down Expand Up @@ -182,6 +183,10 @@ function isTreeCommandEnabled(treeCommand: TreeCommand, contextKeyService: ICont
return true;
}

function isRenderedMessageValue(messageValue: string | IMarkdownRenderResult | undefined): messageValue is IMarkdownRenderResult {
return !!messageValue && typeof messageValue !== 'string' && 'element' in messageValue && 'dispose' in messageValue;
}

const noDataProviderMessage = localize('no-dataprovider', "There is no data provider registered that can provide view data.");

export const RawCustomTreeViewContextKey = new RawContextKey<boolean>('customTreeView', false);
Expand All @@ -204,7 +209,7 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
private focused: boolean = false;
private domNode!: HTMLElement;
private treeContainer: HTMLElement | undefined;
private _messageValue: string | undefined;
private _messageValue: string | { element: HTMLElement; dispose: () => void } | undefined;
private _canSelectMany: boolean = false;
private _manuallyManageCheckboxes: boolean = false;
private messageElement: HTMLElement | undefined;
Expand All @@ -214,6 +219,7 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
private _container: HTMLElement | undefined;

private root: ITreeItem;
private markdownRenderer: MarkdownRenderer | undefined;
private elementsToRefresh: ITreeItem[] = [];
private lastSelection: readonly ITreeItem[] = [];
private lastActive: ITreeItem;
Expand Down Expand Up @@ -388,12 +394,12 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
this._onDidChangeWelcomeState.fire();
}

private _message: string | undefined;
get message(): string | undefined {
private _message: string | IMarkdownString | undefined;
get message(): string | IMarkdownString | undefined {
return this._message;
}

set message(message: string | undefined) {
set message(message: string | IMarkdownString | undefined) {
this._message = message;
this.updateMessage();
this._onDidChangeWelcomeState.fire();
Expand Down Expand Up @@ -825,15 +831,23 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
this.updateContentAreas();
}

private showMessage(message: string): void {
this._messageValue = message;
private showMessage(message: string | IMarkdownString): void {
if (isRenderedMessageValue(this._messageValue)) {
this._messageValue.dispose();
}
if (isMarkdownString(message) && !this.markdownRenderer) {
this.markdownRenderer = this.instantiationService.createInstance(MarkdownRenderer, {});
}
this._messageValue = isMarkdownString(message) ? this.markdownRenderer!.render(message) : message;
if (!this.messageElement) {
return;
}
this.messageElement.classList.remove('hide');
this.resetMessageElement();
if (!isFalsyOrWhitespace(this._message)) {
if (typeof this._messageValue === 'string' && !isFalsyOrWhitespace(this._messageValue)) {
this.messageElement.textContent = this._messageValue;
} else if (isRenderedMessageValue(this._messageValue)) {
this.messageElement.appendChild(this._messageValue.element);
}
this.layout(this._height, this._width);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/common/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ export interface ITreeView extends IDisposable {

manuallyManageCheckboxes: boolean;

message?: string;
message?: string | IMarkdownString;

title: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const allApiProposals = Object.freeze({
timeline: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.timeline.d.ts',
tokenInformation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tokenInformation.d.ts',
treeViewActiveItem: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.treeViewActiveItem.d.ts',
treeViewMarkdownMessage: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.treeViewMarkdownMessage.d.ts',
treeViewReveal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.treeViewReveal.d.ts',
tunnelFactory: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tunnelFactory.d.ts',
tunnels: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tunnels.d.ts',
Expand Down
28 changes: 28 additions & 0 deletions src/vscode-dts/vscode.proposed.treeViewMarkdownMessage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*---------------------------------------------------------------------------------------------
* 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 TreeView2<T> extends Disposable {
readonly onDidExpandElement: Event<TreeViewExpansionEvent<T>>;
readonly onDidCollapseElement: Event<TreeViewExpansionEvent<T>>;
readonly selection: readonly T[];
readonly onDidChangeSelection: Event<TreeViewSelectionChangeEvent<T>>;
readonly visible: boolean;
readonly onDidChangeVisibility: Event<TreeViewVisibilityChangeEvent>;
readonly onDidChangeCheckboxState: Event<TreeCheckboxChangeEvent<T>>;
title?: string;
description?: string;
badge?: ViewBadge | undefined;
reveal(element: T, options?: { select?: boolean; focus?: boolean; expand?: boolean | number }): Thenable<void>;

/**
* An optional human-readable message that will be rendered in the view.
* Only a subset of markdown is supported.
* Setting the message to null, undefined, or empty string will remove the message from the view.
*/
message?: string | MarkdownString;
}
}