コード例 #1
0
        /// <summary>
        /// Creates an interpreter which was created programmatically by some plugin
        /// </summary>
        private IReplEvaluator CreateConfigurableInterpreter(string replId)
        {
            string[] components = replId.Split(new[] { '|' }, 5);
            if (components.Length == 5)
            {
                string interpreter        = components[1];
                string interpreterVersion = components[2];
                // string userId = components[3];
                // We don't care about the user identifier - it is there to
                // ensure that evaluators can be distinguished within a project
                // and/or with the same interpreter.
                string projectName = components[4];

                var replOptions = new ConfigurablePythonReplOptions();
                replOptions.InterpreterFactory = _interpreterService.FindInterpreter(interpreter, interpreterVersion);

                if (replOptions.InterpreterFactory == null)
                {
                    var solution = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
                    if (solution != null)
                    {
                        foreach (var proj in solution.EnumerateLoadedProjects())
                        {
                            if (!proj.GetRootCanonicalName().Equals(projectName, StringComparison.Ordinal))
                            {
                                continue;
                            }
                            var pyProj = proj.GetPythonProject();
                            if (pyProj == null)
                            {
                                continue;
                            }
                            replOptions.InterpreterFactory = pyProj.Interpreters.FindInterpreter(interpreter, interpreterVersion);
                            replOptions.Project            = pyProj;
                            break;
                        }
                    }
                }

                if (replOptions.InterpreterFactory != null)
                {
                    return(new PythonReplEvaluatorDontPersist(
                               replOptions.InterpreterFactory,
                               _serviceProvider,
                               replOptions,
                               _interpreterService
                               ));
                }
            }
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Creates an interactive evaluator programmatically for some plugin
        /// </summary>
        private IInteractiveEvaluator CreateConfigurableEvaluator(string replId)
        {
            string[] components = replId.Split(new[] { '|' }, 2);
            if (components.Length == 2)
            {
                string interpreter = components[1];

                var factory = _interpreterService.FindInterpreter(interpreter);

                if (factory != null)
                {
                    var replOptions = new ConfigurablePythonReplOptions();
                    replOptions.InterpreterFactory = factory;

                    if (interpreter.StartsWith(MSBuildProjectInterpreterFactoryProvider.MSBuildProviderName + "|"))
                    {
                        string[] projectComponents = interpreter.Split(new[] { '|' }, 3);
                        string   projectName       = projectComponents[2];

                        var solution = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
                        if (solution != null)
                        {
                            foreach (var pyProj in solution.EnumerateLoadedPythonProjects())
                            {
                                var name = ((IVsHierarchy)pyProj).GetRootCanonicalName();
                                if (string.Equals(name, projectName, StringComparison.OrdinalIgnoreCase))
                                {
                                    replOptions.Project = pyProj;
                                    break;
                                }
                            }
                        }
                    }

                    return(new PythonReplEvaluatorDontPersist(
                               replOptions.InterpreterFactory,
                               _serviceProvider,
                               replOptions,
                               _interpreterService
                               ));
                }
            }
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Creates an interactive evaluator programmatically for some plugin
        /// </summary>
        private IInteractiveEvaluator CreateConfigurableEvaluator(string replId) {
            string[] components = replId.Split(new[] { '|' }, 5);
            if (components.Length == 5) {
                string interpreter = components[1];
                string interpreterVersion = components[2];
                // string userId = components[3];
                // We don't care about the user identifier - it is there to
                // ensure that evaluators can be distinguished within a project
                // and/or with the same interpreter.
                string projectName = components[4];

                var factory = _interpreterService.FindInterpreter(interpreter, interpreterVersion);

                if (factory != null) {
                    var replOptions = new ConfigurablePythonReplOptions();
                    replOptions.InterpreterFactory = factory;

                    var solution = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
                    if (solution != null) {
                        foreach (var pyProj in solution.EnumerateLoadedPythonProjects()) {
                            var name = ((IVsHierarchy)pyProj).GetRootCanonicalName();
                            if (string.Equals(name, projectName, StringComparison.OrdinalIgnoreCase)) {
                                replOptions.Project = pyProj;
                                break;
                            }
                        }
                    }

                    return new PythonReplEvaluatorDontPersist(
                        replOptions.InterpreterFactory,
                        _serviceProvider,
                        replOptions,
                        _interpreterService
                    );
                }
            }
            return null;
        }