提交 8b303f57 编写于 作者: C CyrusNajmabadi

Merge pull request #5626 from CyrusNajmabadi/workspaceOpenDocument

Provide a better exception message.  Fixes #4613
......@@ -8,6 +8,7 @@
using EnvDTE;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Notification;
......@@ -47,6 +48,8 @@ internal abstract class VisualStudioWorkspaceImpl : VisualStudioWorkspace
// document worker coordinator
private ISolutionCrawlerRegistrationService _registrationService;
private readonly ForegroundThreadAffinitizedObject foregroundObject = new ForegroundThreadAffinitizedObject();
public VisualStudioWorkspaceImpl(
SVsServiceProvider serviceProvider,
WorkspaceBackgroundWork backgroundWork)
......@@ -672,6 +675,11 @@ public void OpenDocumentCore(DocumentId documentId, bool activate = true)
throw new ArgumentNullException(nameof(documentId));
}
if (!foregroundObject.IsForeground())
{
throw new InvalidOperationException(ServicesVSResources.ThisWorkspaceOnlySupportsOpeningDocumentsOnTheUIThread);
}
var document = this.GetHostDocument(documentId);
if (document != null && document.Project != null)
{
......
......@@ -1083,6 +1083,15 @@ internal class ServicesVSResources {
}
}
/// <summary>
/// Looks up a localized string similar to This workspace only supports opening documents on the UI thread..
/// </summary>
internal static string ThisWorkspaceOnlySupportsOpeningDocumentsOnTheUIThread {
get {
return ResourceManager.GetString("ThisWorkspaceOnlySupportsOpeningDocumentsOnTheUIThread", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to C#/VB Todo List Table Data Source.
/// </summary>
......
......@@ -501,8 +501,10 @@ Use the dropdown to view and switch to other projects this file may belong to.</
<data name="ComputingRemoveSuppressionFix" xml:space="preserve">
<value>Computing remove suppressions fix...</value>
</data>
<data name="ApplyingRemoveSuppressionFix" xml:space="preserve">
<data name="ApplyingRemoveSuppressionFix" xml:space="preserve">
<value>Applying remove suppressions fix...</value>
</data>
<data name="ThisWorkspaceOnlySupportsOpeningDocumentsOnTheUIThread" xml:space="preserve">
<value>This workspace only supports opening documents on the UI thread.</value>
</data>
</root>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册