Skip to content

Commit

Permalink
Finalize markdown tree tooltip and resolveTreeItem
Browse files Browse the repository at this point in the history
Fixes #100741
  • Loading branch information
alexr00 committed Nov 27, 2020
1 parent 016655c commit 01bbb81
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
21 changes: 20 additions & 1 deletion src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8809,6 +8809,25 @@ declare module 'vscode' {
* @return Parent of `element`.
*/
getParent?(element: T): ProviderResult<T>;

/**
* Called only on hover to resolve the [TreeItem](#TreeItem.tooltip) property if it is undefined.
* Only properties that were undefined can be resolved in `resolveTreeItem`.
* Functionality may be expanded later to include being called to resolve other missing
* properties on selection and/or on open.
*
* Will only ever be called once per TreeItem.
*
* *Note* that this function is called when tree items are already showing in the UI.
* Because of that, no property that changes the presentation (label, description, command, etc.)
* can be changed.
*
* @param element The object associated with the TreeItem
* @param item Undefined properties of `item` should be set then `item` should be returned.
* @return The resolved tree item or a thenable that resolves to such. It is OK to return the given
* `item`. When no result is returned, the given `item` will be used.
*/
resolveTreeItem?(item: TreeItem, element: T): ProviderResult<TreeItem>;
}

export class TreeItem {
Expand Down Expand Up @@ -8848,7 +8867,7 @@ declare module 'vscode' {
/**
* The tooltip text when you hover over this item.
*/
tooltip?: string | undefined;
tooltip?: string | MarkdownString | undefined;

/**
* The [command](#Command) that should be executed when the tree item is selected.
Expand Down
23 changes: 0 additions & 23 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,29 +943,6 @@ declare module 'vscode' {
//#endregion

//#region Tree View: https://github.com/microsoft/vscode/issues/61313

// https://github.com/microsoft/vscode/issues/100741
export interface TreeDataProvider<T> {
/**
* Called only on hover to resolve the TreeItem2#tooltip property if it is undefined.
* Only properties that were undefined can be resolved in `resolveTreeItem`.
* Will only ever be called once per TreeItem.
* Functionality may be expanded later to include being called to resolve other missing
* properties on selection and/or on open.
*
* @param element
* @param item Undefined properties of `item` should be set then `item` should be returned.
*/
resolveTreeItem?(item: TreeItem2, element: T): ProviderResult<TreeItem2>;
}

export class TreeItem2 extends TreeItem {
/**
* Content to be shown when you hover over the tree item.
*/
tooltip?: string | MarkdownString | /* for compilation */ any;
}

export interface TreeView<T> extends Disposable {
reveal(element: T | undefined, options?: { select?: boolean, focus?: boolean, expand?: boolean | number }): Thenable<void>;
}
Expand Down
8 changes: 3 additions & 5 deletions src/vs/workbench/api/common/extHostTreeViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { TreeItemCollapsibleState, ThemeIcon, MarkdownString as MarkdownStringTy
import { isUndefinedOrNull, isString } from 'vs/base/common/types';
import { equals, coalesce } from 'vs/base/common/arrays';
import { ILogService } from 'vs/platform/log/common/log';
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { MarkdownString } from 'vs/workbench/api/common/extHostTypeConverters';
import { IMarkdownString } from 'vs/base/common/htmlContent';
Expand Down Expand Up @@ -182,7 +181,7 @@ type TreeData<T> = { message: boolean, element: T | Root | false };

interface TreeNode extends IDisposable {
item: ITreeItem;
extensionItem: vscode.TreeItem2;
extensionItem: vscode.TreeItem;
parent: TreeNode | Root;
children?: TreeNode[];
}
Expand Down Expand Up @@ -569,13 +568,12 @@ class ExtHostTreeView<T> extends Disposable {

private getTooltip(tooltip?: string | vscode.MarkdownString): string | IMarkdownString | undefined {
if (MarkdownStringType.isMarkdownString(tooltip)) {
checkProposedApiEnabled(this.extension);
return MarkdownString.from(tooltip);
}
return tooltip;
}

private createTreeNode(element: T, extensionTreeItem: vscode.TreeItem2, parent: TreeNode | Root): TreeNode {
private createTreeNode(element: T, extensionTreeItem: vscode.TreeItem, parent: TreeNode | Root): TreeNode {
const disposable = new DisposableStore();
const handle = this.createHandle(element, extensionTreeItem, parent);
const icon = this.getLightIconPath(extensionTreeItem);
Expand Down Expand Up @@ -604,7 +602,7 @@ class ExtHostTreeView<T> extends Disposable {
};
}

private getThemeIcon(extensionTreeItem: vscode.TreeItem2): ThemeIcon | undefined {
private getThemeIcon(extensionTreeItem: vscode.TreeItem): ThemeIcon | undefined {
return extensionTreeItem.iconPath instanceof ThemeIcon ? extensionTreeItem.iconPath : undefined;
}

Expand Down

0 comments on commit 01bbb81

Please sign in to comment.