hawkerm / monaco-editor-uwp

A Windows Runtime Component wrapper around the web-based Monaco Editor.
MIT License
153 stars 36 forks source link

Support Multiple Models? #59

Open hawkerm opened 3 years ago

hawkerm commented 3 years ago

Monaco itself can support multiple models (though I don't know if I've done that before). Since we encapsulate the model within each instance of a control, I'm not sure if this is an issue.

However, some APIs in Monaco (like a WorkspaceTextEdit) require a reference to the model.uri field. This is a special URI type within Monaco which has validation on its type here: https://github.com/microsoft/vscode/blob/0f22f2d343e33b03e8033d1083513072f58ece21/src/vs/base/common/uri.ts#L100-L115

That is used to check before the Edit is applied here: https://github.com/microsoft/vscode/blob/0f22f2d343e33b03e8033d1083513072f58ece21/src/vs/editor/browser/services/bulkEditService.ts#L22-L43

Since this is a Monaco type that has more than just data, we can't get away with just serializing/deserializing it across the C#/JavaScript boundary like we have with most other types.

For now, I'm manually injecting it for each Edit if it's required grabbing the required value on the JavaScript side. I don't know if we need a special pattern to 'pretend' to do this behind the scenes in the future or if there's a better way we can deserialize on the JavaScript side to get back into Monaco based types... I'm not familiar enough with object serialization in JavaScript beyond parsing JSON blobs...

Leaving this here for long-term tracking in case other scenarios beyond the one needed for CodeActions arise.