Beispiel #1
0
        public override void LoadSettingsFromStorage()
        {
            _defaultInterpreter        = GetDefaultInterpreterId();
            _defaultInterpreterVersion = GetDefaultInterpreterVersion();

            var model        = (IComponentModel)PythonToolsPackage.GetGlobalService(typeof(SComponentModel));
            var interpreters = model.GetAllPythonInterpreterFactories();

            _options.Clear();
            foreach (var interpreter in interpreters)
            {
                _options.Add(
                    new InterpreterOptions()
                {
                    Display                 = interpreter.GetInterpreterDisplay(),
                    Id                      = interpreter.Id,
                    InteractiveOptions      = null,
                    InterpreterPath         = interpreter.Configuration.InterpreterPath,
                    WindowsInterpreterPath  = interpreter.Configuration.WindowsInterpreterPath,
                    Version                 = interpreter.Configuration.Version.ToString(),
                    Architecture            = FormatArchitecture(interpreter.Configuration.Architecture),
                    PathEnvironmentVariable = interpreter.Configuration.PathEnvironmentVariable,
                    IsConfigurable          = interpreter is ConfigurablePythonInterpreterFactory,
                    SupportsCompletionDb    = interpreter is IInterpreterWithCompletionDatabase,
                    Factory                 = interpreter
                }
                    );
            }
        }
Beispiel #2
0
        private void AddPerformanceSession(object sender, EventArgs e)
        {
            var    dte      = (EnvDTE.DTE)PythonToolsPackage.GetGlobalService(typeof(EnvDTE.DTE));
            string filename = "Performance.pyperf";
            bool   save     = false;

            if (dte.Solution.IsOpen && !String.IsNullOrEmpty(dte.Solution.FullName))
            {
                filename = Path.Combine(Path.GetDirectoryName(dte.Solution.FullName), filename);
                save     = true;
            }
            ShowPerformanceExplorer().Sessions.AddTarget(new ProfilingTarget(), filename, save);
        }
        public override void LoadSettingsFromStorage()
        {
            var model        = (IComponentModel)PythonToolsPackage.GetGlobalService(typeof(SComponentModel));
            var interpreters = model.GetAllPythonInterpreterFactories();

            _options.Clear();
            foreach (var interpreter in interpreters)
            {
                string interpreterId = interpreter.GetInterpreterPath() + "\\";

                _options[interpreter] =
                    ReadOptions(interpreterId);
            }
        }
        public override void SaveSettingsToStorage()
        {
            var model        = (IComponentModel)PythonToolsPackage.GetGlobalService(typeof(SComponentModel));
            var interpreters = model.GetAllPythonInterpreterFactories();
            var replProvider = model.GetService <IReplWindowProvider>();

            foreach (var interpreter in interpreters)
            {
                string interpreterId = interpreter.GetInterpreterPath() + "\\";

                PythonInteractiveOptions options;
                if (_options.TryGetValue(interpreter, out options))
                {
                    SaveString(interpreterId + PrimaryPromptSetting, options.PrimaryPrompt);
                    SaveString(interpreterId + SecondaryPromptSetting, options.SecondaryPrompt);
                    SaveBool(interpreterId + InlinePromptsSetting, options.InlinePrompts);
                    SaveBool(interpreterId + UseInterpreterPromptsSetting, options.UseInterpreterPrompts);
                    SaveEnum <ReplIntellisenseMode>(interpreterId + ReplIntellisenseModeSetting, options.ReplIntellisenseMode);
                    SaveBool(interpreterId + SmartHistorySetting, options.ReplSmartHistory);
                    SaveString(interpreterId + StartupScriptSetting, options.StartupScript);
                    SaveString(interpreterId + ExecutionModeSetting, options.ExecutionMode ?? "");

                    // propagate changed settings to existing REPL windows
                    foreach (var replWindow in replProvider.GetReplWindows())
                    {
                        PythonReplEvaluator pyEval = replWindow.Evaluator as PythonReplEvaluator;
                        if (EvaluatorUsesThisInterpreter(pyEval, interpreter))
                        {
                            if (options.UseInterpreterPrompts)
                            {
                                replWindow.SetOptionValue(ReplOptions.PrimaryPrompt, pyEval.PrimaryPrompt);
                                replWindow.SetOptionValue(ReplOptions.SecondaryPrompt, pyEval.SecondaryPrompt);
                            }
                            else
                            {
                                replWindow.SetOptionValue(ReplOptions.PrimaryPrompt, options.PrimaryPrompt);
                                replWindow.SetOptionValue(ReplOptions.SecondaryPrompt, options.SecondaryPrompt);
                            }
                            replWindow.SetOptionValue(ReplOptions.DisplayPromptInMargin, !options.InlinePrompts);
                            replWindow.SetOptionValue(ReplOptions.UseSmartUpDown, options.ReplSmartHistory);
                        }
                    }
                }
            }
        }
Beispiel #5
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));
            }
        }
Beispiel #6
0
        public PythonGeneralyPropertyPageControl()
        {
            InitializeComponent();

            var model = (IComponentModel)PythonToolsPackage.GetGlobalService(typeof(SComponentModel));

            _interpreters = model.GetAllPythonInterpreterFactories();

            foreach (var interpreter in _interpreters)
            {
                _defaultInterpreter.Items.Add(interpreter.GetInterpreterDisplay());
            }
            if (_defaultInterpreter.Items.Count == 0)
            {
                _defaultInterpreter.Enabled = false;
                _defaultInterpreter.Items.Add("No Python Interpreters Installed");
                _defaultInterpreter.SelectedIndexChanged -= this.Changed;
                _defaultInterpreter.SelectedIndex         = 0;
                _defaultInterpreter.SelectedIndexChanged += this.Changed;
            }
        }
Beispiel #7
0
        public static IEnumerable <InterpreterView> GetInterpreters()
        {
            var componentService = (PythonToolsPackage.GetGlobalService(typeof(SComponentModel))) as IComponentModel;
            var factoryProviders = componentService.GetExtensions <IPythonInterpreterFactoryProvider>();

            var defaultId      = PythonToolsPackage.Instance.InterpreterOptionsPage.DefaultInterpreterValue;
            var defaultVersion = PythonToolsPackage.Instance.InterpreterOptionsPage.DefaultInterpreterVersionValue;

            foreach (var factory in factoryProviders)
            {
                foreach (var interp in factory.GetInterpreterFactories())
                {
                    if (interp != null)
                    {
                        yield return(new InterpreterView(
                                         interp,
                                         interp.GetInterpreterDisplay(),
                                         interp.Id == defaultId && interp.Configuration.Version == defaultVersion));
                    }
                }
            }
        }
Beispiel #8
0
        internal string GetProfilingName(out bool save)
        {
            string baseName = null;

            if (ProjectTarget != null)
            {
                if (!String.IsNullOrEmpty(ProjectTarget.FriendlyName))
                {
                    baseName = ProjectTarget.FriendlyName;
                }
            }
            else if (StandaloneTarget != null)
            {
                if (!String.IsNullOrEmpty(StandaloneTarget.Script))
                {
                    baseName = Path.GetFileNameWithoutExtension(StandaloneTarget.Script);
                }
            }

            if (baseName == null)
            {
                baseName = "Performance";
            }

            baseName = baseName + ".pyperf";

            var dte = (EnvDTE.DTE)PythonToolsPackage.GetGlobalService(typeof(EnvDTE.DTE));

            if (dte.Solution.IsOpen && !String.IsNullOrEmpty(dte.Solution.FullName))
            {
                save = true;
                return(Path.Combine(Path.GetDirectoryName(dte.Solution.FullName), baseName));
            }

            save = false;
            return(baseName);
        }
Beispiel #9
0
        /// <summary>
        /// Opens the find symbols dialog with a list of results.  This is done by requesting
        /// that VS does a search against our library GUID.  Our library then responds to
        /// that request by extracting the prvoided symbol list out and using that for the
        /// search results.
        /// </summary>
        private static void ShowFindSymbolsDialog(ExpressionAnalysis provider, IVsNavInfo symbols)
        {
            // ensure our library is loaded so find all references will go to our library
            Package.GetGlobalService(typeof(IPythonLibraryManager));

            if (provider.Expression != "")
            {
                var findSym = (IVsFindSymbol)PythonToolsPackage.GetGlobalService(typeof(SVsObjectSearch));
                VSOBSEARCHCRITERIA2 searchCriteria = new VSOBSEARCHCRITERIA2();
                searchCriteria.eSrchType   = VSOBSEARCHTYPE.SO_ENTIREWORD;
                searchCriteria.pIVsNavInfo = symbols;
                searchCriteria.grfOptions  = (uint)_VSOBSEARCHOPTIONS2.VSOBSO_LISTREFERENCES;
                searchCriteria.szName      = provider.Expression;

                Guid guid = Guid.Empty;
                //  new Guid("{a5a527ea-cf0a-4abf-b501-eafe6b3ba5c6}")
                ErrorHandler.ThrowOnFailure(findSym.DoSearch(new Guid(CommonConstants.LibraryGuid), new VSOBSEARCHCRITERIA2[] { searchCriteria }));
            }
            else
            {
                var statusBar = (IVsStatusbar)CommonPackage.GetGlobalService(typeof(SVsStatusbar));
                statusBar.SetText("The caret must be on valid expression to find all references.");
            }
        }
Beispiel #10
0
        public override int ExecCommand(uint itemid, ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == VsMenus.guidVsUIHierarchyWindowCmds)
            {
                switch ((VSConstants.VsUIHierarchyWindowCmdIds)nCmdID)
                {
                case VSConstants.VsUIHierarchyWindowCmdIds.UIHWCMDID_DoubleClick:
                case VSConstants.VsUIHierarchyWindowCmdIds.UIHWCMDID_EnterKey:
                    if (itemid == VSConstants.VSITEMID_ROOT)
                    {
                        OpenTargetProperties();

                        // S_FALSE: don't process the double click to expand the item
                        return(VSConstants.S_FALSE);
                    }
                    else if (IsReportItem(itemid))
                    {
                        OpenProfile(itemid);
                    }

                    return((int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED);

                case VSConstants.VsUIHierarchyWindowCmdIds.UIHWCMDID_RightClick:
                    int?ctxMenu = null;

                    if (itemid == VSConstants.VSITEMID_ROOT)
                    {
                        ctxMenu = (int)PkgCmdIDList.menuIdPerfContext;
                    }
                    else if (itemid == ReportsItemId)
                    {
                        ctxMenu = (int)PkgCmdIDList.menuIdPerfReportsContext;
                    }
                    else if (IsReportItem(itemid))
                    {
                        ctxMenu = (int)PkgCmdIDList.menuIdPerfSingleReportContext;
                    }

                    if (ctxMenu != null)
                    {
                        var uishell = (IVsUIShell)PythonToolsPackage.GetGlobalService(typeof(SVsUIShell));
                        if (uishell != null)
                        {
                            var pt   = System.Windows.Forms.Cursor.Position;
                            var pnts = new[] { new POINTS {
                                                   x = (short)pt.X, y = (short)pt.Y
                                               } };
                            var guid = GuidList.guidPythonProfilingCmdSet;
                            int hr   = uishell.ShowContextMenu(
                                0,
                                ref guid,
                                ctxMenu.Value,
                                pnts,
                                new ContextCommandTarget(this, itemid));

                            ErrorHandler.ThrowOnFailure(hr);
                        }
                    }

                    break;
                }
            }

            return(base.ExecCommand(itemid, ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Beispiel #11
0
        public override void SaveSettingsToStorage()
        {
            var defaultInterpreter = GetWindow().GetOption(GetWindow().DefaultInterpreter);

            Version defaultVersion;

            if (Version.TryParse(defaultInterpreter.Version, out defaultVersion))
            {
                if (defaultInterpreter.Id != GetDefaultInterpreterId() || defaultVersion != GetDefaultInterpreterVersion())
                {
                    SaveString(DefaultInterpreterSetting, defaultInterpreter.Id.ToString());
                    SaveString(DefaultInterpreterVersionSetting, defaultVersion.ToString());
                    PythonToolsPackage.Instance.UpdateDefaultAnalyzer();
                }
            }

            var model        = (IComponentModel)PythonToolsPackage.GetGlobalService(typeof(SComponentModel));
            var configurable = model.GetService <IPythonConfigurableInterpreterFactoryProvider>();

            for (int i = 0; i < _options.Count;)
            {
                var option = _options[i];

                bool added = false;
                if (option.Removed)
                {
                    if (!option.Added)
                    {
                        // it was added and then immediately removed, don't save it.
                        configurable.RemoveInterpreter(option.Id);
                    }
                    _options.RemoveAt(i);
                    continue;
                }
                else if (option.Added)
                {
                    if (option.Id == Guid.Empty)
                    {
                        option.Id = Guid.NewGuid();
                    }
                    option.Added = false;
                    added        = true;
                }

                if (option.IsConfigurable)
                {
                    // save configurable interpreter options
                    var fact = configurable.SetOptions(
                        option.Id,
                        new Dictionary <string, object>()
                    {
                        { "InterpreterPath", option.InterpreterPath ?? "" },
                        { "WindowsInterpreterPath", option.WindowsInterpreterPath ?? "" },
                        { "PathEnvironmentVariable", option.PathEnvironmentVariable ?? "" },
                        { "Architecture", option.Architecture ?? "x86" },
                        { "Version", option.Version ?? "2.6" },
                        { "Description", option.Display },
                    }
                        );

                    if (added)
                    {
                        if (PythonToolsPackage.Instance.InteractiveOptionsPage._window != null)
                        {
                            PythonToolsPackage.Instance.InteractiveOptionsPage._window.NewInterpreter(fact);
                        }
                    }
                }

                // save settings available for all interpreters.
                Version version;
                if (Version.TryParse(option.Version, out version))
                {
                    string savePath = GetInterpreterSettingPath(option.Id, version);

                    SaveString(savePath + InteractiveOptionsSetting, option.InteractiveOptions ?? "");
                }

                i++;
            }
        }