Exemple #1
0
        private void InitializeServiceOnDocumentOpened(object sender, DocumentEventArgs e)
        {
            if (e.Document.Project.Language != _languageName)
            {
                return;
            }

            var token = _listener.BeginAsyncOperation(nameof(InitializeServiceForOpenedDocumentOnBackgroundAsync));

            InitializeServiceForOpenedDocumentOnBackgroundAsync(e.Document).CompletesAsyncOperation(token);

            async Task InitializeServiceForOpenedDocumentOnBackgroundAsync(Document document)
            {
                await TaskScheduler.Default;

                // Preload project completion providers on a background thread since loading extensions can be slow
                // https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1488945
                if (document.GetLanguageService <CompletionService>() is not null)
                {
                    _ = CompletionService.GetProjectCompletionProviders(document.Project);
                }

                await InitializeServiceForOpenedDocumentAsync(document).ConfigureAwait(false);
            }
        }