Skip to content

Commit

Permalink
[vscode/debug] fix #5641: pass args directly to actions of debug/call…
Browse files Browse the repository at this point in the history
…stack/context menu

Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Jul 5, 2019
1 parent b5a521e commit d4adca2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

## v0.9.0

- [plugin] added support of debug activation events [#5645](https://github.com/theia-ide/theia/pull/5645)

Breaking changes:

- [plugin] fixed typo in 'HostedInstanceState' enum from RUNNNING to RUNNING in `plugin-dev` extension
- [plugin] removed member `processOptions` from `AbstractHostedInstanceManager` as it is not initialized or used
- [plugin] added support of activation events [#5622](https://github.com/theia-ide/theia/pull/5622)
- [plugin] added basic support of activation events [#5622](https://github.com/theia-ide/theia/pull/5622)
- `HostedPluginSupport` is refactored to support multiple `PluginManagerExt` properly

## v0.8.0
Expand Down
34 changes: 20 additions & 14 deletions packages/debug/src/browser/view/debug-stack-frames-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import { injectable, inject, postConstruct, interfaces, Container } from 'inversify';
import { MenuPath, SelectionService } from '@theia/core';
import { MenuPath } from '@theia/core';
import { TreeNode, NodeProps, SelectableTreeNode } from '@theia/core/lib/browser';
import { SourceTreeWidget, TreeElementNode } from '@theia/core/lib/browser/source-tree';
import { DebugStackFramesSource, LoadMoreStackFrames } from './debug-stack-frames-source';
Expand Down Expand Up @@ -48,9 +48,6 @@ export class DebugStackFramesWidget extends SourceTreeWidget {
@inject(DebugViewModel)
protected readonly viewModel: DebugViewModel;

@inject(SelectionService)
protected readonly selectionService: SelectionService;

@inject(DebugCallStackItemTypeKey)
protected readonly debugCallStackItemTypeKey: DebugCallStackItemTypeKey;

Expand Down Expand Up @@ -91,28 +88,37 @@ export class DebugStackFramesWidget extends SourceTreeWidget {
}
this.updatingSelection = true;
try {
let selection: string | number | undefined;
const node = this.model.selectedNodes[0];
if (TreeElementNode.is(node)) {
if (node.element instanceof DebugStackFrame) {
node.element.thread.currentFrame = node.element;
this.debugCallStackItemTypeKey.set('stackFrame');
const source = node.element.source;
if (source) {
if (source.inMemory) {
selection = source.raw.path || source.raw.sourceReference;
} else {
selection = source.uri.toString();
}
}
}
}
this.selectionService.selection = selection;
} finally {
this.updatingSelection = false;
}
}

protected toContextMenuArgs(node: SelectableTreeNode): [string | number] | undefined {
if (TreeElementNode.is(node)) {
if (node.element instanceof DebugStackFrame) {
const source = node.element.source;
if (source) {
if (source.inMemory) {
const path = source.raw.path || source.raw.sourceReference;
if (path !== undefined) {
return [path];
}
} else {
return [source.uri.toString()];
}
}
}
}
return undefined;
}

protected handleClickEvent(node: TreeNode | undefined, event: React.MouseEvent<HTMLElement>): void {
if (TreeElementNode.is(node) && node.element instanceof LoadMoreStackFrames) {
node.element.open();
Expand Down
14 changes: 7 additions & 7 deletions packages/debug/src/browser/view/debug-threads-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import { injectable, inject, postConstruct, interfaces, Container } from 'inversify';
import { MenuPath } from '@theia/core';
import { TreeNode, NodeProps, SelectableTreeNode } from '@theia/core/lib/browser';
import { SelectionService } from '@theia/core/lib/common/selection-service';
import { SourceTreeWidget, TreeElementNode } from '@theia/core/lib/browser/source-tree';
import { DebugThreadsSource } from './debug-threads-source';
import { DebugSession } from '../debug-session';
Expand Down Expand Up @@ -53,9 +52,6 @@ export class DebugThreadsWidget extends SourceTreeWidget {
@inject(DebugViewModel)
protected readonly viewModel: DebugViewModel;

@inject(SelectionService)
protected readonly selectionService: SelectionService;

@inject(DebugCallStackItemTypeKey)
protected readonly debugCallStackItemTypeKey: DebugCallStackItemTypeKey;

Expand Down Expand Up @@ -95,7 +91,6 @@ export class DebugThreadsWidget extends SourceTreeWidget {
}
this.updatingSelection = true;
try {
let selection: number | undefined;
const node = this.model.selectedNodes[0];
if (TreeElementNode.is(node)) {
if (node.element instanceof DebugSession) {
Expand All @@ -104,15 +99,20 @@ export class DebugThreadsWidget extends SourceTreeWidget {
} else if (node.element instanceof DebugThread) {
node.element.session.currentThread = node.element;
this.debugCallStackItemTypeKey.set('thread');
selection = node.element.raw.id;
}
}
this.selectionService.selection = selection;
} finally {
this.updatingSelection = false;
}
}

protected toContextMenuArgs(node: SelectableTreeNode): [number] | undefined {
if (TreeElementNode.is(node) && node.element instanceof DebugThread) {
return [node.element.raw.id];
}
return undefined;
}

protected getDefaultNodeStyle(node: TreeNode, props: NodeProps): React.CSSProperties | undefined {
if (this.threads.multiSesssion) {
return super.getDefaultNodeStyle(node, props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ export class MenusContributionPointHandler {
const menuPath = inline ? ScmWidget.RESOURCE_INLINE_MENU : ScmWidget.RESOURCE_CONTEXT_MENU;
this.registerScmMenuAction(menuPath, menu);
}
} else if (location === 'debug/callstack/context') {
for (const menu of allMenus[location]) {
for (const menuPath of [DebugStackFramesWidget.CONTEXT_MENU, DebugThreadsWidget.CONTEXT_MENU]) {
this.registerMenuAction(menuPath, menu, {
execute: (...args) => this.commands.executeCommand(menu.command, args[0]),
isEnabled: (...args) => this.commands.isEnabled(menu.command, args[0]),
isVisible: (...args) => this.commands.isVisible(menu.command, args[0])
});
}
}
} else if (allMenus.hasOwnProperty(location)) {
const menuPaths = MenusContributionPointHandler.parseMenuPaths(location);
if (!menuPaths.length) {
Expand All @@ -127,7 +137,6 @@ export class MenusContributionPointHandler {
switch (value) {
case 'editor/context': return [EDITOR_CONTEXT_MENU];
case 'explorer/context': return [NAVIGATOR_CONTEXT_MENU];
case 'debug/callstack/context': return [DebugStackFramesWidget.CONTEXT_MENU, DebugThreadsWidget.CONTEXT_MENU];
}
return [];
}
Expand Down Expand Up @@ -216,13 +225,11 @@ export class MenusContributionPointHandler {
protected registerGlobalMenuAction(menuPath: MenuPath, menu: Menu): void {
const selectedResource = () => {
const selection = this.selectionService.selection;

if (TreeWidgetSelection.is(selection) && selection.source instanceof TreeViewWidget && selection[0]) {
return selection.source.toTreeViewSelection(selection[0]);
}

const uri = this.resourceContextKey.get();
return uri ? uri['codeUri'] : (typeof selection !== 'object' && typeof selection !== 'function') ? selection : undefined;
return uri ? uri['codeUri'] : undefined;
};
this.registerMenuAction(menuPath, menu, {
execute: () => this.commands.executeCommand(menu.command, selectedResource()),
Expand Down

0 comments on commit d4adca2

Please sign in to comment.