serdarciplak / BlazorMonaco

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

Is there any way to clear the CompletionList for a CompletionItemProvider? #116

Closed txlee22 closed 5 months ago

txlee22 commented 7 months ago

I need to load a new CompletionList based on data records that are being drilled into. How can I replace or update the CompletionList that's being used by the editor?

BlazorMonaco.Languages.Global.RegisterCompletionItemProvider does a great job at creating/appending to the CompletionList, but I can't seem to figure out how to remove CompletionItems from the Suggestions field. Every time I drill into a data record, the CompletionList is being added onto and there are a lot of duplicate Suggestions in addition to Suggestions based on a different data record.

txlee22 commented 7 months ago

Is it possible that the lack of Dispose in the Monaco.d.cs snippet below is what's preventing me from replacing the CompletionList?

public class CompletionList
{
    public List<CompletionItem> Suggestions { get; set; }
    public bool? Incomplete { get; set; }
    // TODO
    // dispose?(): void;
}
serdarciplak commented 5 months ago

Yeah, disposing the old registrations may fix the issue here, and I'll investigate what's the best way to implement it. But this is not how you should use this.

The RegisterCompletionItemProvider method does not add or set a list of items. It registers a new item provider and that item provider is called every time the completion list is shown. So, you should not register new item providers every time your item list changes. You should register a single item provider which returns the items in an internal list of yours. When you need to change the displayed items, you should just update your list. So, the next call to the item provider returns the updated list and the new list is displayed in the completion list.

txlee22 commented 5 months ago

Gotcha thanks for the response! I guess there's no ability then to be able to set a CompletionItemProvider and bind to a specific instance of StandaloneCodeEditor? In other words, you can't have more than one CompletionItemProvider.

To be honest, I have no idea if this was even a feature of Monaco Editor but it would've been useful for the application I'm working on right now.