-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
markdown.api.render does not work the first time when passed a TextDocument #80338
Comments
It seems like there are two possible solutions here:
Disclaimer: I have no idea how passing messages to extensions works. I may be completely off base here. |
@ChaosinaCan , Are you sending a PR for this or can I take this up ? |
I've done a bit of investigation into this. It seems that the documentation on executeCommand() is incorrect. If the command is not yet registered, then the arguments are serialized and sent by RPC, which strips all methods and type info from objects. Possible solutions:
/**
* Executes the command denoted by the given command identifier.
*
* * *Note 1:* When executing an editor command not all types are allowed to
* be passed as arguments. Allowed are the primitive types `string`, `boolean`,
* `number`, `undefined`, and `null`, as well as [`Position`](#Position), [`Range`](#Range), [`Uri`](#Uri) and [`Location`](#Location).
* * *Note 2:* When executing commands that have been contributed by other
* extensions, any JSON-serializable objects are additionally allowed.
* * *Note 3:* There are no restrictions when executing commands that have been
* contributed by your own extension.
If solution 1 is acceptable, I can submit a PR. If we want solution 2 or something similar to it, that is a job for someone else. |
IMHO solution 1 should be good , but it is @mjbvz 's call :) |
The first proposal sounds good to me, but please do a separate PR for the documentation change. Let me know if you have any questions about implementing this |
@jrieken's commit implements solution 2, which makes everything work like you'd expect given executeCommand()'s current documentation. Thanks! |
So no work required for this, correct? |
cf88c7f should resolve this with no further work needed. Previously when executing a command which is contributed by an unloaded extension, then arguments would be serialized and sent to a proxy object. The extension would then be loaded, and the command would be run given the deserialized arguments. The serialization discarded information from the arguments, so the command would fail. If I understand the fix correctly, instead of running the command with the deserialized arguments after loading the extension, it will now unwind back to where the arguments were serialized and directly execute the command with the original arguments (which is possible now that the extension is loaded), so the command succeeds. |
Thanks. Closing this then since it sounds like the issue has already been fixed by cf88c7f |
Issue Type: Bug
When I try to send a
TextDocument
to themarkdown.api.render
command, it always fails the first time it is called. If I send a string, it works as expected.In my extension, I have code which looks like this:
I insert the result into an HTML template and set it as a WebView's html. The first time I open my webview, I see a loading spinner when hovering my cursor over the view for a couple seconds (I assume the Markdown extension is loading in the background), but when it stops loading the webview is still blank. Sometimes VS Code even crashes instead. If it doesn't crash and I close and re-open my webview, I see the rendered markdown content as expected.
If I set a breakpoint on the executeCommand() line and then step over it, it jumps to c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\vs\workbench\services\extensions\node\file:__w\1\s\src\vs\workbench\services\extensions\common\rpcProtocol.ts line 319. I see the following locals:
this: d
e: Error: e.getText is not a function
i: undefined
If I change my code to pass the full text of the document...
...then everything works as expected.
I noticed that the documentation for
executeCommand()
indicates that only certain types are safe to pass, and thatTextDocument
is not one of them, but https://code.visualstudio.com/updates/v1_38#_markdownapirender indicates that the command accepts either a string or aTextDocument
. Since the command works properly once the extension is already loaded, maybe there is an issue with passing the document or keeping it alive while the extension is being loaded?VS Code version: Code 1.38.0 (3db7e09, 2019-09-03T21:49:13.459Z)
OS version: Windows_NT x64 6.1.7601
System Info
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
oop_rasterization: unavailable_off
protected_video_decode: unavailable_off
rasterization: unavailable_off
skia_deferred_display_list: disabled_off
skia_renderer: disabled_off
surface_synchronization: enabled_on
video_decode: unavailable_off
viz_display_compositor: disabled_off
webgl: enabled
webgl2: enabled
Extensions (39)
The text was updated successfully, but these errors were encountered: