Esempio n. 1
0
        void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            List <string> strList = new List <string>();

            if (NSPackage.nimsuggest == null)
            {
                return;
            }

            var caretpos = NSLangServ.CaretPosGet();

            NSPackage.nimsuggest.Query(NimSuggestProc.Qtype.sug, caretpos["line"], caretpos["col"]);
            m_compList = new List <Completion>();

            foreach (string skey in NSPackage.nimsuggest.sugdct.Keys)
            {
                var    sugdct   = NSPackage.nimsuggest.sugdct[skey];
                string procname = skey;
                int    per_spot = skey.IndexOf(".");
                if (per_spot != -1)
                {
                    procname = skey.Substring(per_spot + 1, skey.Length - per_spot - 1);
                }
                else
                {
                    procname = skey;
                }
                if (m_glyphdct.ContainsKey(sugdct["type"]))
                {
                    m_compList.Add(new Completion(skey, procname, sugdct["type"] + sugdct["help"], m_glyphdct[sugdct["type"]], "icon text"));
                }
                else
                {
                    m_compList.Add(new Completion(skey, procname, sugdct["type"] + sugdct["help"], null, "icon text"));
                }
            }

            SnapshotPoint           currentPoint = (session.TextView.Caret.Position.BufferPosition) - 1;
            ITextStructureNavigator navigator    = m_sourceProvider.NavigatorService.GetTextStructureNavigator(m_textBuffer);
            TextExtent extent     = navigator.GetExtentOfWord(currentPoint);
            string     w1         = currentPoint.Snapshot.GetText(extent.Span);
            var        startpoint = session.GetTriggerPoint(session.TextView.TextBuffer).GetPosition(currentPoint.Snapshot);

            ITrackingSpan applicableTo;

            if (w1 == ".")
            {
                applicableTo = currentPoint.Snapshot.CreateTrackingSpan(startpoint, 0, SpanTrackingMode.EdgeInclusive);
            }
            else
            {
                applicableTo = currentPoint.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive);
            }


            //var applicableTo = m_textBuffer.CurrentSnapshot.CreateTrackingSpan(session.GetTriggerPoint(session.TextView.TextBuffer).GetPosition(currentPoint.Snapshot), 0, SpanTrackingMode.EdgeInclusive);

            //completionSets.Add(new CompletionSet("Tokens", "Tokens", applicableTo, m_compList, null));
            completionSets.Add(new CompletionSet("Tokens", "Tokens", applicableTo, m_compList, null));
            //completionSets.Add(new CompletionSet(m_compList));

            //completionSets.Add(new CompletionSet("Tokens", "Tokens", FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer), session), m_compList, null));
        }
Esempio n. 2
0
        public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures)
        {
            //if (!session.TextView.Properties.ContainsProperty(SessionKey)) {
            //    return;
            //}
            NSUtil.DebugPrintAlways("NSSig - AugmentSignatureHelpSession");

            if (NSPackage.nimsuggest == null)
            {
                return;
            }

            signatures.Clear();
            var caretpos = NSLangServ.CaretPosGet();

            NSPackage.nimsuggest.Query(NimSuggestProc.Qtype.con, caretpos["line"], caretpos["col"]);

            SnapshotPoint?point_trigger = session.GetTriggerPoint(subjectBuffer.CurrentSnapshot);

            if (!point_trigger.HasValue)
            {
                return;
            }

            //ITextSnapshot snapshot = subjectBuffer.CurrentSnapshot;
            //int position = session.GetTriggerPoint(subjectBuffer).GetPosition(subjectBuffer.CurrentSnapshot);
            int position = point_trigger.Value.Position;

            string text = subjectBuffer.CurrentSnapshot.GetText();

            SnapshotPoint point_curr = session.GetTriggerPoint(subjectBuffer).GetPoint(subjectBuffer.CurrentSnapshot);

            point_curr = point_trigger.Value;
            SnapshotPoint point_left  = point_curr;
            SnapshotPoint point_right = point_curr;

            ITextSnapshotLine line  = point_left.GetContainingLine();
            string            terms = "\n\r\t.:()[]{}?/+-;=*!<>";

            while (true)
            {
                point_left -= 1;
                if (point_left <= line.Start)
                {
                    point_left = line.Start;
                    break;
                }
                if (terms.IndexOf(point_left.GetChar()) != -1)
                {
                    point_left += 1;
                    break;
                }
            }
            while (true)
            {
                if (point_right >= line.End)
                {
                    point_right = line.End;
                    break;
                }
                if (terms.IndexOf(point_right.GetChar()) != -1)
                {
                    point_right -= 1;
                    break;
                }
                point_right += 1;
            }
            if (point_left > point_right)
            {
                point_right = point_left;
            }
            ITrackingSpan applicable_to_span = subjectBuffer.CurrentSnapshot.CreateTrackingSpan(point_left, point_right - point_left, SpanTrackingMode.EdgeInclusive);
            //ITrackingSpan applicableToSpan = subjectBuffer.CurrentSnapshot.CreateTrackingSpan(new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0);

            string sig_help_default = "";

            foreach (string skey in NSPackage.nimsuggest.sugdct.Keys)
            {
                var sigdct = NSPackage.nimsuggest.sugdct[skey];
                if (sigdct["help"].Length > sig_help_default.Length)
                {
                    sig_help_default = sigdct["help"];
                }
            }

            foreach (string skey in NSPackage.nimsuggest.sugdct.Keys)
            {
                var sigdct = NSPackage.nimsuggest.sugdct[skey];
                //SortedDictionary<string,string>
                signatures.Add(SigAdd(subjectBuffer, skey, sigdct, sig_help_default, applicable_to_span, session));
            }

            //var currentSnapshot = subjectTriggerPoint.Value.Snapshot;
            //var querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0);
            //var applicableToSpan = currentSnapshot.CreateTrackingSpan(querySpan.Start.Position, 0, SpanTrackingMode.EdgeInclusive);

            //signatures.Add(CreateSignature(subjectBuffer, "add(int firstInt, int secondInt)", "Documentation for adding integers.", applicableToSpan));
            //signatures.Add(CreateSignature(subjectBuffer, "add(double firstDouble, double secondDouble)", "Documentation for adding doubles.", applicableToSpan));

            //string sighelp = "hey1";
            //if (sighelp != null) {
            //}
        }