Beispiel #1
0
        internal TaskProviderItem FromUnresolvedImport(
            IServiceProvider serviceProvider,
            IPythonInterpreterFactoryWithDatabase factory,
            string importName,
            SourceSpan span
            )
        {
            string message;

            if (factory != null && !factory.IsCurrent)
            {
                message = Strings.UnresolvedModuleTooltipRefreshing.FormatUI(importName);
            }
            else
            {
                message = Strings.UnresolvedModuleTooltip.FormatUI(importName);
            }

            return(new TaskProviderItem(
                       serviceProvider,
                       message,
                       span,
                       VSTASKPRIORITY.TP_NORMAL,
                       VSTASKCATEGORY.CAT_BUILDCOMPILE,
                       true,
                       _snapshot
                       ));
        }
Beispiel #2
0
        internal EnvironmentView(
            IInterpreterOptionsService service,
            IInterpreterRegistryService registry,
            IPythonInterpreterFactory factory,
            Redirector redirector
            )
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            _service  = service;
            _registry = registry;
            Factory   = factory;

            _withDb = factory as IPythonInterpreterFactoryWithDatabase;
            if (_withDb != null)
            {
                _withDb.IsCurrentChanged += Factory_IsCurrentChanged;
                IsCheckingDatabase        = _withDb.IsCheckingDatabase;
                IsCurrent = _withDb.IsCurrent;
            }


            if (_service.IsConfigurable(factory.Configuration.Id))
            {
                IsConfigurable = true;
            }

            Description = Factory.Configuration.Description;
            IsDefault   = (_service != null && _service.DefaultInterpreter == Factory);

            PrefixPath             = Factory.Configuration.PrefixPath;
            InterpreterPath        = Factory.Configuration.InterpreterPath;
            WindowsInterpreterPath = Factory.Configuration.WindowsInterpreterPath;

            Extensions = new ObservableCollection <object>();
            Extensions.Add(new EnvironmentPathsExtensionProvider());
            if (IsConfigurable)
            {
                Extensions.Add(new ConfigurationExtensionProvider(_service));
            }

            CanBeDefault = Factory.CanBeDefault();

            Company    = _registry.GetProperty(Factory.Configuration.Id, CompanyKey) as string ?? "";
            SupportUrl = _registry.GetProperty(Factory.Configuration.Id, SupportUrlKey) as string ?? "";
        }
Beispiel #3
0
        /// <summary>
        /// Generates the completion database and returns a task that will
        /// complete when the database is regenerated.
        /// </summary>
        internal static Task <int> GenerateDatabaseAsync(
            this IPythonInterpreterFactoryWithDatabase factory,
            GenerateDatabaseOptions options
            )
        {
            var tcs = new TaskCompletionSource <int>();

            factory.GenerateDatabase(options, tcs.SetResult);
            return(tcs.Task);
        }
Beispiel #4
0
        internal EnvironmentView(
            IInterpreterOptionsService service,
            IPythonInterpreterFactory factory,
            Redirector redirector
            )
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            _service = service;
            Factory  = factory;

            _withDb = factory as IPythonInterpreterFactoryWithDatabase;
            if (_withDb != null)
            {
                _withDb.IsCurrentChanged += Factory_IsCurrentChanged;
                IsCheckingDatabase        = _withDb.IsCheckingDatabase;
                IsCurrent = _withDb.IsCurrent;
            }

            var configurableProvider = _service != null?
                                       _service.KnownProviders
                                       .OfType <ConfigurablePythonInterpreterFactoryProvider>()
                                       .FirstOrDefault() :
                                           null;

            if (configurableProvider != null && configurableProvider.IsConfigurable(factory))
            {
                IsConfigurable = true;
            }

            Description = Factory.Description;
            IsDefault   = (_service != null && _service.DefaultInterpreter == Factory);

            PrefixPath             = Factory.Configuration.PrefixPath;
            InterpreterPath        = Factory.Configuration.InterpreterPath;
            WindowsInterpreterPath = Factory.Configuration.WindowsInterpreterPath;
            LibraryPath            = Factory.Configuration.LibraryPath;

            Extensions = new ObservableCollection <object>();
            Extensions.Add(new EnvironmentPathsExtensionProvider());
            if (IsConfigurable)
            {
                Extensions.Add(new ConfigurationExtensionProvider(configurableProvider));
            }

            CanBeDefault = Factory.CanBeDefault();
        }
Beispiel #5
0
        public static IEnumerable <DBPackageView> FromModuleList(
            IList <string> modules,
            IList <string> stdLibModules,
            IPythonInterpreterFactoryWithDatabase factory
            )
        {
            var stdLib        = new HashSet <string>(stdLibModules, StringComparer.Ordinal);
            var stdLibPackage = new DBPackageView(Resources.StandardLibraryModuleListItem);

            yield return(stdLibPackage);

#if DEBUG
            var seenPackages = new HashSet <string>(StringComparer.Ordinal);
#endif

            HashSet <string> knownModules            = null;
            bool             areKnownModulesUpToDate = false;
            if (!factory.IsCurrent)
            {
                knownModules            = new HashSet <string>(factory.GetUpToDateModules(), StringComparer.Ordinal);
                areKnownModulesUpToDate = true;
            }
            for (int i = 0; i < modules.Count;)
            {
                if (stdLib.Contains(modules[i]))
                {
                    stdLibPackage._isUpToDate = knownModules == null ||
                                                knownModules.Contains(modules[i]) == areKnownModulesUpToDate;
                    stdLibPackage._moduleCount += 1;
                    i += 1;
                    continue;
                }

#if DEBUG
                Debug.Assert(seenPackages.Add(modules[i]));
#endif

                var package = new DBPackageView(modules[i]);
                package._isUpToDate = knownModules == null ||
                                      knownModules.Contains(modules[i]) == areKnownModulesUpToDate;
                package._moduleCount = 1;

                var dotName = package._fullname + ".";
                for (++i; i < modules.Count && modules[i].StartsWith(dotName, StringComparison.Ordinal); ++i)
                {
                    package._isUpToDate &= knownModules == null ||
                                           knownModules.Contains(modules[i]) == areKnownModulesUpToDate;
                    package._moduleCount += 1;
                }

                yield return(package);
            }
        }
Beispiel #6
0
        internal EnvironmentView(
            IInterpreterOptionsService service,
            IPythonInterpreterFactory factory,
            Redirector redirector
        ) {
            if (service == null) {
                throw new ArgumentNullException("service");
            }
            if (factory == null) {
                throw new ArgumentNullException("factory");
            }

            _service = service;
            Factory = factory;

            _withDb = factory as IPythonInterpreterFactoryWithDatabase;
            if (_withDb != null) {
                _withDb.IsCurrentChanged += Factory_IsCurrentChanged;
                IsCheckingDatabase = _withDb.IsCheckingDatabase;
                IsCurrent = _withDb.IsCurrent;
            }

            var configurableProvider = _service != null ?
                _service.KnownProviders
                    .OfType<ConfigurablePythonInterpreterFactoryProvider>()
                    .FirstOrDefault() :
                null;

            if (configurableProvider != null && configurableProvider.IsConfigurable(factory)) {
                IsConfigurable = true;
            }

            Description = Factory.Description;
            IsDefault = (_service != null && _service.DefaultInterpreter == Factory);

            PrefixPath = Factory.Configuration.PrefixPath;
            InterpreterPath = Factory.Configuration.InterpreterPath;
            WindowsInterpreterPath = Factory.Configuration.WindowsInterpreterPath;
            LibraryPath = Factory.Configuration.LibraryPath;

            Extensions = new ObservableCollection<object>();
            Extensions.Add(new EnvironmentPathsExtensionProvider());
            if (IsConfigurable) {
                Extensions.Add(new ConfigurationExtensionProvider(configurableProvider));
            }

            CanBeDefault = Factory.CanBeDefault();
        }
Beispiel #7
0
        internal EnvironmentView(
            IInterpreterOptionsService service,
            IInterpreterRegistryService registry,
            IPythonInterpreterFactory factory,
            Redirector redirector
        ) {
            if (service == null) {
                throw new ArgumentNullException(nameof(service));
            }
            if (registry == null) {
                throw new ArgumentNullException(nameof(registry));
            }
            if (factory == null) {
                throw new ArgumentNullException(nameof(factory));
            }
            if (factory.Configuration == null) {
                throw new ArgumentException("factory must include a configuration");
            }

            _service = service;
            _registry = registry;
            Factory = factory;
            Configuration = Factory.Configuration;

            _withDb = factory as IPythonInterpreterFactoryWithDatabase;
            if (_withDb != null) {
                _withDb.IsCurrentChanged += Factory_IsCurrentChanged;
                IsCheckingDatabase = _withDb.IsCheckingDatabase;
                IsCurrent = _withDb.IsCurrent;
            }
            

            if (_service.IsConfigurable(Factory.Configuration.Id)) {
                IsConfigurable = true;
            }

            Description = Factory.Configuration.Description;
            IsDefault = (_service != null && _service.DefaultInterpreterId == Configuration.Id);

            PrefixPath = Factory.Configuration.PrefixPath;
            InterpreterPath = Factory.Configuration.InterpreterPath;
            WindowsInterpreterPath = Factory.Configuration.WindowsInterpreterPath;

            Extensions = new ObservableCollection<object>();
            Extensions.Add(new EnvironmentPathsExtensionProvider());
            if (IsConfigurable) {
                Extensions.Add(new ConfigurationExtensionProvider(_service, alwaysCreateNew: false));
            }

            CanBeDefault = Factory.CanBeDefault();

            Company = _registry.GetProperty(Factory.Configuration.Id, CompanyKey) as string ?? "";
            SupportUrl = _registry.GetProperty(Factory.Configuration.Id, SupportUrlKey) as string ?? "";
        }
Beispiel #8
0
        public static IEnumerable <DBPackageView> FromModuleList(
            IList <string> modules,
            IList <string> stdLibModules,
            IPythonInterpreterFactoryWithDatabase factory
            )
        {
            var stdLib        = new HashSet <string>(stdLibModules, StringComparer.Ordinal);
            var stdLibPackage = new DBPackageView("(Standard Library)");

            yield return(stdLibPackage);

#if DEBUG
            var seenPackages = new HashSet <string>(StringComparer.Ordinal);
#endif

            HashSet <string> knownModules            = null;
            bool             areKnownModulesUpToDate = false;
            if (!factory.IsCurrent)
            {
                var factory2 = factory as IPythonInterpreterFactoryWithDatabase2;
                if (factory2 == null)
                {
                    knownModules = new HashSet <string>(Regex.Matches(
                                                            factory.GetIsCurrentReason(CultureInfo.InvariantCulture),
                                                            @"\b[\w\d\.]+\b"
                                                            ).Cast <Match>().Select(m => m.Value),
                                                        StringComparer.Ordinal
                                                        );
                    areKnownModulesUpToDate = false;
                }
                else
                {
                    knownModules            = new HashSet <string>(factory2.GetUpToDateModules(), StringComparer.Ordinal);
                    areKnownModulesUpToDate = true;
                }
            }
            for (int i = 0; i < modules.Count;)
            {
                if (stdLib.Contains(modules[i]))
                {
                    stdLibPackage._isUpToDate = knownModules == null ||
                                                knownModules.Contains(modules[i]) == areKnownModulesUpToDate;;
                    stdLibPackage._moduleCount += 1;
                    i += 1;
                    continue;
                }

#if DEBUG
                Debug.Assert(seenPackages.Add(modules[i]));
#endif

                var package = new DBPackageView(modules[i]);
                package._isUpToDate = knownModules == null ||
                                      knownModules.Contains(modules[i]) == areKnownModulesUpToDate;
                package._moduleCount = 1;

                var dotName = package._fullname + ".";
                for (++i; i < modules.Count && modules[i].StartsWith(dotName, StringComparison.Ordinal); ++i)
                {
                    package._isUpToDate &= knownModules == null ||
                                           knownModules.Contains(modules[i]) == areKnownModulesUpToDate;
                    package._moduleCount += 1;
                }

                yield return(package);
            }
        }
Beispiel #9
0
        internal EnvironmentView(
            IInterpreterOptionsService service,
            IInterpreterRegistryService registry,
            IPythonInterpreterFactory factory,
            Redirector redirector
            )
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }
            if (factory.Configuration == null)
            {
                throw new ArgumentException("factory must include a configuration");
            }

            _service                 = service;
            _registry                = registry;
            Factory                  = factory;
            Configuration            = Factory.Configuration;
            LocalizedDisplayName     = Configuration.Description;
            IsBroken                 = !Configuration.IsRunnable();
            BrokenEnvironmentHelpUrl = "https://go.microsoft.com/fwlink/?linkid=863373";

            _withDb = factory as IPythonInterpreterFactoryWithDatabase;
            if (_withDb != null)
            {
                _withDb.IsCurrentChanged += Factory_IsCurrentChanged;
                IsCheckingDatabase        = _withDb.IsCheckingDatabase;
                IsCurrent = _withDb.IsCurrent;
            }


            if (_service.IsConfigurable(Factory.Configuration.Id))
            {
                IsConfigurable = true;
            }

            Description = Factory.Configuration.Description;
            IsDefault   = (_service != null && _service.DefaultInterpreterId == Configuration.Id);

            PrefixPath             = Factory.Configuration.PrefixPath;
            InterpreterPath        = Factory.Configuration.InterpreterPath;
            WindowsInterpreterPath = Factory.Configuration.WindowsInterpreterPath;

            Extensions = new ObservableCollection <object>();
            Extensions.Add(new EnvironmentPathsExtensionProvider());
            if (IsConfigurable)
            {
                Extensions.Add(new ConfigurationExtensionProvider(_service, alwaysCreateNew: false));
            }

            CanBeDefault = Factory.CanBeDefault();

            Company    = _registry.GetProperty(Factory.Configuration.Id, CompanyKey) as string ?? "";
            SupportUrl = _registry.GetProperty(Factory.Configuration.Id, SupportUrlKey) as string ?? "";

            LocalizedHelpText = Company;
        }
Beispiel #10
0
        internal EnvironmentView(
            IInterpreterOptionsService service,
            IInterpreterRegistryService registry,
            IPythonInterpreterFactory factory,
            Redirector redirector
            )
        {
            if (service == null) {
                throw new ArgumentNullException(nameof(service));
            }
            if (registry == null) {
                throw new ArgumentNullException(nameof(registry));
            }
            if (factory == null) {
                throw new ArgumentNullException(nameof(factory));
            }

            _service = service;
            _registry = registry;
            Factory = factory;

            _withDb = factory as IPythonInterpreterFactoryWithDatabase;
            if (_withDb != null) {
                _withDb.IsCurrentChanged += Factory_IsCurrentChanged;
                IsCheckingDatabase = _withDb.IsCheckingDatabase;
                IsCurrent = _withDb.IsCurrent;
            }

            if (_service.IsConfigurable(factory.Configuration.Id)) {
                IsConfigurable = true;
            }

            Description = Factory.Configuration.FullDescription;
            IsDefault = (_service != null && _service.DefaultInterpreter == Factory);

            PrefixPath = Factory.Configuration.PrefixPath;
            InterpreterPath = Factory.Configuration.InterpreterPath;
            WindowsInterpreterPath = Factory.Configuration.WindowsInterpreterPath;
            LibraryPath = Factory.Configuration.LibraryPath;

            Extensions = new ObservableCollection<object>();
            Extensions.Add(new EnvironmentPathsExtensionProvider());
            if (IsConfigurable) {
                Extensions.Add(new ConfigurationExtensionProvider(_service));
            }

            CanBeDefault = Factory.CanBeDefault();

            Vendor = _registry.GetProperty(Factory.Configuration.Id, "Vendor") as string;
            SupportUrl = _registry.GetProperty(Factory.Configuration.Id, "SupportUrl") as string;
        }