serdarciplak / BlazorMonaco

Blazor component for Microsoft's Monaco Editor which powers Visual Studio Code.
https://serdarciplak.github.io/BlazorMonaco/
MIT License
441 stars 99 forks source link

Add overload for Trigger() replacing JsonElement as parameter #40

Closed HillPhelmuth closed 3 years ago

HillPhelmuth commented 3 years ago

I've created a custom c# code completion provider and created an action to trigger it manually. This requires using Monaco's editor.trigger function. However, the interop method makes this sort of awkward since JsonElement isn't really designed to be used outside of a JsonDocument. I've made this work by directly invoking your blazorMonaco.editor.trigger javascript function.

private async Task Suggest() => await Js.InvokeVoidAsync("blazorMonaco.editor.trigger", _editor.Id, "whatever...", "editor.action.triggerSuggest", "whatever...");

While this isn't particularly burdensome, I think it would be good to offer an overload of the Trigger method that takes a string or object instead of a JsonElement for the payload, particularly since the payload doesn't require a meaningful value for many of Monaco's triggered functions.

If you agree, I'd be happy to submit a pull-request to this effect.

serdarciplak commented 3 years ago

Hi @HillPhelmuth Thanks a lot for pointing this out. As you've said, it's not convenient to create a useless JsonElement instance. So, I've changed this parameter to an Object which can be of anytype and nullable. This change is now available in v2.1.0