Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }