예제 #1
0
        public IList <Location> FindDefs(int index, Document doc)
        {
            List <Location> result = new List <Location>();

            if (doc == null)
            {
                return(result);
            }
            var workspace = doc.Workspace;

            IParseTree ref_pt = Util.Find(index, doc);

            if (ref_pt == null)
            {
                return(result);
            }

            ParsingResults ref_pd = ParsingResultsFactory.Create(doc);

            if (ref_pd.ParseTree == null)
            {
                Compile(workspace);
            }

            ref_pd.Attributes.TryGetValue(ref_pt, out IList <Symtab.CombinedScopeSymbol> list_values);
            if (list_values == null)
            {
                return(result);
            }

            foreach (CombinedScopeSymbol value in list_values)
            {
                if (value == null)
                {
                    continue;
                }

                Symtab.ISymbol @ref = value as Symtab.ISymbol;
                if (@ref == null)
                {
                    continue;
                }

                List <Symtab.ISymbol> defs = @ref.resolve();
                if (defs == null)
                {
                    continue;
                }

                foreach (var def in defs)
                {
                    string def_file = def.file;
                    if (def_file == null)
                    {
                        continue;
                    }

                    Document def_item = workspace.FindDocument(def_file);
                    if (def_item == null)
                    {
                        continue;
                    }

                    Location new_loc = new Location()
                    {
                        Range = new Workspaces.Range(def.Token.First().StartIndex, def.Token.First().StopIndex),
                        Uri   = def_item
                    };
                    result.Add(new_loc);
                }
            }
            return(result);
        }
예제 #2
0
        public IEnumerable <Location> FindRefsAndDefs(int index, Document doc)
        {
            List <Location> result = new List <Location>();
            IParseTree      ref_pt = Util.Find(index, doc);

            if (ref_pt == null)
            {
                return(result);
            }
            var workspace = doc.Workspace;

            ParsingResults ref_pd = ParsingResultsFactory.Create(doc);

            if (ref_pd.ParseTree == null)
            {
                Compile(workspace);
            }

            ref_pd.Attributes.TryGetValue(ref_pt, out IList <Symtab.CombinedScopeSymbol> list_value);
            if (list_value == null)
            {
                return(result);
            }

            List <Symtab.ISymbol> found_defs = null;

            Symtab.ISymbol found_ref = null;
            foreach (CombinedScopeSymbol value in list_value)
            {
                if (value == null)
                {
                    continue;
                }

                Symtab.ISymbol @ref = value as Symtab.ISymbol;
                if (@ref == null)
                {
                    continue;
                }

                if (@ref.Token == null)
                {
                    continue;
                }

                found_ref = @ref;
                List <Symtab.ISymbol> defs = @ref.resolve();
                if (defs == null)
                {
                    continue;
                }
                found_defs = defs;
                break;
            }
            if (found_defs != null)
            {
                foreach (var def in found_defs)
                {
                    result.Add(
                        new Location()
                    {
                        Range = new Workspaces.Range(def.Token.First().StartIndex, def.Token.First().StopIndex),
                        Uri   = workspace.FindDocument(def.file)
                    });
                    var dd = def as BaseSymbol;
                    foreach (var r in dd.Refs)
                    {
                        result.Add(
                            new Location()
                        {
                            Range = new Workspaces.Range(r.Token.First().StartIndex, r.Token.First().StopIndex),
                            Uri   = workspace.FindDocument(r.file)
                        });
                    }
                }
            }
            return(result);
        }
예제 #3
0
        public QuickInfo GetQuickInfo(int index, Document doc)
        {
            ParsingResults pd        = ParsingResultsFactory.Create(doc);
            var            workspace = doc.Workspace;

            if (pd.ParseTree == null)
            {
                Compile(workspace);
            }

            Antlr4.Runtime.Tree.IParseTree pt = LanguageServer.Util.Find(index, doc);
            var gd = ParserDescriptionFactory.Create(doc);

            if (pt == null)
            {
                return(null);
            }

            Antlr4.Runtime.Tree.IParseTree p = pt;
            pd.Attributes.TryGetValue(p, out IList <CombinedScopeSymbol> list_value);
            if (list_value == null)
            {
                return(null);
            }

            TerminalNodeImpl q     = p as Antlr4.Runtime.Tree.TerminalNodeImpl;
            Range            range = new Workspaces.Range(new Workspaces.Index(q.Symbol.StartIndex), new Workspaces.Index(q.Symbol.StopIndex + 1));
            bool             found = pd.PopupList.TryGetValue(q, out int tag_type);

            if (!found)
            {
                return(null);
            }

            if (list_value == null || list_value.Count == 0)
            {
                return(new QuickInfo()
                {
                    Display = gd.Map[tag_type], Range = range
                });
            }
            if (list_value.Count == 1)
            {
                CombinedScopeSymbol value = list_value.First();
                Symtab.ISymbol      name  = value as Symtab.ISymbol;
                string show = name?.Name;
                if (value is Symtab.Literal)
                {
                    show = ((Symtab.Literal)value).Cleaned;
                }
                if (gd.PopUpDefinition[tag_type] != null)
                {
                    Func <ParsingResults, IParseTree, string> fun = gd.PopUpDefinition[tag_type];
                    string mess = fun(pd, p);
                    if (mess != null)
                    {
                        return(new QuickInfo()
                        {
                            Display = mess, Range = range
                        });
                    }
                }
                string display = gd.Map[tag_type]
                                 + "\n"
                                 + show;
                return(new QuickInfo()
                {
                    Display = display, Range = range
                });
            }
            {
                string display = "Ambiguous -- ";
                foreach (CombinedScopeSymbol value in list_value)
                {
                    Symtab.ISymbol name = value as Symtab.ISymbol;
                    string         show = name?.Name;
                    if (value is Symtab.Literal)
                    {
                        show = ((Symtab.Literal)value).Cleaned;
                    }
                    if (gd.PopUpDefinition[tag_type] != null)
                    {
                        Func <ParsingResults, IParseTree, string> fun = gd.PopUpDefinition[tag_type];
                        string mess = fun(pd, p);
                        if (mess != null)
                        {
                            display = display + mess;
                        }
                    }
                    else
                    {
                        display = display + gd.Map[tag_type]
                                  + "\n"
                                  + show;
                    }
                }
                return(new QuickInfo()
                {
                    Display = display, Range = range
                });
            }
        }