private CodeCompletionSettings GetCodeCompletionSettingsForPosition(string source, int position, Configuration codeAssistanceConfiguration) { var parser = new Parser(); var parseResult = parser.Parse(source); var filter = GetFilterSegment(parseResult.Tokens, position); var settings = new CodeCompletionSettings { CompletionData = GetCodeCompletionForExpression(parseResult.Tree.FindExpressionAt(position), codeAssistanceConfiguration, source.Substring(filter.Offset, filter.Length)), IdentifierSegment = filter }; return settings; }
/// <summary> /// Shows completion window for passed functions. /// </summary> public void ShowCompletionWindow(CodeCompletionSettings settings) { if (settings.CompletionData == null || !settings.CompletionData.Any()) return; _completionWindow = new CompletionWindow(textEditor.TextArea); ICompletionData first = null; foreach (var item in settings.CompletionData) { if (first == null) first = item; _completionWindow.CompletionList.CompletionData.Add(item); } _completionWindow.StartOffset = settings.IdentifierSegment.Offset; _completionWindow.EndOffset = settings.IdentifierSegment.EndOffset; if (first != null) { _completionWindow.CompletionList.SelectedItem = first; } _completionWindow.Show(); _completionWindow.Closed += (sender, args) => _completionWindow = null; _completionWindow.PreviewTextInput += (sender, args) => { if (args.Text == "(" || args.Text == " ") { _completionWindow.CompletionList.RequestInsertion(EventArgs.Empty); } var c = args.Text[args.Text.Length - 1]; args.Handled = !char.IsLetterOrDigit(c) && c != '_'; }; }