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

            SnapshotPoint point = session.GetTriggerPoint(m_textBuffer).GetPoint(m_textBuffer.CurrentSnapshot);

            if (nodeprovider.isComment(point))
            {
                return;
            }

            Node node = nodeprovider.GetMostSpecificNode(point);

            List <Completion> m_compList = null;

            if (node != null && node.astnode is ScopedNode)
            {
                var terms = ((ScopedNode)node.astnode).ExpectedTerms.Where(term => term.FlagIsSet(Irony.Parsing.TermFlags.IsKeyword) || term.FlagIsSet(Irony.Parsing.TermFlags.IsPunctuation));
                if (terms.Count() > 0)
                {
                    foreach (var term in terms)
                    {
                        if (!strList.Contains(term.Name))
                        {
                            strList.Add(term.Name);
                        }
                    }
                }
                else
                {
                    foreach (var term in UOSL.Service.UOSLBase.Keywords)
                    {
                        if (!strList.Contains(term.Key))
                        {
                            strList.Add(term.Key);
                        }
                    }
                }

                if (strList.Count > 0)
                {
                    foreach (string str in strList)
                    {
                        (m_compList ?? (m_compList = new List <Completion>())).Add(new Completion(str, str, str, null, null));
                    }

                    strList.Clear();
                }
            }


            if (node == null || node.astnode.AsString == "Declarations" || node.astnode.AsString == "Script")
            {
                int pos = point.Position;
                // move to beginning of previous word
                while ((pos >= point.Snapshot.Length || char.IsWhiteSpace(point.Snapshot[pos])) && pos >= 0)
                {
                    pos--;
                }
                int end = pos;
                while (!char.IsWhiteSpace(point.Snapshot[pos]) && pos >= 0)
                {
                    pos--;
                }
                string keyword = pos > 0 && pos < end?point.Snapshot.GetText(pos + 1, end - pos) : null;

                if (keyword == "trigger" && m_trigsNames != null)
                {
                    completionSets.Add(new CompletionSet(
                                           "Triggers", //the non-localized title of the tab
                                           "Triggers", //the display title of the tab
                                           FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer),
                                                                   session),
                                           m_trigsNames,
                                           null));
                }
                else if (m_types != null && keyword == "function" || keyword == "member" || keyword == "forward")
                {
                    completionSets.Add(new CompletionSet(
                                           "Types", //the non-localized title of the tab
                                           "Types", //the display title of the tab
                                           FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer),
                                                                   session),
                                           m_types,
                                           null));
                }
                else if (m_trigsFull != null)
                {
                    if (m_compList != null)
                    {
                        completionSets.Add(new CompletionSet(
                                               "Keywords", //the non-localized title of the tab
                                               "Keywords", //the display title of the tab
                                               FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer),
                                                                       session),
                                               m_compList,
                                               null));
                    }

                    completionSets.Add(new CompletionSet(
                                           "Triggers", //the non-localized title of the tab
                                           "Triggers", //the display title of the tab
                                           FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer),
                                                                   session),
                                           m_trigsFull,
                                           null));
                }
                else if (m_compList != null)
                {
                    completionSets.Add(new CompletionSet(
                                           "Keywords", //the non-localized title of the tab
                                           "Keywords", //the display title of the tab
                                           FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer),
                                                                   session),
                                           m_compList,
                                           null));
                }
            }
            else
            {
                if (m_compList != null)
                {
                    completionSets.Add(new CompletionSet(
                                           "Keywords", //the non-localized title of the tab
                                           "Keywords", //the display title of the tab
                                           FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer),
                                                                   session),
                                           m_compList,
                                           null));
                }

                ScopedNode snode = node.astnode as ScopedNode;
                if (snode.ScopeVars != null)
                {
                    foreach (var var in snode.ScopeVars)
                    {
                        strList.Add(var.Name);
                    }

                    if (strList.Count > 0)
                    {
                        strList.Sort();

                        m_compList = new List <Completion>();
                        foreach (string str in strList)
                        {
                            m_compList.Add(new Completion(str, str, str, null, null));
                        }

                        completionSets.Add(new CompletionSet(
                                               "Vars", //the non-localized title of the tab
                                               "Vars", //the display title of the tab
                                               FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer),
                                                                       session),
                                               m_compList,
                                               null));

                        strList.Clear();
                    }
                }

                if (nodeprovider.Funcs != null)
                {
                    foreach (var func in nodeprovider.Funcs)
                    {
                        if (!strList.Contains(func.Name))
                        {
                            strList.Add(func.Name);
                        }
                    }

                    if (strList.Count > 0)
                    {
                        strList.Sort();

                        m_compList = new List <Completion>();
                        foreach (string str in strList)
                        {
                            m_compList.Add(new Completion(str, str, str, null, null));
                        }

                        completionSets.Add(new CompletionSet(
                                               "Funcs", //the non-localized title of the tab
                                               "Funcs", //the display title of the tab
                                               FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer),
                                                                       session),
                                               m_compList,
                                               null));
                    }

                    strList.Clear();
                }

                if (m_core != null)
                {
                    completionSets.Add(new CompletionSet(
                                           "Core", //the non-localized title of the tab
                                           "Core", //the display title of the tab
                                           FindTokenSpanAtPosition(session.GetTriggerPoint(m_textBuffer),
                                                                   session),
                                           m_core,
                                           null));
                }
            }
        }