microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.43k stars 29.34k forks source link

"Update import from ..." quick fix doesn't trigger when clicked if on top of code lens #169854

Closed yume-chan closed 1 year ago

yume-chan commented 1 year ago

Type: Bug

  1. Click the blue light bulb
  2. Click the "Update import from ..." quick fix

🐛: Quick fix widget closes, but no import updated

https://user-images.githubusercontent.com/1330321/209171127-aa8c39d5-36ca-4fd7-90dc-1a6d5be28299.mp4

VS Code version: Code - Insiders 1.75.0-insider (42814d18a7d46adfb1c24e1349b7ab18833ec6ac, 2022-12-22T05:21:47.548Z) OS version: Windows_NT x64 10.0.25267 Modes: Sandboxed: Yes

System Info |Item|Value| |---|---| |CPUs|AMD Ryzen 5 5600X 6-Core Processor (12 x 3700)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off| |Load (avg)|undefined| |Memory (System)|31.91GB (12.14GB free)| |Process Argv|| |Screen Reader|no| |VM|0%|
Extensions (34) Extension|Author (truncated)|Version ---|---|--- Bookmarks|ale|13.3.1 smart-clicks|ant|0.1.1 vscode-zipfs|arc|3.0.0 vscode-eslint|dba|2.3.0 gitlens|eam|13.2.0 prettier-vscode|esb|9.10.3 copilot-nightly|Git|1.65.7761 remotehub|Git|0.49.2022122201 rest-client|hum|0.25.1 vscode-env|Iro|0.1.0 search-node-modules|jas|1.3.0 fluent-icons|mig|0.0.18 vscode-docker|ms-|1.23.3 remote-containers|ms-|0.268.0 remote-ssh|ms-|0.95.2022122215 remote-ssh-edit|ms-|0.84.0 remote-wsl|ms-|0.72.0 hexeditor|ms-|1.9.9 js-debug-nightly|ms-|2022.12.1417 live-server|ms-|0.5.2022122201 remote-explorer|ms-|0.1.2022121209 remote-repositories|ms-|0.26.0 vscode-typescript-next|ms-|5.0.202212210 vsliveshare|ms-|1.0.5788 abracadabra|nic|6.17.0 material-icon-theme|PKi|4.23.0 prisma|Pri|4.8.0 vscode-yaml|red|1.11.10112022 vscode-sort-json|ric|1.20.0 reveal|smu|1.2.7 code-spell-checker|str|2.12.0 luna-paint|Tyr|0.16.0 markdown-all-in-one|yzh|3.5.0 material-theme|zhu|3.15.6
mjbvz commented 1 year ago

I can't reproduce this issue. Can you please try putting together a small example project that demonstrates this problem

yume-chan commented 1 year ago

Did some debugging, this issue triggers when code fix menu item is overlapping with CodeLens. It doesn't matter what the code fix is. For example in a JavaScript file:

module.exports = { a: 1 } // Invoke code fix menu on `module`, add/remove empty lines below to make some menu item overlapping with CodeLens below

// enable `"javascript.referencesCodeLens.enabled": true`, there will be a CodeLens here
function foo() {

}

https://user-images.githubusercontent.com/1330321/210427910-675dc999-2232-490e-922f-32ffabb0cc07.mp4


https://github.com/microsoft/vscode/blob/61e40d1910a2bac6ef2c0d5271ad89b9b4338af7/src/vs/editor/browser/controller/mouseTarget.ts#L630-L638

The editor intercepts the event because this hit test found a match. Not sure what "view zone" is, but looking at my original reproduce, there is a CodeLens there.

vscodenpa commented 1 year ago

Hey @mjbvz, this issue might need further attention.

@yume-chan, you can help us out by closing this issue if the problem no longer exists, or adding more information.

yume-chan commented 1 year ago

@mjbvz Please try again using the new repro step above. It's still reproducible in latest insiders version.

mjbvz commented 1 year ago

Thank you @yume-chan! I can repo now

@alexdima I believe the root cause is that our editor mouse handlers don't know about context views. In this instance, clicking in the action widget fires mouseDown here:

https://github.com/microsoft/vscode/blob/cc443365dcf57248436812e218805983f426cabe/src/vs/editor/browser/controller/mouseHandler.ts#L305

This code ends up thinking that the user has clicked on an MouseTargetType.CONTENT_VIEW_ZONE element, which suppresses the mousedown event. This means our code action list never receives a click event

Can you provide some suggestions on how to fix this? I tried adding a new PartFingerprint.ContextView enum value but then realized the context view service can't use PartFingerprint because it lives in base

malinthar commented 1 year ago

I could reproduce the same with Ballerina vscode extension as depicted below. code_actions_new

When I select an item from the context menu on a code lens it selects the public token as depicted above(triggers a mouseDown event). This prevents the selected item (code action) from executing. However, if I selected the same somewhere else (not on code lens) it does not trigger such a event and the code action executes fine.

alexdima commented 1 year ago

I see. The root problem is that we add a foreign dom node to the editor dom node via direct DOM APIs and that is unexpected to the mouse handling logic. The foreign dom nodes added to the editor have so far been added via API (content widgets, overlay widgets, etc.).