-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
fix default Anchor param of context menu #10540
Conversation
A similar change has been proposed previously, but it was rejected because there was code that relied on the current behavior. I believe that this recent change should reduce our dependence on that behavior upstream, but there may be quite a lot of downstream code that still relies on it. Given that, there are other possibilities for working around this problem in the current context.
|
c7f078b
to
c15d754
Compare
I defined the |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export function isAnchor(arg: any): boolean { | ||
if (arg && 'x' in arg && 'y' in arg && Object.keys(arg).length === 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: We try to limit our any
usage in the framework.
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
export function isAnchor(arg: any): boolean { | |
if (arg && 'x' in arg && 'y' in arg && Object.keys(arg).length === 2) { | |
export function isAnchor(arg: unknown): boolean { | |
if (typeof arg === 'object' && arg && 'x' in arg && 'y' in arg && Object.keys(arg).length === 2) { |
@@ -1197,7 +1197,7 @@ export class DebugFrontendApplicationContribution extends AbstractViewContributi | |||
} | |||
|
|||
async start(noDebug?: boolean, debugSessionOptions?: DebugSessionOptions): Promise<void> { | |||
let current = debugSessionOptions ? debugSessionOptions : this.configurations.current; | |||
let current = debugSessionOptions && !isAnchor(debugSessionOptions) ? debugSessionOptions : this.configurations.current; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to check this condition in the command handler (around line 640), since the possibility of receiving of anchor is limited to that context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to check this condition in the command handler (around line 640), since the possibility of receiving of anchor is limited to that context.
ok, done
c15d754
to
5191d2f
Compare
export function isAnchor(arg?: Anchor): boolean { | ||
if (arg && 'x' in arg && 'y' in arg && Object.keys(arg).length === 2) { | ||
return true; | ||
} | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct and sufficient? The Anchor
type also includes MouseEvent
s (l. 26).
export interface Coordinate { x: number; y: number; }
export const Coordinate = Symbol('Coordinate');
export type Anchor = MouseEvent | Coordinate;
That also seems to be the error that is killing the build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the type to unknown.
Signed-off-by: shuyaqian 717749594@qq.com
5191d2f
to
2cd14f8
Compare
execute: (config?: DebugSessionOptions) => this.start(false, isAnchor(config) ? undefined : config) | ||
}); | ||
registry.registerCommand(DebugCommands.START_NO_DEBUG, { | ||
execute: (config?: DebugSessionOptions) => this.start(true, config) | ||
execute: (config?: DebugSessionOptions) => this.start(true, isAnchor(config) ? undefined : config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to change my mind here, but even though the cause of the problem is that an Anchor is being passed in, but what we really want to guarantee is that the config
is an instance of DebugSessionOptions
- the problem with the CommandHandler
system is that we're allowed to say config?: DebugSessionOption
, but in fact anything can be passed in - Anchors, or anything else..
So rather than adding a check for whether this is an Anchor, it would be more correct in this context to implement a check that something is a DebugSessionOptions. Something like.
export namespace DebugSessionOptions {
export function is(candidate: unknown): candidate is DebugSessionOptions {
const options = candidate as DebugSessionOptions;
return typeof options === 'object' && !!candidate && 'configuration' in candidate && DebugConfiguration.is(options.candidate);
}
}
Again, sorry for the change of direction!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say hold off on this pending a general resolution of the problems introduced by window.menuBarVisibility
compact
. As I say here, the correct, non-breaking solution is probably just to fix the behavior of the menu introduced by that PR, rather than fix the commands one by one or change the existing behavior of real context menus.
Signed-off-by: shuyaqian 717749594@qq.com
What it does
Fix default Anchor param of context menu.
How to test
debugSessionOptions
received is an anchorReview checklist
Reminder for reviewers