Beispiel #1
0
        void MergeNodes(CompletionNode existing, CompletionNode cn)
        {
            if (cn.children != null)
            {
                List <CompletionNode> nodes = new List <CompletionNode>();
                if (existing.children != null)
                {
                    nodes.AddRange(existing.children);
                }

                foreach (CompletionNode x in cn.children)
                {
                    CompletionNode oldn = FindChildNode(nodes, x.display);
                    if (oldn != null)
                    {
                        MergeNodes(oldn, x);
                    }
                    else
                    {
                        nodes.Add(x);
                    }
                }
                existing.children = nodes.ToArray();
            }
        }
Beispiel #2
0
 public void Reset(SquirrelVersion squirrelVersion)
 {
     this.squirrelVersion = squirrelVersion;
     nodes = new List <CompletionNode>();
     curr  = new CompletionNode();
     AddKeywords();
 }
Beispiel #3
0
        public override void GetParameterInfo(int index, int parameter, out string name, out string display, out string description)
        {
            CompletionNode cn = declarations[index];

            name        = "par" + parameter;
            display     = name;
            description = cn.parameters[parameter];
        }
Beispiel #4
0
        private void AddKeyword(string name)
        {
            CompletionNode cn = new CompletionNode();

            cn.name  = cn.display = name;
            cn.glyph = (int)GlyphImageIndex.Keyword;
            cn.type  = "keyword";
            nodes.Add(cn);
        }
Beispiel #5
0
        public void AddSource(Stream stm)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(stm);
            XmlNodeList    xnl = doc.GetElementsByTagName("symbols");
            XmlNode        n   = xnl[0];
            CompletionNode cn  = new CompletionNode();

            ParseNode(cn, n);

            if (cn.children != null)
            {
                foreach (CompletionNode x in cn.children)
                {
                    CompletionNode newn = FindChildNode(nodes, x.display);
                    if (newn != null)
                    {
                        MergeNodes(x, newn);
                    }
                    else
                    {
                        nodes.Add(x);
                    }
                }

                nodes.Sort(delegate(CompletionNode a, CompletionNode b)
                {
                    return(a.display.CompareTo(b.display));
                });
                curr.children = nodes.ToArray();
            }

            /*if(cn.children != null) {
             *  foreach (CompletionNode x in cn.children)
             *  {
             *      string name = x.display;
             *      int j = 0;
             *      foreach (CompletionNode cur in nodes)
             *      {
             *          if (cur.display == name)
             *          {
             *              nodes[j] = x;
             *              continue;
             *          }
             *          j++;
             *      }
             *      nodes.Add(x);
             *  }
             * }
             * nodes.Sort(delegate(CompletionNode a, CompletionNode b)
             * {
             *  return a.display.CompareTo(b.display);
             * });
             * curr.children = nodes.ToArray();*/
        }
Beispiel #6
0
        public override int GetParameterCount(int index)
        {
            CompletionNode cn = declarations[index];

            if (cn.parameters != null)
            {
                return(cn.parameters.Length);
            }
            return(0);
        }
Beispiel #7
0
        public override string GetDescription(int index)
        {
            CompletionNode cn = declarations[index];

            /*if (cn.signature != null)
             * {
             *  return cn.display + cn.signature;
             * }*/
            return(cn.display);
        }
Beispiel #8
0
        void ParseNode(CompletionNode parent, XmlNode n)
        {
            if (n.ChildNodes.Count == 0)
            {
                return;
            }
            List <CompletionNode> nodes = new List <CompletionNode>();

            foreach (XmlNode xn in n.ChildNodes)
            {
                if (xn.NodeType == XmlNodeType.Element &&
                    xn.Name == "symbol")
                {
                    XmlElement     e    = (XmlElement)xn;
                    CompletionNode cn   = new CompletionNode();
                    string         name = e.GetAttribute("name");
                    cn.name    = name.ToLower();
                    cn.display = name;
                    cn.type    = e.GetAttribute("type");
                    cn.glyph   = GetImage(cn.type);
                    if (cn.type == "function")
                    {
                        cn.signature = e.GetAttribute("signature");
                        if (cn.signature.StartsWith("(") &&
                            cn.signature.EndsWith(")"))
                        {
                            string trimmed = cn.signature.Substring(1, cn.signature.Length - 2);
                            if (trimmed.IndexOf(',') != -1)
                            {
                                cn.parameters = trimmed.Split(new char[] { ',' });
                            }
                        }
                    }
                    nodes.Add(cn);
                    ParseNode(cn, xn);
                }
            }
            if (nodes.Count > 0)
            {
                nodes.Sort(delegate(CompletionNode a, CompletionNode b)
                {
                    return(a.display.CompareTo(b.display));
                });
                parent.children = nodes.ToArray();
            }
        }
Beispiel #9
0
        public int GetCandidates(List <CompletionNode> ret, String[] syms, int part, bool exactmatch)
        {
            if (children == null)
            {
                return(0);
            }
            int    len   = children.Length;
            int    found = 0;
            String s     = syms[part];

            for (int n = 0; n < len; n++)
            {
                CompletionNode cn = (CompletionNode)children[n];
                if (cn.name.StartsWith(s))
                {
                    int temp = found;

                    if (cn.name.Equals(s))
                    {
                        if (part < syms.Length - 1)
                        {
                            found += cn.GetCandidates(ret, syms, part + 1, exactmatch);
                        }

                        /*else
                         * {
                         *  //force all childrens to be in
                         *  found += cn.GetCandidates(ret, empty, 0);
                         * }*/
                    }
                    //add the parent only if no children were added
                    if (temp == found && cn.name.Equals(s) == exactmatch)
                    {
                        found++;
                        ret.Add(cn);
                    }
                }
            }
            return(found);
        }