private ITrackingSpan FindTokenSpanAtPosition(ICompletionSession session) { SnapshotPoint currentPoint = session.TextView.Caret.Position.BufferPosition - 1; TextExtent extent = _textStructureNavigator.GetExtentOfWord(currentPoint); var prev = _textStructureNavigator.GetSpanOfPreviousSibling(extent.Span); if (prev != null && !prev.Contains(extent.Span)) { string text = prev.GetText(); if (!string.IsNullOrEmpty(text) && text.Last() != '%' && !char.IsLetter(text[0])) { return(null); } if (text.First() != '%' && CmdLanguage.Keywords.ContainsKey(text.ToLowerInvariant())) { text = text.ToLowerInvariant(); if (text != "if" && text != "not") { return(null); } } } return(currentPoint.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive)); }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> qiContent, out ITrackingSpan applicableToSpan) { // Map the trigger point down to our buffer. SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(_mSubjectBuffer.CurrentSnapshot); if (!subjectTriggerPoint.HasValue) { applicableToSpan = null; return; } ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot; //look for occurrences of our QuickInfo words in the span ITextStructureNavigator navigator = _mProvider.NavigatorService.GetTextStructureNavigator(_mSubjectBuffer); TextExtent extent = navigator.GetExtentOfWord(subjectTriggerPoint.Value); if (extent.IsSignificant) { var tt1 = navigator.GetSpanOfNextSibling(extent.Span); var tt2 = navigator.GetSpanOfFirstChild(extent.Span); var tt3 = navigator.GetSpanOfPreviousSibling(extent.Span); var tt4 = navigator.GetSpanOfEnclosing(extent.Span); var t1 = tt1.GetText(); var t2 = tt2.GetText(); var t3 = tt3.GetText(); } string searchText = extent.Span.GetText(); foreach (string key in _mDictionary.Keys) { int foundIndex = searchText.IndexOf(key, StringComparison.CurrentCultureIgnoreCase); if (foundIndex > -1) { applicableToSpan = currentSnapshot.CreateTrackingSpan ( //querySpan.Start.Add(foundIndex).Position, 9, SpanTrackingMode.EdgeInclusive extent.Span.Start + foundIndex, key.Length, SpanTrackingMode.EdgeInclusive ); string value; _mDictionary.TryGetValue(key, out value); qiContent.Add(value ?? ""); return; } } applicableToSpan = null; }
public static int?GetSubwordBoundary(this ITextStructureNavigator navigator, SnapshotPoint point, bool forward) { var wordSpan = navigator.GetExtentOfWord(point).Span; wordSpan = new SnapshotSpan(navigator.GetSpanOfPreviousSibling(wordSpan).Start, navigator.GetSpanOfNextSibling(wordSpan).End); if (wordSpan.Length == 0) { return(null); } int step = forward ? 1 : -1; SnapshotSpan wordSpanPrev; do { var word = wordSpan.GetText(); int i = point.Position - wordSpan.Start; while (0 < i && i < word.Length) { if (IsSubwordBoundary(word, i, forward)) { return(wordSpan.Start + i); } i += step; } point = wordSpan.Start + i; wordSpanPrev = wordSpan; wordSpan = navigator.GetSpanOfEnclosing(wordSpan); } while (wordSpan != wordSpanPrev); return(null); }
public SnapshotSpan GetSpanOfPreviousSibling(SnapshotSpan activeSpan) { return(_delegateNavigator.GetSpanOfPreviousSibling(activeSpan)); }
public SnapshotSpan GetSpanOfPreviousSibling(SnapshotSpan activeSpan) { return(_plainTextNavigator.GetSpanOfPreviousSibling(activeSpan)); }
public SnapshotSpan GetSpanOfPreviousSibling(SnapshotSpan activeSpan) => xmlNavigator.GetSpanOfPreviousSibling(activeSpan);
void IQuickInfoSource.AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan) { // Map the trigger point down to our buffer. SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(m_subjectBuffer.CurrentSnapshot); if (!subjectTriggerPoint.HasValue) { applicableToSpan = null; return; } ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot; SnapshotSpan querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0); //look for occurrences of our QuickInfo words in the span ITextStructureNavigator navigator = m_provider.NavigatorService.GetTextStructureNavigator(m_subjectBuffer); TextExtent extent = navigator.GetExtentOfWord(subjectTriggerPoint.Value); string searchText = extent.Span.GetText(); if (searchText.Length < 2)//一般都是一个符号 { applicableToSpan = null; return; } SnapshotSpan ssPrevious = navigator.GetSpanOfPreviousSibling(extent.Span); SnapshotSpan ssEnclosing = navigator.GetSpanOfEnclosing(extent.Span); string strPreText = ssPrevious.GetText(); string strEnclosing = ssEnclosing.GetText(); string desText, strCtrlName; if (strPreText == "<" || strPreText == "</" || strEnclosing.StartsWith("</"))//控件名 { SouiData.GetInstance().GetKeyInf(searchText, out desText, currentSnapshot, out applicableToSpan, querySpan); if (desText != null) { quickInfoContent.Add(desText); } else { applicableToSpan = null; } return; } else if (strPreText == "=\"")//属性值 { applicableToSpan = null; return; } //属性名 else if (strEnclosing.StartsWith("<")) { strCtrlName = navigator.GetExtentOfWord(ssEnclosing.Start + 1).Span.GetText(); if (strCtrlName == null || strCtrlName.Length == 0) { applicableToSpan = null; return; } SouiData.GetInstance().GetProInf(strCtrlName, searchText, out desText, currentSnapshot, out applicableToSpan, querySpan); if (desText != null) { quickInfoContent.Add(desText); return; } } else if (strPreText.StartsWith("<")) { strCtrlName = navigator.GetExtentOfWord(ssPrevious.Start + 1).Span.GetText(); if (strCtrlName == null || strCtrlName.Length == 0) { applicableToSpan = null; return; } SouiData.GetInstance().GetProInf(strCtrlName, searchText, out desText, currentSnapshot, out applicableToSpan, querySpan); if (desText != null) { quickInfoContent.Add(desText); return; } } strCtrlName = strPreText; while (ssPrevious.Start > 0) { if (strPreText == "<") { SouiData.GetInstance().GetProInf(strCtrlName, searchText, out desText, currentSnapshot, out applicableToSpan, querySpan); if (desText != null) { quickInfoContent.Add(desText); return; } break; } strCtrlName = strPreText; ssPrevious = navigator.GetExtentOfWord(ssPrevious.Start - 1).Span; strPreText = ssPrevious.GetText(); } applicableToSpan = null; }