private readonly CustomCompletionProvider customCompletionProvider = new CustomCompletionProvider();
private readonly EntityNameCompletionProvider entityNameCompletionProvider = new EntityNameCompletionProvider();
.
.
.
this.editor.DocumentTextChanged += (sender, e) =>
{
if (e.TextChange.Source == this.editor.ActiveView)
{
if (e.IsTypedWordStart)
{
// If no completion session is currently open, show a completion list
if (!this.editor.IntelliPrompt.Sessions.Contains(IntelliPromptSessionTypes.Completion))
{
this.editor.Document.Language.RegisterService<ICompletionProvider>(this.customCompletionProvider);
EditorCommands.RequestIntelliPromptCompletionSession.Execute(this.editor.ActiveView);
}
}
else
{
if (e.TypedText == "/")
{
this.editor.Document.Language.RegisterService<ICompletionProvider>(this.entityNameCompletionProvider);
EditorCommands.RequestIntelliPromptCompletionSession.Execute(this.editor.ActiveView);
}
}
}
};
public class EntityNameCompletionProvider : CompletionProviderBase
{
public override bool RequestSession(IEditorView view, bool canCommitWithoutPopup)
{
var completionSession = new CompletionSession
{
CanCommitWithoutPopup = canCommitWithoutPopup,
CanFilterUnmatchedItems = true,
MatchOptions = CompletionMatchOptions.UseAcronyms | CompletionMatchOptions.UseShorthand,
};
var highlightingStyleRegistry = view.HighlightingStyleRegistry;
completionSession.Items.Add(new CompletionItem("/BD_01", new CommonImageSourceProvider(CommonImageKind.Keyword), new CustomContentProvider(highlightingStyleRegistry, typeof(bool))));
completionSession.Items.Add(new CompletionItem("/BD_01/BaseMarker", new CommonImageSourceProvider(CommonImageKind.Keyword), new CustomContentProvider(highlightingStyleRegistry, typeof(byte))));
completionSession.Items.Add(new CompletionItem("/BD_01/ActionMarker", new CommonImageSourceProvider(CommonImageKind.Keyword), new CustomContentProvider(highlightingStyleRegistry, typeof(char))));
completionSession.Items.Add(new CompletionItem("/Ground", new CommonImageSourceProvider(CommonImageKind.Keyword), new CustomContentProvider(highlightingStyleRegistry, typeof(double))));
completionSession.Items.Add(new CompletionItem("/RJ_01", new CommonImageSourceProvider(CommonImageKind.Keyword), new CustomContentProvider(highlightingStyleRegistry, typeof(float))));
completionSession.Items.Add(new CompletionItem("/RJ_01/BaseMarker", new CommonImageSourceProvider(CommonImageKind.Keyword), new CustomContentProvider(highlightingStyleRegistry, typeof(int))));
completionSession.Items.Add(new CompletionItem("/RJ_01/ActionMarker", new CommonImageSourceProvider(CommonImageKind.Keyword), new CustomContentProvider(highlightingStyleRegistry, typeof(long))));
if (completionSession.Items.Count > 0)
{
// Ensure the caret is visible
view.Scroller.ScrollToCaret();
// Ensure the items are sorted and open the session
completionSession.SortItems();
completionSession.Open(view);
return true;
}
return false;
}
}
Environment
- Windows 10 Enterprise 20H2
- Visual studio 2019 16.11.16
- net48
- ActiproSoftware.Controls.WPF.SyntaxEditor 22.1.2 nuget
I'm working on example of auto completion, and the text of "CompletionItem" starts with a slash.
Enter "/" in Syntex Editor and select an item from the list to enter "//Value". (eg. "//BD_01", expect: "/BD_01")
Enter "/BD_01/ActionMarker", press Ctrl+Space, and select "/BD_01/ActionMarker", and enter "/BD_01//BD_01/ActionMarker". (expect: "/BD_01/ActionMarker")
How can Auto completion work properly when it is not "Word"?
[Modified 2 years ago]