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

Refactor DebugHover so it stays properly in place #163012

Merged
merged 2 commits into from Oct 7, 2022
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
40 changes: 17 additions & 23 deletions src/vs/workbench/contrib/debug/browser/debugEditorActions.ts
Expand Up @@ -3,29 +3,28 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as nls from 'vs/nls';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { Range } from 'vs/editor/common/core/range';
import { getDomNodePagePosition } from 'vs/base/browser/dom';
import { Action } from 'vs/base/common/actions';
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorAction, EditorAction2, IActionOptions, registerEditorAction } from 'vs/editor/browser/editorExtensions';
import { Position } from 'vs/editor/common/core/position';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { registerEditorAction, EditorAction, IActionOptions, EditorAction2 } from 'vs/editor/browser/editorExtensions';
import { MessageController } from 'vs/editor/contrib/message/browser/messageController';
import * as nls from 'vs/nls';
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { IDebugService, CONTEXT_IN_DEBUG_MODE, CONTEXT_DEBUG_STATE, IDebugEditorContribution, EDITOR_CONTRIBUTION_ID, BreakpointWidgetContext, BREAKPOINT_EDITOR_CONTRIBUTION_ID, IBreakpointEditorContribution, REPL_VIEW_ID, CONTEXT_STEP_INTO_TARGETS_SUPPORTED, WATCH_VIEW_ID, CONTEXT_DEBUGGERS_AVAILABLE, CONTEXT_EXCEPTION_WIDGET_VISIBLE, CONTEXT_DISASSEMBLE_REQUEST_SUPPORTED, CONTEXT_LANGUAGE_SUPPORTS_DISASSEMBLE_REQUEST, CONTEXT_FOCUSED_STACK_FRAME_HAS_INSTRUCTION_POINTER_REFERENCE, CONTEXT_CALLSTACK_ITEM_TYPE, IDebugConfiguration } from 'vs/workbench/contrib/debug/common/debug';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { openBreakpointSource } from 'vs/workbench/contrib/debug/browser/breakpointsView';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { PanelFocusContext } from 'vs/workbench/common/contextkeys';
import { IViewsService } from 'vs/workbench/common/views';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { registerAction2, MenuId, Action2 } from 'vs/platform/actions/common/actions';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { openBreakpointSource } from 'vs/workbench/contrib/debug/browser/breakpointsView';
import { BreakpointWidgetContext, BREAKPOINT_EDITOR_CONTRIBUTION_ID, CONTEXT_CALLSTACK_ITEM_TYPE, CONTEXT_DEBUGGERS_AVAILABLE, CONTEXT_DEBUG_STATE, CONTEXT_DISASSEMBLE_REQUEST_SUPPORTED, CONTEXT_EXCEPTION_WIDGET_VISIBLE, CONTEXT_FOCUSED_STACK_FRAME_HAS_INSTRUCTION_POINTER_REFERENCE, CONTEXT_IN_DEBUG_MODE, CONTEXT_LANGUAGE_SUPPORTS_DISASSEMBLE_REQUEST, CONTEXT_STEP_INTO_TARGETS_SUPPORTED, EDITOR_CONTRIBUTION_ID, IBreakpointEditorContribution, IDebugConfiguration, IDebugEditorContribution, IDebugService, REPL_VIEW_ID, WATCH_VIEW_ID } from 'vs/workbench/contrib/debug/common/debug';
import { DisassemblyViewInput } from 'vs/workbench/contrib/debug/common/disassemblyViewInput';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { MessageController } from 'vs/editor/contrib/message/browser/messageController';
import { getDomNodePagePosition } from 'vs/base/browser/dom';
import { Position } from 'vs/editor/common/core/position';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { Action } from 'vs/base/common/actions';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';

class ToggleBreakpointAction extends EditorAction {
constructor() {
Expand Down Expand Up @@ -321,13 +320,8 @@ class ShowDebugHoverAction extends EditorAction {
if (!position || !editor.hasModel()) {
return;
}
const word = editor.getModel().getWordAtPosition(position);
if (!word) {
return;
}

const range = new Range(position.lineNumber, position.column, position.lineNumber, word.endColumn);
return editor.getContribution<IDebugEditorContribution>(EDITOR_CONTRIBUTION_ID)?.showHover(range, true);
return editor.getContribution<IDebugEditorContribution>(EDITOR_CONTRIBUTION_ID)?.showHover(position, true);
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts
Expand Up @@ -213,7 +213,7 @@ export class DebugEditorContribution implements IDebugEditorContribution {

private toDispose: IDisposable[];
private hoverWidget: DebugHoverWidget;
private hoverRange: Range | null = null;
private hoverPosition: Position | null = null;
private mouseDown = false;
private exceptionWidgetVisible: IContextKey<boolean>;

Expand Down Expand Up @@ -318,10 +318,11 @@ export class DebugEditorContribution implements IDebugEditorContribution {
const debugHoverWasVisible = this.hoverWidget.isVisible();
this.hoverWidget.hide();
this.enableEditorHover();
if (debugHoverWasVisible && this.hoverRange) {
if (debugHoverWasVisible && this.hoverPosition) {
// If the debug hover was visible immediately show the editor hover for the alt transition to be smooth
const hoverController = this.editor.getContribution<ModesHoverController>(ModesHoverController.ID);
hoverController?.showContentHover(this.hoverRange, HoverStartMode.Immediate, false);
const range = new Range(this.hoverPosition.lineNumber, this.hoverPosition.column, this.hoverPosition.lineNumber, this.hoverPosition.column);
hoverController?.showContentHover(range, HoverStartMode.Immediate, false);
}

const onKeyUp = new DomEmitter(document, 'keyup');
Expand Down Expand Up @@ -365,11 +366,11 @@ export class DebugEditorContribution implements IDebugEditorContribution {
}
}

async showHover(range: Range, focus: boolean): Promise<void> {
async showHover(position: Position, focus: boolean): Promise<void> {
const sf = this.debugService.getViewModel().focusedStackFrame;
const model = this.editor.getModel();
if (sf && model && this.uriIdentityService.extUri.isEqual(sf.source.uri, model.uri) && !this.altPressed) {
return this.hoverWidget.showAt(range, focus);
return this.hoverWidget.showAt(position, focus);
}
}

Expand All @@ -391,8 +392,8 @@ export class DebugEditorContribution implements IDebugEditorContribution {
private get showHoverScheduler(): RunOnceScheduler {
const hoverOption = this.editor.getOption(EditorOption.hover);
const scheduler = new RunOnceScheduler(() => {
if (this.hoverRange) {
this.showHover(this.hoverRange, false);
if (this.hoverPosition) {
this.showHover(this.hoverPosition, false);
}
}, hoverOption.delay * 2);
this.toDispose.push(scheduler);
Expand Down Expand Up @@ -443,8 +444,8 @@ export class DebugEditorContribution implements IDebugEditorContribution {
return;
}
if (target.type === MouseTargetType.CONTENT_TEXT) {
if (target.range && !target.range.equalsRange(this.hoverRange)) {
this.hoverRange = target.range;
if (target.position && !Position.equals(target.position, this.hoverPosition)) {
this.hoverPosition = target.position;
this.hideHoverScheduler.cancel();
this.showHoverScheduler.schedule();
}
Expand Down