icsharpcode / AvalonEdit

The WPF-based text editor component used in SharpDevelop
http://avalonedit.net/
MIT License
1.86k stars 470 forks source link

The code completion effiencency can be improved #407

Open xiaoxstz opened 1 year ago

xiaoxstz commented 1 year ago

In the project ICSharpCode.AvalonEdit.Sample, the code about code completion is shown below.

void textEditor_TextArea_TextEntered(object sender, TextCompositionEventArgs e)
{
    if (e.Text == ".") {
        // open code completion after the user has pressed dot:
        completionWindow = new CompletionWindow(textEditor.TextArea);
        // provide AvalonEdit with the data:
        IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
        data.Add(new MyCompletionData("Item1"));
        data.Add(new MyCompletionData("Item2"));
        data.Add(new MyCompletionData("Item3"));
        data.Add(new MyCompletionData("Another item"));
        completionWindow.Show();
        completionWindow.Closed += delegate {
            completionWindow = null;
        };
    }
}

Every time before the completion window is used, it needs to be created. It wastes much computing force, especially when the CompletionData is large

So, I think there are two approaches below to improve.

  1. Create the completion window only one time. When it's needed, activated it.
  2. CompletionWindow.CompletionList.CompletionData should be writable for users. In this way, we can create the data only once. Every time the completion window is needed, we can pass the data to CompletionData.