Ejemplo n.º 1
0
        void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            if (completionSets.Count != 0)
            {
                //                 completionSets.Clear();
                //                 session.Dismiss();
                //此处为XML激活的自动完成比如输入 <时
                return;
            }
            if (m_xmlType == XML_TYPE.Unknow)
            {
            }
            SnapshotPoint?currentPoint = session.GetTriggerPoint(m_textBuffer.CurrentSnapshot); // (session.TextView.Caret.Position.BufferPosition);

            if (!currentPoint.HasValue)
            {
                return;
            }
            ITextSnapshotLine       TextSnapshotLine = session.TextView.TextSnapshot.GetLineFromPosition(currentPoint.Value);
            ITextStructureNavigator navigator        = m_sourceProvider.NavigatorService.GetTextStructureNavigator(m_textBuffer);
            string        xmlText   = TextSnapshotLine.GetText();
            SnapshotPoint linestart = TextSnapshotLine.Start;

            xmlText = xmlText.Substring(0, currentPoint.Value - linestart.Position);
            //向前查找 <或>或者空格
            //string xmlText= m_textBuffer.CurrentSnapshot.GetText();
            int pos1 = xmlText.LastIndexOf("<");
            int pos2 = xmlText.LastIndexOf(" ");
            int pos3 = xmlText.LastIndexOf(">");
            int pos4 = xmlText.LastIndexOf("=");

            if (pos3 > pos1)
            {
                return;//标签已关闭
            }
            if (pos1 > pos2)
            {
                SouiData.GetInstance().GetMap(m_xmlType, out m_compList, SouiData.MAPTYPE.C, m_sourceProvider.GlyphService);
                var set = new CompletionSet(
                    "SOUI",
                    "SOUI",
                    FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer), session),
                    m_compList,
                    null);
                //                 if(completionSets.Count>0)
                //                 {
                //                     completionSets.Clear();
                //                 }
                completionSets.Add(set);
            }
            else if (pos4 > pos2)
            {
                string key = "";
                if (pos1 > pos3)
                {
                    if (xmlText[pos1 + 1] != '/')             //闭合节点
                    {
                        int pos = xmlText.IndexOf(" ", pos1); //<0123 56
                        ++pos1;
                        key = xmlText.Substring(pos1, pos - pos1);
                    }
                }
                //控件名
                if (key.Length != 0)
                {
                    //属性名
                    string pro = "";
                    xmlText.IndexOf(" ", pos1);//<0123 56
                    int pos = xmlText.LastIndexOf(" ", pos4);
                    ++pos;
                    pro = xmlText.Substring(pos, pos4 - pos);
                    if (pro.Length != 0)
                    {
                        SouiData.GetInstance().GetMap(m_xmlType, out m_compList, m_sourceProvider.GlyphService, key, pro);
                        var set = new CompletionSet(
                            "SOUI",
                            "SOUI",
                            FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer), session),
                            m_compList,
                            null);
                        if (completionSets.Count > 0)
                        {
                            completionSets.Clear();
                        }
                        completionSets.Add(set);
                    }
                }
            }
            else
            {
                string key = "";
                if (pos1 > pos3)
                {
                    if (xmlText[pos1 + 1] != '/')             //闭合节点
                    {
                        int pos = xmlText.IndexOf(" ", pos1); //<0123 56
                        ++pos1;
                        key = xmlText.Substring(pos1, pos - pos1);
                    }
                }
                if (key.Length != 0)
                {
                    SouiData.GetInstance().GetMap(m_xmlType, out m_compList, SouiData.MAPTYPE.P, m_sourceProvider.GlyphService, key);
                    var set = new CompletionSet(
                        "SOUI",
                        "SOUI",
                        FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer), session),
                        m_compList,
                        null);
                    if (completionSets.Count > 0)
                    {
                        completionSets.Clear();
                    }
                    completionSets.Add(set);
                }
            }
        }
Ejemplo n.º 2
0
        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;
        }