Beispiel #1
0
        protected override void Initialize()
        {
            base.Initialize();

            _foregroundObject = ForegroundThreadAffinitizedObject.Initialize();

            foreach (var editorFactory in CreateEditorFactories())
            {
                RegisterEditorFactory(editorFactory);
            }

            RegisterLanguageService(typeof(TLanguageService), () =>
            {
                // Create the language service, tell it to set itself up, then store it in a field
                // so we can notify it that it's time to clean up.
                _languageService = CreateLanguageService();
                _languageService.Setup();
                return(_languageService.ComAggregate);
            });

            // Okay, this is also a bit strange.  We need to get our Interop dll into our process,
            // but we're in the GAC.  Ask the base Roslyn Package to load, and it will take care of
            // it for us.
            // * NOTE * workspace should never be created before loading roslyn package since roslyn package
            //          installs a service roslyn visual studio workspace requires
            IVsPackage setupPackage;
            var        shell = (IVsShell)this.GetService(typeof(SVsShell));

            shell.LoadPackage(Guids.RoslynPackageId, out setupPackage);

            _miscellaneousFilesWorkspace = this.ComponentModel.GetService <MiscellaneousFilesWorkspace>();
            if (_miscellaneousFilesWorkspace != null)
            {
                // make sure solution crawler start once everything has been setup.
                _miscellaneousFilesWorkspace.StartSolutionCrawler();
            }

            RegisterMiscellaneousFilesWorkspaceInformation(_miscellaneousFilesWorkspace);

            this.Workspace = this.CreateWorkspace();
            if (this.Workspace != null)
            {
                // make sure solution crawler start once everything has been setup.
                // this also should be started before any of workspace events start firing
                this.Workspace.StartSolutionCrawler();
            }

            // Ensure services that must be created on the UI thread have been.
            HACK_AbstractCreateServicesOnUiThread.CreateServicesOnUIThread(ComponentModel, RoslynLanguageName);
        }
Beispiel #2
0
        protected override void Initialize()
        {
            base.Initialize();

            ForegroundThreadAffinitizedObject.Initialize();

            FatalError.Handler         = FailFast.OnFatalException;
            FatalError.NonFatalHandler = WatsonReporter.Report;

            // We also must set the FailFast handler for the compiler layer as well
            var compilerAssembly   = typeof(Compilation).Assembly;
            var compilerFatalError = compilerAssembly.GetType("Microsoft.CodeAnalysis.FatalError", throwOnError: true);
            var property           = compilerFatalError.GetProperty(nameof(FatalError.Handler), BindingFlags.Static | BindingFlags.Public);
            var compilerFailFast   = compilerAssembly.GetType(typeof(FailFast).FullName, throwOnError: true);
            var method             = compilerFailFast.GetMethod(nameof(FailFast.OnFatalException), BindingFlags.Static | BindingFlags.NonPublic);

            property.SetValue(null, Delegate.CreateDelegate(property.PropertyType, method));

            InitializePortableShim(compilerAssembly);

            RegisterFindResultsLibraryManager();

            var componentModel = (IComponentModel)this.GetService(typeof(SComponentModel));

            _workspace = componentModel.GetService <VisualStudioWorkspace>();

            var telemetrySetupExtensions = componentModel.GetExtensions <IRoslynTelemetrySetup>();

            foreach (var telemetrySetup in telemetrySetupExtensions)
            {
                telemetrySetup.Initialize(this);
            }

            // set workspace output pane
            _outputPane = new WorkspaceFailureOutputPane(this, _workspace);

            InitializeColors();

            // load some services that have to be loaded in UI thread
            LoadComponentsInUIContext();

            _solutionEventMonitor = new SolutionEventMonitor(_workspace);
        }
Beispiel #3
0
        /// <summary>
        /// Reset the thread affinity, in particular the designated foreground thread, to the active
        /// thread.
        /// </summary>
        public static void ResetThreadAffinity()
        {
            ForegroundThreadAffinitizedObject.Initialize(force: true);

            // HACK: When the platform team took over several of our components they created a copy
            // of ForegroundThreadAffinitizedObject.  This needs to be reset in the same way as our copy
            // does.  Reflection is the only choice at the moment.
            foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
            {
                var type = assembly.GetType("Microsoft.VisualStudio.Language.Intellisense.Implementation.ForegroundThreadAffinitizedObject", throwOnError: false);
                if (type != null)
                {
                    type.GetField("foregroundThread", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, ForegroundThreadAffinitizedObject.ForegroundThread);
                    type.GetField("ForegroundTaskScheduler", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, ForegroundThreadAffinitizedObject.ForegroundTaskScheduler);

                    break;
                }
            }
        }