siku2 / rust-monaco

Rust WASM bindings for the Monaco Editor
Apache License 2.0
77 stars 25 forks source link

Creating `IMarkerData` instances #35

Closed ctron closed 1 year ago

ctron commented 1 year ago

I am trying to set markers. To my understanding I need to create an IMarkerData instance. However, I can't see any constructor method, like new.

ctron commented 1 year ago

I am running into the same issue with other types as well, like LanguageConfiguration and CommentRule, to name a few.

They seem to "extend" on Object, but not allow to create an empty/default instance.

Maybe you can point me into the right direction, I might be able to come up with a PR.

ctron commented 1 year ago

I think I found a workaround:

let comments: CommentRule = js_sys::Object::new().unchecked_into();
comments.set_line_comment(Some("//"));
siku2 commented 1 year ago

That's the correct way to do it, yes. I just added a convenience constructor for the various types I could think of. See: https://github.com/siku2/rust-monaco/blob/794a4cc7819f9ed7eb06559e24f75a41e23cf22a/src/sys/editor.rs#L28-L52

Also the reason there isn't just a blanket implementation for all types is that for some types the empty object isn't valid or there are other invariants to uphold.

ctron commented 1 year ago

I guess this can be closed now.