Beispiel #1
0
        private static Task <Action> GetInitializeTask()
        {
            var componentModel = (IComponentModel)VsPackage.GetGlobalService(typeof(SComponentModel));

            if (componentModel == null)
            {
                throw new InvalidOperationException();
            }

            try
            {
                // HACK: Short cut to set the Powershell execution policy for this process to RemoteSigned.
                // This is so that we can initialize the PowerShell host and load our modules successfully.
                Environment.SetEnvironmentVariable(
                    "PSExecutionPolicyPreference", "RemoteSigned", EnvironmentVariableTarget.Process);
            }
            catch (SecurityException)
            {
                // ignore if user doesn't have permission to add process-level environment variable,
                // which is very rare.
            }

            var initializer = componentModel.GetService <IHostInitializer>();

            return(Task.Factory.StartNew(() =>
            {
                initializer.Start();
                return new Action(initializer.SetDefaultRunspace);
            }));
        }
Beispiel #2
0
        public override T GetService <T>(Type type = null)
        {
            // First try internal services
            var service = base.GetService <T>(type);

            if (service == null)
            {
                // First try MEF
                service = _appShell.ExportProvider.GetExportedValueOrDefault <T>();
                if (service == null)
                {
                    // Now try VS services. Only allowed on UI thread.
                    _appShell.AssertIsOnMainThread();
                    if (_appShell.IsUnitTestEnvironment)
                    {
                        service = RPackage.Current.GetService(type ?? typeof(T)) as T;
                    }
                    else
                    {
                        service = VsPackage.GetGlobalService(type ?? typeof(T)) as T;
                    }
                }
            }
            return(service);
        }
Beispiel #3
0
        private void ConfigurePackageServices()
        {
            var platformServices = new VsPlatformServices();

            var componentModel     = (IComponentModel)VsPackage.GetGlobalService(typeof(SComponentModel));
            var compositionCatalog = new CompositionCatalog(componentModel.DefaultCompositionService, componentModel.DefaultExportProvider);
            var exportProvider     = componentModel.DefaultExportProvider;

            _services
            .AddService(componentModel)
            .AddService(componentModel.DefaultCompositionService)
            .AddService(exportProvider)
            .AddService(compositionCatalog)
            .AddService(new VsUIServices(this))
            .AddService(new VsPlotExportDialog(this))
            .AddService(platformServices)
            .AddService <IEditorSupport, VsEditorSupport>()
            .AddService <IImageService, ImageService>()
            .AddService(new REditorSettings(this))
            .AddService(new RMarkdownEditorSettings(this))
            .AddService <IStatusBar, VsStatusBar>()
            .AddService <RPackageToolWindowProvider>()
            .AddRComponentsServices()
            .AddWindowsRInterpretersServices()
            .AddWindowsHostClientServices()
            .AddWindowsRComponentsServices()
            .AddEditorServices()
            .AddWindowsContainerServices();
            // TODO: add more

            _application = new VsApplication(_services);
            _services.AddService(_application);
            _services.GetService <IRSettings>().LoadSettings();
        }
Beispiel #4
0
        private async Task <MSSolution> GetCurrentSolution()
        {
            var dte = Package.GetGlobalService(typeof(SDTE)) as DTE;
            var solutionFullName = dte?.Solution.FullName;

            if (string.IsNullOrEmpty(solutionFullName))
            {
                throw new NoSolutionOpenException();
            }

            var msBuildWorkspace = MSBuildWorkspace.Create();

            return(await msBuildWorkspace.OpenSolutionAsync(solutionFullName));
        }
Beispiel #5
0
        /// <summary>
        /// Get the open solution.
        /// </summary>
        /// <returns></returns>
        private static Solution GetOpenSolution()
        {
            var dte = VsPackage.GetGlobalService(typeof(DTE)) as DTE;

            if (dte != null)
            {
                var openSolution = dte.Solution;
                return(openSolution);
            }
            else
            {
                return(null);
            }
        }
Beispiel #6
0
        private static Task <Action> GetInitializeTask()
        {
            var componentModel = (IComponentModel)VsPackage.GetGlobalService(typeof(SComponentModel));

            if (componentModel == null)
            {
                throw new InvalidOperationException();
            }

            var initializer = componentModel.GetService <IHostInitializer>();

            return(Task.Factory.StartNew(() => {
                initializer.Start();
                return new Action(initializer.SetDefaultRunspace);
            }));
        }
Beispiel #7
0
        private void SubmitAddRefStats()
        {
            DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;

            if (dte != null)
            {
                bool optOutOfStats = dte.GetOptOutStatsSetting();
                if (!optOutOfStats)
                {
                    var langName = typesHandler.RelativeTypesUrl.Substring(6);
                    Analytics.SubmitAnonymousAddReferenceUsage(langName);
                }
            }
            else
            {
                OutputWindowWriter.WriterWindow.WriteLine("Warning: Failed to resolve DTE");
            }
        }
Beispiel #8
0
        private void showToolWindow()
        {
            var vsUiShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell));
            var guid      = Guid.Parse(
                "e3bfb80d-d50a-4a85-bacd-64daca9095f7");                //This is the exact Guid declared by the DataTableVisualizerToolWindow
            var result = vsUiShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fFindFirst, ref guid,
                                                  out var windowFrame); // Find MyToolWindow

            if (result != VSConstants.S_OK)
            {
                result = vsUiShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref guid,
                                                  out windowFrame); // Crate MyToolWindow if not found
            }
            if (result == VSConstants.S_OK)                         // Show MyToolWindow
            {
                ErrorHandler.ThrowOnFailure(windowFrame.Show());
            }
        }
Beispiel #9
0
        public override T GetService <T>(Type type = null)
        {
            type = type ?? typeof(T);

            if (type == typeof(ICoreShell))
            {
                return(_shell as T);
            }
            if (type == typeof(ExportProvider))
            {
                return(ExportProvider as T);
            }
            if (type == typeof(ICompositionService))
            {
                return(CompositionService as T);
            }
            if (type == typeof(ICompositionCatalog))
            {
                return((T)(ICompositionCatalog) new CompositionCatalog(CompositionService, ExportProvider));
            }

            // First try internal services
            var service = base.GetService <T>(type);

            if (service == null)
            {
                // First try MEF
                service = ExportProvider.GetExportedValueOrDefault <T>();
                if (service == null)
                {
                    // Now try VS services. Only allowed on UI thread.
                    if (TestEnvironment.Current != null)
                    {
                        service = RPackage.Current != null?RPackage.Current.GetService(type) as T : null;
                    }
                    else
                    {
                        service = VsPackage.GetGlobalService(type) as T;
                    }
                }
            }
            return(service);
        }
Beispiel #10
0
        private async Task AttemptLogErrorAsync(string message)
        {
            if (!ThreadHelper.CheckAccess())
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
            }

            var outputWindow = (IVsOutputWindow)Package.GetGlobalService(typeof(SVsOutputWindow));

            if (outputWindow != null)
            {
                outputWindow.GetPane(VSConstants.OutputWindowPaneGuid.BuildOutputPane_guid, out var pane);
                if (pane != null)
                {
                    pane.OutputString(message);
                    pane.Activate();
                }
            }
        }
        private async Task HandleChange(int delta)
        {
            if (ParticlesEnabled)
            {
                for (var i = 0; i < 10; i++)
                {
                    var explosion = new ExplosionParticle(_adornmentLayer,
                                                          (DTE)Package.GetGlobalService(typeof(DTE)),
                                                          _view.Caret.Top,
                                                          _view.Caret.Left);
                    var expl = explosion.Explode();

#pragma warning disable CS4014 // Don't care about return
                    Task.Run(() => expl);
#pragma warning restore CS4014
                }
            }
            if (ShakeEnabled)
            {
                await Shake(delta);
            }
        }
Beispiel #12
0
        private void Init()
        {
            dte = Package.GetGlobalService(typeof(DTE)) as DTE2;

            if (dte != null)
            {
                events = dte.Events as Events2;
                if (events != null)
                {
                    dteEvents                  = events.DTEEvents;
                    solutionEvents             = events.SolutionEvents;
                    dteEvents.OnBeginShutdown += ShutDown;
                    solutionEvents.Opened     += () => SwitchStartupDir("\n====== Solution opening Detected ======\n");
                }
            }

            terminalController.SetShell(optionMgr.Shell);

            terminalController.Init(GetProjectPath());

            terminalController.InvokeCmd("\n[Global Init Script ...]\n", optionMgr.getGlobalScript());
        }
Beispiel #13
0
        private void ConfigureServices()
        {
            var platformServices   = new VsPlatformServices();
            var telemetry          = new VsTelemetryService();
            var componentModel     = (IComponentModel)VsPackage.GetGlobalService(typeof(SComponentModel));
            var loggingPermissions = new LoggingPermissions(platformServices, telemetry, new RegistryImpl());
            var settings           = new RToolsSettingsImplementation(this, new VsSettingsStorage(), loggingPermissions);
            var compositionCatalog = new CompositionCatalog(componentModel.DefaultCompositionService, componentModel.DefaultExportProvider);
            var exportProvider     = componentModel.DefaultExportProvider;

            _services
            .AddService(componentModel)
            .AddService(componentModel.DefaultCompositionService)
            .AddService(exportProvider)
            .AddService(compositionCatalog)
            .AddService(new VsMainThread())
            .AddService(new VsTaskService())
            .AddService(_idleTimeService)
            .AddService(new VsUIServices(this))
            .AddService(new SecurityService(this))
            .AddService(loggingPermissions)
            .AddService(new Logger(ApplicationName, Path.GetTempPath(), loggingPermissions))
            .AddService(platformServices)
            .AddService(settings)
            .AddService(new REditorSettings(new LanguageSettingsStorage(this, RGuidList.RLanguageServiceGuid, RGuidList.RPackageGuid, new string[] { RPackage.ProductName })))
            .AddService(new ImageService(exportProvider.GetExportedValue <IGlyphService>()))
            .AddService(new VsEditorSupport(this))
            .AddService(telemetry)
            .AddService(new FileSystem())
            .AddService(new ProcessServices())
            .AddService(new RegistryImpl())
            .AddService(new MicrosoftRClientInstaller())
            .AddWindowsRInterpretersServices()
            .AddWindowsHostClientServices();
            // TODO: add more

            settings.LoadSettings();
        }
Beispiel #14
0
        /// <summary>
        /// Brings up the browse folder dialog.
        /// </summary>
        /// <param name="sender">The browse button.</param>
        /// <param name="e">The <see cref="EventArgs"/> object that contains the event data.</param>
        private void OnBrowseButtonClick(object sender, EventArgs e)
        {
            // initialize the dialog to the current directory (if it exists)
            bool   overridePersistedInitialDirectory = false;
            string initialDirectory = null;

            if (Directory.Exists(FullPath))
            {
                initialDirectory = FullPath;
                overridePersistedInitialDirectory = true;
            }

            IntPtr      parentWindow    = Handle;
            Guid        persistenceSlot = typeof(FileBrowserTextBox).GUID;
            IVsUIShell2 shell           = (IVsUIShell2)Package.GetGlobalService(typeof(SVsUIShell));
            // show the dialog
            string path = shell.GetDirectoryViaBrowseDialog(parentWindow, persistenceSlot, "Select folder", initialDirectory, overridePersistedInitialDirectory);

            if (path != null)
            {
                if (MakeRelative && !string.IsNullOrEmpty(RootFolder))
                {
                    string rootFolder = Path.GetFullPath(RootFolder);
                    if (Directory.Exists(rootFolder))
                    {
                        if (!rootFolder.EndsWith(Path.DirectorySeparatorChar.ToString()) && !rootFolder.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
                        {
                            rootFolder = rootFolder + Path.DirectorySeparatorChar;
                        }

                        path = new Url(rootFolder).MakeRelative(new Url(path));
                    }
                }

                this.folderTextBox.Text = path;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ShowDefinitionInILSpyCommand"/> class.
        /// Adds our command handlers for menu (commands must exist in the command table file)
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        private ShowDefinitionInILSpyCommand(SpyDefinitionPackage package) : base(package, CommandId)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            this.package = package;

            //OleMenuCommandService commandService =
            //    this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            //if (commandService != null)
            //{
            //    var menuCommandID = new CommandID(ILSpyCommand.CommandSet, CommandId);
            //    var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
            //    commandService.AddCommand(menuItem);
            //}

            _dte = Package.GetGlobalService(typeof(DTE)) as DTE;

            var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));

            this.workspace = componentModel.GetService <VisualStudioWorkspace>() as VisualStudioWorkspace;
        }
 private SnowParticle NewParticle()
 {
     return(new SnowParticle(_adornmentLayer,
                             (DTE)Package.GetGlobalService(typeof(DTE)),
                             particle => _explosionParticles.Add(particle)));
 }