public PythonLanguageClientContextWorkspace(IPythonWorkspaceContext pythonWorkspace)
        {
            _pythonWorkspace = pythonWorkspace ?? throw new ArgumentNullException(nameof(pythonWorkspace));
            _disposables     = new DisposableBag(GetType().Name);

            _pythonWorkspace.ActiveInterpreterChanged  += OnInterpreterChanged;
            _pythonWorkspace.SearchPathsSettingChanged += OnSearchPathsChanged;
            _disposables.Add(() => {
                _pythonWorkspace.ActiveInterpreterChanged  -= OnInterpreterChanged;
                _pythonWorkspace.SearchPathsSettingChanged -= OnSearchPathsChanged;
            });

            _pythonWorkspace.AddActionOnClose(this, (obj) => Closed?.Invoke(this, EventArgs.Empty));
        }
Beispiel #2
0
        internal static IVsInteractiveWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project, IPythonWorkspaceContext workspace)
        {
            var compModel        = serviceProvider.GetComponentModel();
            var provider         = compModel.GetService <InteractiveWindowProvider>();
            var vsProjectContext = compModel.GetService <VsProjectContextProvider>();

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

            var workspaceId = workspace != null?PythonReplEvaluatorProvider.GetEvaluatorId(workspace) : 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 workspace, prefer that to a per config one
            if (!string.IsNullOrEmpty(workspaceId))
            {
                window = provider.Open(
                    workspaceId,
                    e => ((e as SelectableReplEvaluator)?.Evaluator as PythonCommonInteractiveEvaluator)?.AssociatedWorkspaceHasChanged != 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(workspaceId))
            {
                window = provider.Create(workspaceId);
                workspace.AddActionOnClose(window, w => InteractiveWindowProvider.CloseIfEvaluatorMatches(w, workspaceId));
            }
            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);
        }