提交 5de1ec02 编写于 作者: R Ravi Chande 提交者: GitHub

Merge pull request #12287 from rchande/snippetsAfterSolutionLoad

Initialize snippets after solution load is complete
......@@ -96,6 +96,8 @@ protected override void LoadComponentsInUIContext()
_packageInstallerService?.Connect(this.RoslynLanguageName);
_symbolSearchService?.Connect(this.RoslynLanguageName);
HACK_AbstractCreateServicesOnUiThread.CreateServicesOnUIThread(ComponentModel, RoslynLanguageName);
}
protected abstract VisualStudioWorkspaceImpl CreateWorkspace();
......
......@@ -113,32 +113,16 @@ private void PopulateSnippetCaches()
{
Debug.Assert(_expansionManager != null);
// If the expansion manager is an IExpansionManager, then we can use the asynchronous
// population mechanism it provides. Otherwise, getting snippet information from the
// IVsExpansionManager must be done synchronously on the UI thread.
// IExpansionManager was introduced in Visual Studio 2015 Update 1, but will be enabled
// by default for the first time in Visual Studio 2015 Update 2. However, the platform
// still supports returning the IVsExpansionManager if a major problem in the
// IExpansionManager is discovered, so we must continue supporting the fallback.
var token = _waiter.BeginAsyncOperation(GetType().Name + ".Start");
var asyncExpansionManager = _expansionManager as IExpansionManager;
if (asyncExpansionManager != null)
{
// Call the asynchronous IExpansionManager API from a background thread
Task.Run(() => PopulateSnippetCacheAsync(asyncExpansionManager))
.CompletesAsyncOperation(token);
}
else
{
// Call the synchronous IVsExpansionManager API from the UI thread
Task.Factory.StartNew(() => PopulateSnippetCacheOnForeground(_expansionManager),
CancellationToken.None,
TaskCreationOptions.None,
ForegroundTaskScheduler).CompletesAsyncOperation(token);
}
// In Dev14 Update2+ the platform always provides an IExpansion Manager
var asyncExpansionManager = (IExpansionManager)_expansionManager;
// Call the asynchronous IExpansionManager API from a background thread
Task.Factory.StartNew(() => PopulateSnippetCacheAsync(asyncExpansionManager),
CancellationToken.None,
TaskCreationOptions.None,
TaskScheduler.Default).CompletesAsyncOperation(token);
}
private async Task PopulateSnippetCacheAsync(IExpansionManager expansionManager)
......@@ -162,26 +146,6 @@ private async Task PopulateSnippetCacheAsync(IExpansionManager expansionManager)
ForegroundTaskScheduler).ConfigureAwait(false);
}
/// <remarks>
/// Changes to the <see cref="IVsExpansionManager.EnumerateExpansions"/> invocation
/// should also be made to the IExpansionManager.EnumerateExpansionsAsync
/// invocation in <see cref="PopulateSnippetCacheAsync(IExpansionManager)"/>.
/// </remarks>
private void PopulateSnippetCacheOnForeground(IVsExpansionManager expansionManager)
{
AssertIsForeground();
expansionManager.EnumerateExpansions(
_languageGuidForSnippets,
fShortCutOnly: 0,
bstrTypes: null,
iCountTypes: 0,
fIncludeNULLType: 1,
fIncludeDuplicates: 1, // Allows snippets with the same title but different shortcuts
pEnum: out var expansionEnumerator);
PopulateSnippetCacheFromExpansionEnumeration(expansionEnumerator);
}
/// <remarks>
/// This method must be called on the UI thread because it eventually calls into
/// IVsExpansionEnumeration.Next, which must be called on the UI thread due to an issue
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册