public Task <SimpleExpansion> GetExpansionsAsync( string line, int caretIndex, CancellationToken token) { return(CommandExpansion.GetExpansionsAsync(line, caretIndex, token)); }
private async Task TriggerCompletionAsync() { if (CommandExpansion == null) { return; // Host CommandExpansion service not available } if (IsCompletionSessionActive) { _completionSession.Dismiss(); _completionSession = null; } string line = WpfConsole.InputLineText; int caretIndex = CaretPosition - WpfConsole.InputLineStart.Value; Debug.Assert(caretIndex >= 0); // Cancel tab expansion if it takes more than 'TabExpansionTimeout' secs (defaults to 3 secs) to get any results CancellationTokenSource ctSource = new CancellationTokenSource(TabExpansionTimeout * 1000); SimpleExpansion simpleExpansion = null; try { WpfConsole.Dispatcher.SetExecutingCommand(true); simpleExpansion = await CommandExpansion.GetExpansionsAsync(line, caretIndex, ctSource.Token); } catch (Exception x) { // Ignore exception from expansion, but write it to the activity log ExceptionHelper.WriteErrorToActivityLog(x); } finally { WpfConsole.Dispatcher.SetExecutingCommand(false); } if (simpleExpansion != null && simpleExpansion.Expansions != null) { IList <string> expansions = simpleExpansion.Expansions; if (expansions.Count == 1) // Shortcut for 1 TabExpansion candidate { ReplaceTabExpansion(simpleExpansion.Start, simpleExpansion.Length, expansions[0]); } else if (expansions.Count > 1) // Only start intellisense session for multiple expansion candidates { _completionSession = CompletionBroker.CreateCompletionSession( WpfTextView, WpfTextView.TextSnapshot.CreateTrackingPoint(CaretPosition.Position, PointTrackingMode.Positive), true); _completionSession.Properties.AddProperty("TabExpansion", simpleExpansion); _completionSession.Dismissed += CompletionSession_Dismissed; _completionSession.Start(); } } }
async Task <SimpleExpansion> TryGetExpansionsAsync( string line, int caretIndex, CancellationToken token) { try { return(await CommandExpansion.GetExpansionsAsync(line, caretIndex, token)); } catch (OperationCanceledException) { return(null); } catch (Exception ex) { LoggingService.LogError("GetExpansionsAsync error.", ex); return(null); } }