Exemple #1
0
        internal AstPythonModule(string moduleName, IPythonInterpreter interpreter, PythonAst ast, string filePath, IEnumerable <string> parseErrors)
        {
            Name           = moduleName;
            _documentation = ast.Documentation;
            FilePath       = filePath;
            DocumentUri    = ProjectEntry.MakeDocumentUri(FilePath);
            Locations      = new[] { new LocationInfo(filePath, DocumentUri, 1, 1) };
            _interpreter   = interpreter;

            _properties   = new Dictionary <object, object>();
            _childModules = new List <string>();
            _members      = new Dictionary <string, IMember>();

            // Do not allow children of named modules
            if (!ModulePath.IsInitPyFile(FilePath))
            {
                _foundChildModules = true;
            }

            var walker = new AstAnalysisWalker(interpreter, ast, this, filePath, DocumentUri, _members, true, true);

            ast.Walk(walker);
            walker.Complete();

            ParseErrors = parseErrors?.ToArray();
        }
Exemple #2
0
        public override object GetIconHandle(bool open)
        {
            if (ItemNode.IsExcluded)
            {
                return(base.GetIconHandle(open));
            }

            for (HierarchyNode child = this.FirstChild; child != null; child = child.NextSibling)
            {
                if (ModulePath.IsInitPyFile(child.Url))
                {
                    if (_imageList == null)
                    {
#if DEV11_OR_LATER
                        _imageList = Utilities.GetImageList(Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.Resources.PythonPackageIcons.png"));
#else
                        _imageList = Utilities.GetImageList(Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.Resources.PythonPackageIcons.bmp"));
#endif
                    }

                    return(open ?
                           ((Bitmap)_imageList.Images[0]).GetHicon() :
                           ((Bitmap)_imageList.Images[1]).GetHicon());
                }
            }

            return(base.GetIconHandle(open));
        }
Exemple #3
0
        protected override ImageMoniker GetIconMoniker(bool open)
        {
            if (!ItemNode.IsExcluded && AllChildren.Any(n => ModulePath.IsInitPyFile(n.Url)))
            {
                return(open ? KnownMonikers.PackageFolderOpened : KnownMonikers.PackageFolderClosed);
            }

            return(base.GetIconMoniker(open));
        }
Exemple #4
0
        internal AstPythonModule(string moduleName, IPythonInterpreter interpreter, string documentation, string filePath, IEnumerable <string> parseErrors) :
            base(moduleName)
        {
            _documentation = documentation;
            FilePath       = filePath;
            DocumentUri    = ProjectEntry.MakeDocumentUri(FilePath);
            Locations      = new[] { new LocationInfo(filePath, DocumentUri, 1, 1) };
            _interpreter   = interpreter;

            // Do not allow children of named modules
            _foundChildModules = !ModulePath.IsInitPyFile(FilePath);
            ParseErrors        = parseErrors?.ToArray();
        }
Exemple #5
0
        internal void EnsureModuleVariables(PythonAnalyzer state) {
            var entry = ProjectEntry;

            _scope.SetModuleVariable("__builtins__", state.ClassInfos[BuiltinTypeId.Dict].Instance);
            _scope.SetModuleVariable("__file__", GetStr(state, entry.FilePath));
            _scope.SetModuleVariable("__name__", GetStr(state, Name));
            _scope.SetModuleVariable("__package__", GetStr(state, ParentPackage?.Name));
            if (state.LanguageVersion.Is3x()) {
                _scope.SetModuleVariable("__cached__", GetStr(state));
                if (ModulePath.IsInitPyFile(entry.FilePath)) {
                    _scope.SetModuleVariable("__path__", state.ClassInfos[BuiltinTypeId.List].Instance);
                }
                _scope.SetModuleVariable("__spec__", state.ClassInfos[BuiltinTypeId.Object].Instance);
            }
            ModuleDefinition.EnqueueDependents();

        }
Exemple #6
0
        internal AstPythonModule(string moduleName, IPythonInterpreter interpreter, PythonAst ast, string filePath)
        {
            Name          = moduleName;
            Documentation = ast.Documentation;
            FilePath      = filePath;
            Locations     = new[] { new LocationInfo(filePath, 1, 1) };
            _interpreter  = interpreter;

            _properties   = new Dictionary <object, object>();
            _childModules = new List <string>();
            _members      = new Dictionary <string, IMember>();

            // Do not allow children of named modules
            if (!ModulePath.IsInitPyFile(FilePath))
            {
                _foundChildModules = true;
            }

            var walker = new AstAnalysisWalker(interpreter, ast, this, filePath, _members, true, true);

            ast.Walk(walker);
        }