Пример #1
0
        internal static IVsInteractiveWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project)
        {
            var compModel        = serviceProvider.GetComponentModel();
            var provider         = compModel.GetService <InteractiveWindowProvider>();
            var vsProjectContext = compModel.GetService <VsProjectContextProvider>();

            var projectId = project != null?PythonReplEvaluatorProvider.GetEvaluatorId(project) : null;

            var configId = config != null?PythonReplEvaluatorProvider.GetEvaluatorId(config) : null;

            IVsInteractiveWindow window;

            // If we find an open window for the project, prefer that to a per-config one
            if (!string.IsNullOrEmpty(projectId))
            {
                window = provider.Open(projectId);
                if (window != null)
                {
                    if (window.InteractiveWindow.GetPythonEvaluator()?.AssociatedProjectHasChanged == true)
                    {
                        // We have an existing window, but it needs to be reset.
                        // Let's create a new one
                        window = provider.Create(projectId);
                        project.AddActionOnClose(window, w => InteractiveWindowProvider.CloseIfEvaluatorMatches(w, projectId));
                    }

                    return(window);
                }
            }

            // If we find an open window for the configuration, return that
            if (!string.IsNullOrEmpty(configId))
            {
                window = provider.Open(configId);
                if (window != null)
                {
                    return(window);
                }
            }

            // No window found, so let's create one
            if (!string.IsNullOrEmpty(projectId))
            {
                window = provider.Create(projectId);
                project.AddActionOnClose(window, w => InteractiveWindowProvider.CloseIfEvaluatorMatches(w, projectId));
            }
            else if (!string.IsNullOrEmpty(configId))
            {
                window = provider.Create(configId);
            }
            else
            {
                var interpService = compModel.GetService <IInterpreterOptionsService>();
                window = provider.Create(PythonReplEvaluatorProvider.GetEvaluatorId(interpService.DefaultInterpreter.Configuration));
            }

            return(window);
        }
Пример #2
0
        internal static IVsInteractiveWindow/*!*/ EnsureReplWindow(IServiceProvider serviceProvider, IPythonInterpreterFactory factory, PythonProjectNode project) {
            var compModel = serviceProvider.GetComponentModel();
            var provider = compModel.GetService<InteractiveWindowProvider>();

            string replId = PythonReplEvaluatorProvider.GetReplId(factory, project);
            var window = provider.FindReplWindow(replId);
            if (window == null) {
                window = provider.CreateInteractiveWindow(
                    serviceProvider.GetPythonContentType(),
                    factory.Description + " Interactive",
                    typeof(PythonLanguageInfo).GUID,
                    replId
                );

                var toolWindow = window as ToolWindowPane;
                if (toolWindow != null) {
                    toolWindow.BitmapImageMoniker = KnownMonikers.PYInteractiveWindow;
                }

                var pyService = serviceProvider.GetPythonToolsService();
                window.InteractiveWindow.SetSmartUpDown(pyService.GetInteractiveOptions(factory).ReplSmartHistory);
            }

            if (project != null && project.Interpreters.IsProjectSpecific(factory)) {
                project.AddActionOnClose(window, BasePythonReplEvaluator.CloseReplWindow);
            }

            return window;
        }
        internal static IReplWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, IPythonInterpreterFactory factory, PythonProjectNode project)
        {
            var compModel = serviceProvider.GetComponentModel();
            var provider  = compModel.GetService <IReplWindowProvider>();

            string replId = PythonReplEvaluatorProvider.GetReplId(factory, project);
            var    window = provider.FindReplWindow(replId);

            if (window == null)
            {
                window = provider.CreateReplWindow(
                    serviceProvider.GetPythonContentType(),
                    factory.Description + " Interactive",
                    typeof(PythonLanguageInfo).GUID,
                    replId
                    );

                var pyService = serviceProvider.GetPythonToolsService();
                window.SetOptionValue(
                    ReplOptions.UseSmartUpDown,
                    pyService.GetInteractiveOptions(factory).ReplSmartHistory
                    );
            }

            if (project != null && project.Interpreters.IsProjectSpecific(factory))
            {
                project.AddActionOnClose(window, BasePythonReplEvaluator.CloseReplWindow);
            }

            return(window);
        }
Пример #4
0
        internal static IVsInteractiveWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project)
        {
            var compModel        = serviceProvider.GetComponentModel();
            var provider         = compModel.GetService <InteractiveWindowProvider>();
            var vsProjectContext = compModel.GetService <VsProjectContextProvider>();

            var projectId = project != null?PythonReplEvaluatorProvider.GetEvaluatorId(project) : null;

            var configId = config != null?PythonReplEvaluatorProvider.GetEvaluatorId(config) : null;

            if (config?.IsRunnable() == false)
            {
                throw new MissingInterpreterException(
                          Strings.MissingEnvironment.FormatUI(config.Description, config.Version)
                          );
            }

            IVsInteractiveWindow window;

            // If we find an open window for the project, prefer that to a per-config one
            if (!string.IsNullOrEmpty(projectId))
            {
                window = provider.Open(
                    projectId,
                    e => ((e as SelectableReplEvaluator)?.Evaluator as PythonCommonInteractiveEvaluator)?.AssociatedProjectHasChanged != true
                    );
                if (window != null)
                {
                    return(window);
                }
            }

            // If we find an open window for the configuration, return that
            if (!string.IsNullOrEmpty(configId))
            {
                window = provider.Open(configId);
                if (window != null)
                {
                    return(window);
                }
            }

            // No window found, so let's create one
            if (!string.IsNullOrEmpty(projectId))
            {
                window = provider.Create(projectId);
                project.AddActionOnClose(window, w => InteractiveWindowProvider.CloseIfEvaluatorMatches(w, projectId));
            }
            else if (!string.IsNullOrEmpty(configId))
            {
                window = provider.Create(configId);
            }
            else
            {
                var interpService = compModel.GetService <IInterpreterOptionsService>();
                window = provider.Create(PythonReplEvaluatorProvider.GetEvaluatorId(interpService.DefaultInterpreter.Configuration));
            }

            return(window);
        }
Пример #5
0
        internal static IVsInteractiveWindow/*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project) {
            var compModel = serviceProvider.GetComponentModel();
            var provider = compModel.GetService<InteractiveWindowProvider>();
            var vsProjectContext = compModel.GetService<VsProjectContextProvider>();

            var projectId = project != null ? PythonReplEvaluatorProvider.GetEvaluatorId(project) : null;
            var configId = config != null ? PythonReplEvaluatorProvider.GetEvaluatorId(config) : null;

            IVsInteractiveWindow window;

            // If we find an open window for the project, prefer that to a per-config one
            if (!string.IsNullOrEmpty(projectId)) {
                window = provider.Open(projectId);
                if (window != null) {
                    if (window.InteractiveWindow.GetPythonEvaluator()?.AssociatedProjectHasChanged == true) {
                        // We have an existing window, but it needs to be reset.
                        // Let's create a new one
                        window = provider.Create(projectId);
                        project.AddActionOnClose(window, InteractiveWindowProvider.Close);
                    }

                    return window;
                }
            }

            // If we find an open window for the configuration, return that
            if (!string.IsNullOrEmpty(configId)) {
                window = provider.Open(configId);
                if (window != null) {
                    return window;
                }
            }

            // No window found, so let's create one
            if (!string.IsNullOrEmpty(projectId)) {
                window = provider.Create(projectId);
                project.AddActionOnClose(window, InteractiveWindowProvider.Close);
            } else if (!string.IsNullOrEmpty(configId)) {
                window = provider.Create(configId);
            } else {
                var interpService = compModel.GetService<IInterpreterOptionsService>();
                window = provider.Create(PythonReplEvaluatorProvider.GetEvaluatorId(interpService.DefaultInterpreter.Configuration));
            }

            return window;
        }
Пример #6
0
        public PythonLanguageClientContextProject(PythonProjectNode project)
        {
            _project     = project ?? throw new ArgumentNullException(nameof(project));
            _disposables = new DisposableBag(GetType().Name);

            _project.LanguageServerInterpreterChanged += OnInterpreterChanged;
            _project.LanguageServerSearchPathsChanged += OnSearchPathsChanged;
            _disposables.Add(() => {
                _project.LanguageServerInterpreterChanged -= OnInterpreterChanged;
                _project.LanguageServerSearchPathsChanged -= OnSearchPathsChanged;
            });

            _project.AddActionOnClose(this, (obj) => Closed?.Invoke(this, EventArgs.Empty));
        }
Пример #7
0
        internal static IVsInteractiveWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project)
        {
            var compModel        = serviceProvider.GetComponentModel();
            var provider         = compModel.GetService <InteractiveWindowProvider>();
            var vsProjectContext = compModel.GetService <VsProjectContextProvider>();

            string replId = config != null?
                            PythonReplEvaluatorProvider.GetEvaluatorId(config) :
                                PythonReplEvaluatorProvider.GetEvaluatorId(project);

            var window = provider.OpenOrCreate(replId);

            project?.AddActionOnClose(window, InteractiveWindowProvider.Close);

            return(window);
        }
Пример #8
0
        internal static IReplWindowToolWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, IPythonInterpreterFactory factory, PythonProjectNode project)
        {
            var compModel = serviceProvider.GetComponentModel();
            var provider  = compModel.GetService <IReplWindowProvider>();

            string replId = PythonReplEvaluatorProvider.GetReplId(factory, project);
            var    window = provider.FindReplWindow(replId);

            if (window == null)
            {
                window = provider.CreateReplWindow(
                    serviceProvider.GetPythonContentType(),
                    factory.Description + " Interactive",
                    typeof(PythonLanguageInfo).GUID,
                    replId
                    );

                var toolWindow = window as ToolWindowPane;
                if (toolWindow != null)
                {
#if DEV14_OR_LATER
                    toolWindow.BitmapImageMoniker = KnownMonikers.PYInteractiveWindow;
#else
                    // TODO: Add image here for VS 2013
#endif
                }

                var pyService = serviceProvider.GetPythonToolsService();
                window.SetSmartUpDown(pyService.GetInteractiveOptions(factory).ReplSmartHistory);
            }

            if (project != null && project.Interpreters.IsProjectSpecific(factory))
            {
                project.AddActionOnClose(window, BasePythonReplEvaluator.CloseReplWindow);
            }

            return(window);
        }
Пример #9
0
        internal static IVsInteractiveWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project)
        {
            var compModel        = serviceProvider.GetComponentModel();
            var provider         = compModel.GetService <InteractiveWindowProvider>();
            var vsProjectContext = compModel.GetService <VsProjectContextProvider>();

            string replId = PythonReplEvaluatorProvider.GetReplId(config.Id, project);
            var    window = provider.FindReplWindow(replId);

            if (window == null)
            {
                window = provider.CreateInteractiveWindow(
                    serviceProvider.GetPythonContentType(),
                    config.FullDescription + " Interactive",
                    typeof(PythonLanguageInfo).GUID,
                    replId
                    );

#if DEV14
                var toolWindow = window as ToolWindowPane;
                if (toolWindow != null)
                {
                    toolWindow.BitmapImageMoniker = KnownMonikers.PYInteractiveWindow;
                }
#endif

                var pyService = serviceProvider.GetPythonToolsService();
                window.InteractiveWindow.SetSmartUpDown(pyService.GetInteractiveOptions(config).ReplSmartHistory);
            }


            if (project != null && vsProjectContext.IsProjectSpecific(config))
            {
                project.AddActionOnClose(window, BasePythonReplEvaluator.CloseReplWindow);
            }

            return(window);
        }