|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | + |
| 7 | +declare module 'vscode' { |
| 8 | + export namespace debug { |
| 9 | + /** |
| 10 | + * Registers a custom data visualization for variables when debugging. |
| 11 | + * |
| 12 | + * @param id The corresponding ID in the package.json `debugVisualizers` contribution point. |
| 13 | + * @param provider The {@link DebugVisualizationProvider} to register |
| 14 | + */ |
| 15 | + export function registerDebugVisualizationProvider<T extends DebugVisualization>( |
| 16 | + id: string, |
| 17 | + provider: DebugVisualizationProvider<T> |
| 18 | + ): Disposable; |
| 19 | + |
| 20 | + /** |
| 21 | + * Registers a tree that can be referenced by {@link DebugVisualization.visualization}. |
| 22 | + * @param id |
| 23 | + * @param provider |
| 24 | + */ |
| 25 | + export function registerDebugVisualizationTreeProvider<T extends DebugTreeItem>( |
| 26 | + id: string, |
| 27 | + provider: DebugVisualizationTree<T> |
| 28 | + ): Disposable; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * An item from the {@link DebugVisualizationTree} |
| 33 | + */ |
| 34 | + export interface DebugTreeItem { |
| 35 | + /** |
| 36 | + * A human-readable string describing this item. |
| 37 | + */ |
| 38 | + label: string; |
| 39 | + |
| 40 | + /** |
| 41 | + * A human-readable string which is rendered less prominent. |
| 42 | + */ |
| 43 | + description?: string; |
| 44 | + |
| 45 | + /** |
| 46 | + * {@link TreeItemCollapsibleState} of the tree item. |
| 47 | + */ |
| 48 | + collapsibleState?: TreeItemCollapsibleState; |
| 49 | + |
| 50 | + /** |
| 51 | + * Context value of the tree item. This can be used to contribute item specific actions in the tree. |
| 52 | + * For example, a tree item is given a context value as `folder`. When contributing actions to `view/item/context` |
| 53 | + * using `menus` extension point, you can specify context value for key `viewItem` in `when` expression like `viewItem == folder`. |
| 54 | + * ```json |
| 55 | + * "contributes": { |
| 56 | + * "menus": { |
| 57 | + * "view/item/context": [ |
| 58 | + * { |
| 59 | + * "command": "extension.deleteFolder", |
| 60 | + * "when": "viewItem == folder" |
| 61 | + * } |
| 62 | + * ] |
| 63 | + * } |
| 64 | + * } |
| 65 | + * ``` |
| 66 | + * This will show action `extension.deleteFolder` only for items with `contextValue` is `folder`. |
| 67 | + */ |
| 68 | + contextValue?: string; |
| 69 | + |
| 70 | + /** |
| 71 | + * Whether this item can be edited by the user. |
| 72 | + */ |
| 73 | + canEdit?: boolean; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Provides a tree that can be referenced in debug visualizations. |
| 78 | + */ |
| 79 | + export interface DebugVisualizationTree<T extends DebugTreeItem = DebugTreeItem> { |
| 80 | + /** |
| 81 | + * Gets the tree item for an element or the base context item. |
| 82 | + */ |
| 83 | + getTreeItem(context: DebugVisualizationContext): ProviderResult<T>; |
| 84 | + /** |
| 85 | + * Gets children for the tree item or the best context item. |
| 86 | + */ |
| 87 | + getChildren(element: T): ProviderResult<T[]>; |
| 88 | + /** |
| 89 | + * Handles the user editing an item. |
| 90 | + */ |
| 91 | + editItem?(item: T, value: string): ProviderResult<T>; |
| 92 | + } |
| 93 | + |
| 94 | + export class DebugVisualization { |
| 95 | + /** |
| 96 | + * The name of the visualization to show to the user. |
| 97 | + */ |
| 98 | + name: string; |
| 99 | + |
| 100 | + /** |
| 101 | + * An icon for the view when it's show in inline actions. |
| 102 | + */ |
| 103 | + iconPath?: Uri | { light: Uri; dark: Uri } | ThemeIcon; |
| 104 | + |
| 105 | + /** |
| 106 | + * Visualization to use for the variable. This may be either: |
| 107 | + * - A command to run when the visualization is selected for a variable. |
| 108 | + * - A reference to a previously-registered {@link DebugVisualizationTree} |
| 109 | + */ |
| 110 | + visualization?: Command | { treeId: string }; |
| 111 | + |
| 112 | + /** |
| 113 | + * Creates a new debug visualization object. |
| 114 | + * @param name Name of the visualization to show to the user. |
| 115 | + */ |
| 116 | + constructor(name: string); |
| 117 | + } |
| 118 | + |
| 119 | + export interface DebugVisualizationProvider<T extends DebugVisualization = DebugVisualization> { |
| 120 | + /** |
| 121 | + * Called for each variable when the debug session stops. It should return |
| 122 | + * any visualizations the extension wishes to show to the user. |
| 123 | + * |
| 124 | + * Note that this is only called when its `when` clause defined under the |
| 125 | + * `debugVisualizers` contribution point in the `package.json` evaluates |
| 126 | + * to true. |
| 127 | + */ |
| 128 | + provideDebugVisualization(context: DebugVisualizationContext, token: CancellationToken): ProviderResult<T[]>; |
| 129 | + |
| 130 | + /** |
| 131 | + * Invoked for a variable when a user picks the visualizer. |
| 132 | + * |
| 133 | + * It may return a {@link TreeView} that's shown in the Debug Console or |
| 134 | + * inline in a hover. A visualizer may choose to return `undefined` from |
| 135 | + * this function and instead trigger other actions in the UI, such as opening |
| 136 | + * a custom {@link WebviewView}. |
| 137 | + */ |
| 138 | + resolveDebugVisualization?(visualization: T, token: CancellationToken): ProviderResult<T>; |
| 139 | + } |
| 140 | + |
| 141 | + export interface DebugVisualizationContext { |
| 142 | + /** |
| 143 | + * The Debug Adapter Protocol Variable to be visualized. |
| 144 | + * @see https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable |
| 145 | + */ |
| 146 | + variable: any; |
| 147 | + /** |
| 148 | + * The Debug Adapter Protocol variable reference the type (such as a scope |
| 149 | + * or another variable) that contained this one. Empty for variables |
| 150 | + * that came from user evaluations in the Debug Console. |
| 151 | + * @see https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable |
| 152 | + */ |
| 153 | + containerId?: number; |
| 154 | + /** |
| 155 | + * The ID of the Debug Adapter Protocol StackFrame in which the variable was found, |
| 156 | + * for variables that came from scopes in a stack frame. |
| 157 | + * @see https://microsoft.github.io/debug-adapter-protocol/specification#Types_StackFrame |
| 158 | + */ |
| 159 | + frameId?: number; |
| 160 | + /** |
| 161 | + * The ID of the Debug Adapter Protocol Thread in which the variable was found. |
| 162 | + * @see https://microsoft.github.io/debug-adapter-protocol/specification#Types_StackFrame |
| 163 | + */ |
| 164 | + threadId: number; |
| 165 | + /** |
| 166 | + * The debug session the variable belongs to. |
| 167 | + */ |
| 168 | + session: DebugSession; |
| 169 | + } |
| 170 | +} |
0 commit comments