Esempio n. 1
0
        /// <summary>
        /// Finds all symbols in a script
        /// </summary>
        /// <param name="scriptAst">The abstract syntax tree of the given script</param>
        /// <param name="powerShellVersion">The PowerShell version the Ast was generated from</param>
        /// <returns>A collection of SymbolReference objects</returns>
        static public IEnumerable <SymbolReference> FindSymbolsInDocument(Ast scriptAst, Version powerShellVersion)
        {
            IEnumerable <SymbolReference> symbolReferences = null;

            // TODO: Restore this when we figure out how to support multiple
            //       PS versions in the new PSES-as-a-module world (issue #276)
//            if (powerShellVersion >= new Version(5,0))
//            {
//#if PowerShellv5
//                FindSymbolsVisitor2 findSymbolsVisitor = new FindSymbolsVisitor2();
//                scriptAst.Visit(findSymbolsVisitor);
//                symbolReferences = findSymbolsVisitor.SymbolReferences;
//#endif
//            }
//            else
            {
                if (IsPowerShellDataFileAst(scriptAst))
                {
                    var findHashtableSymbolsVisitor = new FindHashtableSymbolsVisitor();
                    scriptAst.Visit(findHashtableSymbolsVisitor);
                    symbolReferences = findHashtableSymbolsVisitor.SymbolReferences;
                }
                else
                {
                    FindSymbolsVisitor findSymbolsVisitor = new FindSymbolsVisitor();
                    scriptAst.Visit(findSymbolsVisitor);
                    symbolReferences = findSymbolsVisitor.SymbolReferences;
                }
            }

            return(symbolReferences);
        }
        protected override IEnumerable <SymbolReference> GetSymbolsImpl(ScriptFile scriptFile, Version psVersion)
        {
            var findHashtableSymbolsVisitor = new FindHashtableSymbolsVisitor();

            scriptFile.ScriptAst.Visit(findHashtableSymbolsVisitor);
            return(findHashtableSymbolsVisitor.SymbolReferences);
        }