icsharpcode/AvalonEdit

The code completion effiencency can be improved

Opened this issue · 0 comments

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.