Exemple #1
0
        internal PythonAnalyzer(IPythonInterpreterFactory factory, IPythonInterpreter pythonInterpreter)
        {
            _interpreterFactory           = factory;
            _langVersion                  = factory.GetLanguageVersion();
            _disposeInterpreter           = pythonInterpreter == null;
            _interpreter                  = pythonInterpreter ?? factory.CreateInterpreter();
            _builtinName                  = _langVersion.Is3x() ? SharedDatabaseState.BuiltinName3x : SharedDatabaseState.BuiltinName2x;
            _modules                      = new ModuleTable(this, _interpreter);
            _modulesByFilename            = new ConcurrentDictionary <string, ModuleInfo>(StringComparer.OrdinalIgnoreCase);
            _modulesWithUnresolvedImports = new HashSet <ModuleInfo>();
            _itemCache                    = new Dictionary <object, AnalysisValue>();

            Limits = AnalysisLimits.GetDefaultLimits();

            _queue = new Deque <AnalysisUnit>();

            _defaultContext = _interpreter.CreateModuleContext();

            _evalUnit = new AnalysisUnit(null, null, new ModuleInfo("$global", new ProjectEntry(this, "$global", String.Empty, null), _defaultContext).Scope, true);
            AnalysisLog.NewUnit(_evalUnit);

            try {
                LoadInitialKnownTypes();
            } catch (Exception ex) {
                if (ex.IsCriticalException())
                {
                    throw;
                }
                // This will be rethrown in LoadKnownTypesAsync
                _loadKnownTypesException = ExceptionDispatchInfo.Capture(ex);
            }
        }
        internal PythonAnalyzer(IPythonInterpreterFactory factory, IPythonInterpreter pythonInterpreter, string builtinName)
        {
            _interpreterFactory           = factory;
            _langVersion                  = factory.GetLanguageVersion();
            _disposeInterpreter           = pythonInterpreter == null;
            _interpreter                  = pythonInterpreter ?? factory.CreateInterpreter();
            _builtinName                  = builtinName ?? (_langVersion.Is3x() ? SharedDatabaseState.BuiltinName3x : SharedDatabaseState.BuiltinName2x);
            _modules                      = new ModuleTable(this, _interpreter);
            _modulesByFilename            = new ConcurrentDictionary <string, ModuleInfo>(StringComparer.OrdinalIgnoreCase);
            _modulesWithUnresolvedImports = new HashSet <ModuleInfo>();
            _itemCache                    = new Dictionary <object, AnalysisValue>();

            try {
                using (var key = Registry.CurrentUser.OpenSubKey(AnalysisLimitsKey)) {
                    Limits = AnalysisLimits.LoadFromStorage(key);
                }
            } catch (SecurityException) {
                Limits = new AnalysisLimits();
            } catch (UnauthorizedAccessException) {
                Limits = new AnalysisLimits();
            } catch (IOException) {
                Limits = new AnalysisLimits();
            }

            _queue = new Deque <AnalysisUnit>();

            _defaultContext = _interpreter.CreateModuleContext();

            _evalUnit = new AnalysisUnit(null, null, new ModuleInfo("$global", new ProjectEntry(this, "$global", String.Empty, null), _defaultContext).Scope, true);
            AnalysisLog.NewUnit(_evalUnit);

            LoadInitialKnownTypes();
        }
Exemple #3
0
        public ProjectAnalyzer(IPythonInterpreter interpreter, IPythonInterpreterFactory factory, IErrorProviderFactory errorProvider, PythonProjectNode project = null)
        {
            _errorProvider = errorProvider;

            _queue         = new ParseQueue(this);
            _analysisQueue = new AnalysisQueue(this);

            _interpreterFactory = factory;
            _project            = project;

            _analysisState = new PythonAnalyzer(interpreter, factory.GetLanguageVersion());
            _projectFiles  = new Dictionary <string, IProjectEntry>(StringComparer.OrdinalIgnoreCase);

            if (PythonToolsPackage.Instance != null)
            {
                _errorList = (IVsErrorList)PythonToolsPackage.GetGlobalService(typeof(SVsErrorList));
            }
        }
        internal PythonAnalyzer(IPythonInterpreterFactory factory)
        {
            InterpreterFactory = factory;
            LanguageVersion    = factory.GetLanguageVersion();
            Interpreter        = factory.CreateInterpreter();
            _pathResolver      = new PathResolver(LanguageVersion);

            _builtinName      = BuiltinTypeId.Unknown.GetModuleName(LanguageVersion);
            Modules           = new ModuleTable(this, Interpreter);
            ModulesByFilename = new ConcurrentDictionary <string, ModuleInfo>(StringComparer.OrdinalIgnoreCase);

            Limits = AnalysisLimits.GetDefaultLimits();
            Queue  = new Deque <AnalysisUnit>();

            _defaultContext = Interpreter.CreateModuleContext();

            _evalUnit = new AnalysisUnit(null, null, new ModuleInfo("$global", new ProjectEntry(this, "$global", String.Empty, null, null), _defaultContext).Scope, true);
            AnalysisLog.NewUnit(_evalUnit);
        }
Exemple #5
0
        public InterpreterView(IPythonInterpreterFactory interpreter, string name, bool isDefault) {
            Interpreter = interpreter;
            Name = name;
            Identifier = _identifier = string.Format(
                CultureInfo.InvariantCulture,
                "{0};{1}",
                interpreter.Id,
                interpreter.GetLanguageVersion());

            var withDb = interpreter as IInterpreterWithCompletionDatabase;
            if (withDb != null) {
                CanRefresh = true;
                withDb.IsCurrentChanged += Interpreter_IsCurrentChanged;
                IsCurrent = withDb.IsCurrent;
                IsCurrentReason = withDb.GetIsCurrentReason(CultureInfo.CurrentUICulture);
            }
            IsRunning = false;
            IsDefault = isDefault;
        }
Exemple #6
0
        internal PythonAnalyzer(IPythonInterpreterFactory factory, IPythonInterpreter pythonInterpreter)
        {
            _interpreterFactory           = factory;
            _langVersion                  = factory.GetLanguageVersion();
            _disposeInterpreter           = pythonInterpreter == null;
            _interpreter                  = pythonInterpreter ?? factory.CreateInterpreter();
            _builtinName                  = BuiltinTypeId.Unknown.GetModuleName(_langVersion);
            _modules                      = new ModuleTable(this, _interpreter);
            _modulesByFilename            = new ConcurrentDictionary <string, ModuleInfo>(StringComparer.OrdinalIgnoreCase);
            _modulesWithUnresolvedImports = new HashSet <ModuleInfo>();
            _itemCache                    = new Dictionary <object, AnalysisValue>();

            Limits = AnalysisLimits.GetDefaultLimits();

            Queue = new Deque <AnalysisUnit>();

            _defaultContext = _interpreter.CreateModuleContext();

            _evalUnit = new AnalysisUnit(null, null, new ModuleInfo("$global", new ProjectEntry(this, "$global", String.Empty, null, null), _defaultContext).Scope, true);
            AnalysisLog.NewUnit(_evalUnit);
        }
Exemple #7
0
        public InterpreterView(IPythonInterpreterFactory interpreter, string name, bool isDefault)
        {
            Interpreter = interpreter;
            Name        = name;
            Identifier  = _identifier = string.Format(
                CultureInfo.InvariantCulture,
                "{0};{1}",
                interpreter.Id,
                interpreter.GetLanguageVersion());

            var withDb = interpreter as IInterpreterWithCompletionDatabase;

            if (withDb != null)
            {
                CanRefresh = true;
                withDb.IsCurrentChanged += Interpreter_IsCurrentChanged;
                IsCurrent       = withDb.IsCurrent;
                IsCurrentReason = withDb.GetIsCurrentReason(CultureInfo.CurrentUICulture);
            }
            IsRunning = false;
            IsDefault = isDefault;
        }
Exemple #8
0
 public PythonAnalyzer(IPythonInterpreterFactory interpreterFactory)
     : this(interpreterFactory.CreateInterpreter(), interpreterFactory.GetLanguageVersion())
 {
 }