public override void SelectBestMatch() { var text = FilterSpan.GetText(FilterSpan.TextBuffer.CurrentSnapshot); if (text.Length == 0) { SelectionStatus = new CompletionSelectionStatus(null, false, false); return; } var num = int.MaxValue; Completion completion = null; foreach (var current in Completions) { var startIndex = current.DisplayText.StartsWith(InitialApplicableTo, StringComparison.OrdinalIgnoreCase) ? this.InitialApplicableTo.Length : 0; var num2 = current.DisplayText.IndexOf(text, startIndex, StringComparison.OrdinalIgnoreCase); if (num2 != -1 && num2 < num) { completion = current; num = num2; } } if (completion == null) { SelectionStatus = new CompletionSelectionStatus(null, false, false); return; } SelectionStatus = new CompletionSelectionStatus(completion, true, true); }
private Span ComputeReplacementSpan(ITextBuffer subjectBuffer, ITextSnapshot snapshot) { var trackingSpan = snapshot.CreateTrackingSpan(FilterSpan.ToSpan(), SpanTrackingMode.EdgeInclusive); var currentSpan = trackingSpan.GetSpan(subjectBuffer.CurrentSnapshot); return(Span.FromBounds(subjectBuffer.CurrentSnapshot[currentSpan.Start - 1] == '<' && _beforeCaretText[0] == '<' ? currentSpan.Start - 1 : currentSpan.Start, currentSpan.End)); }
public override void Filter() { var filterText = FilterSpan.GetText(FilterSpan.TextBuffer.CurrentSnapshot); Predicate <Completion> predicate = delegate(Completion completion) { var startIndex = completion.DisplayText.StartsWith(InitialApplicableTo, StringComparison.OrdinalIgnoreCase) ? InitialApplicableTo.Length : 0; return(completion.DisplayText.IndexOf(filterText, startIndex, StringComparison.OrdinalIgnoreCase) != -1); }; if (Completions.Any(current => predicate(current))) { completions.Filter(predicate); } }
public override void SelectBestMatch() { var text = FilterSpan.GetText(FilterSpan.TextBuffer.CurrentSnapshot); if (text.Length == 0) { if (InitialApplicableTo.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { return; } foreach (var current in Completions) { if (current.InsertionText.StartsWith(InitialApplicableTo, StringComparison.OrdinalIgnoreCase)) { SelectionStatus = new CompletionSelectionStatus(current, true, true); return; } } return; } int num = int.MaxValue; int matchedCount = 0; Completion completion = null; foreach (var current in Completions) { string currentInsertionText = current.InsertionText; if (current.InsertionText.StartsWith("\"", StringComparison.OrdinalIgnoreCase) && current.InsertionText.EndsWith("\"", StringComparison.OrdinalIgnoreCase)) { currentInsertionText = currentInsertionText.Substring(1, currentInsertionText.Length - 2); } var startIndex = current.InsertionText.StartsWith(InitialApplicableTo, StringComparison.OrdinalIgnoreCase) ? this.InitialApplicableTo.Length : 0; var num2 = currentInsertionText.IndexOf(text, startIndex, StringComparison.OrdinalIgnoreCase); if (num2 != -1 && num2 < num) { completion = current; num = num2; ++matchedCount; } } if (completion == null) { SelectionStatus = new CompletionSelectionStatus(null, false, false); return; } bool isFullyMatched = completion.InsertionText.Equals(InitialApplicableTo + text, StringComparison.OrdinalIgnoreCase); var propertiesCollection = FilterSpan.TextBuffer.Properties; if (propertiesCollection.ContainsProperty(BufferProperties.SessionCompletionFullyMatchedStatus)) { propertiesCollection.RemoveProperty(BufferProperties.SessionCompletionFullyMatchedStatus); } propertiesCollection.AddProperty(BufferProperties.SessionCompletionFullyMatchedStatus, isFullyMatched); bool isSelected = (matchedCount > 0); bool isUnique = (matchedCount == 1); SelectionStatus = new CompletionSelectionStatus(completion, isSelected, isUnique); }