提交 8d65147b 编写于 作者: D dpoeschl

Bugfix 1084179: "[Feedback] Visual Studio crash opening specific large project"

TextDocumentState.LoadTextAsync previously allowed InvalidDataExceptions to optionally propagate out. It now always catches InvalidDataExceptions and returns an empty SourceText. It also supports an option for reporting the exception as a WorkspaceFailed event. DocumentState reports the exception, while TextDocumentState does not. (changeset 1389074)
上级 07557aed
......@@ -44,7 +44,7 @@ internal partial class DocumentState : TextDocumentState
SolutionServices services)
{
var textSource = info.TextLoader != null
? CreateRecoverableText(info.TextLoader, info.Id, services)
? CreateRecoverableText(info.TextLoader, info.Id, services, reportInvalidDataException: true)
: CreateStrongText(TextAndVersion.Create(SourceText.From(string.Empty, Encoding.UTF8), VersionStamp.Default, info.FilePath));
var treeSource = CreateLazyFullyParsedTree(
......@@ -329,8 +329,8 @@ public new DocumentState UpdateText(TextLoader loader, PreservationMode mode)
}
var newTextSource = (mode == PreservationMode.PreserveIdentity)
? CreateStrongText(loader, this.Id, this.solutionServices)
: CreateRecoverableText(loader, this.Id, this.solutionServices);
? CreateStrongText(loader, this.Id, this.solutionServices, reportInvalidDataException: true)
: CreateRecoverableText(loader, this.Id, this.solutionServices, reportInvalidDataException: true);
var newTreeSource = CreateLazyFullyParsedTree(
newTextSource,
......
......@@ -56,7 +56,7 @@ public string Name
public static TextDocumentState Create(DocumentInfo info, SolutionServices services)
{
var textSource = info.TextLoader != null
? CreateRecoverableText(info.TextLoader, info.Id, services, catchInvalidDataException: true)
? CreateRecoverableText(info.TextLoader, info.Id, services, reportInvalidDataException: false)
: CreateStrongText(TextAndVersion.Create(SourceText.From(string.Empty, Encoding.UTF8), VersionStamp.Default, info.FilePath));
// remove any initial loader so we don't keep source alive
......@@ -73,9 +73,9 @@ protected static ValueSource<TextAndVersion> CreateStrongText(TextAndVersion tex
return new ConstantValueSource<TextAndVersion>(text);
}
protected static ValueSource<TextAndVersion> CreateStrongText(TextLoader loader, DocumentId documentId, SolutionServices services, bool catchInvalidDataException = false)
protected static ValueSource<TextAndVersion> CreateStrongText(TextLoader loader, DocumentId documentId, SolutionServices services, bool reportInvalidDataException)
{
return new AsyncLazy<TextAndVersion>(c => LoadTextAsync(loader, documentId, services, c, catchInvalidDataException), cacheResult: true);
return new AsyncLazy<TextAndVersion>(c => LoadTextAsync(loader, documentId, services, reportInvalidDataException, c), cacheResult: true);
}
protected static ValueSource<TextAndVersion> CreateRecoverableText(TextAndVersion text, SolutionServices services)
......@@ -83,14 +83,14 @@ protected static ValueSource<TextAndVersion> CreateRecoverableText(TextAndVersio
return new RecoverableTextAndVersion(CreateStrongText(text), services.TemporaryStorage);
}
protected static ValueSource<TextAndVersion> CreateRecoverableText(TextLoader loader, DocumentId documentId, SolutionServices services, bool catchInvalidDataException = false)
protected static ValueSource<TextAndVersion> CreateRecoverableText(TextLoader loader, DocumentId documentId, SolutionServices services, bool reportInvalidDataException)
{
return new RecoverableTextAndVersion(
new AsyncLazy<TextAndVersion>(c => LoadTextAsync(loader, documentId, services, c, catchInvalidDataException), cacheResult: false),
new AsyncLazy<TextAndVersion>(c => LoadTextAsync(loader, documentId, services, reportInvalidDataException, c), cacheResult: false),
services.TemporaryStorage);
}
protected static async Task<TextAndVersion> LoadTextAsync(TextLoader loader, DocumentId documentId, SolutionServices services, CancellationToken cancellationToken, bool catchInvalidDataException = false)
protected static async Task<TextAndVersion> LoadTextAsync(TextLoader loader, DocumentId documentId, SolutionServices services, bool reportInvalidDataException, CancellationToken cancellationToken)
{
try
{
......@@ -110,10 +110,14 @@ protected static async Task<TextAndVersion> LoadTextAsync(TextLoader loader, Doc
services.Workspace.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.Failure, e.Message, documentId));
return TextAndVersion.Create(SourceText.From(string.Empty, Encoding.UTF8), VersionStamp.Default, documentId.GetDebuggerDisplay());
}
catch (InvalidDataException) when (catchInvalidDataException)
catch (InvalidDataException e)
{
// For non-text additional files, create an empty text document.
// TODO: If we add support for non-text additional files in future, remove this catch clause.
// TODO: Adjust this behavior in the future if we add support for non-text additional files
if (reportInvalidDataException)
{
services.Workspace.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.Failure, e.Message, documentId));
}
return TextAndVersion.Create(SourceText.From(string.Empty, Encoding.UTF8), VersionStamp.Default, documentId.GetDebuggerDisplay());
}
}
......@@ -229,8 +233,8 @@ public TextDocumentState UpdateText(TextLoader loader, PreservationMode mode)
// don't blow up on non-text documents.
var newTextSource = (mode == PreservationMode.PreserveIdentity)
? CreateStrongText(loader, this.Id, this.solutionServices, catchInvalidDataException: true)
: CreateRecoverableText(loader, this.Id, this.solutionServices, catchInvalidDataException: true);
? CreateStrongText(loader, this.Id, this.solutionServices, reportInvalidDataException: false)
: CreateRecoverableText(loader, this.Id, this.solutionServices, reportInvalidDataException: false);
return new TextDocumentState(
this.solutionServices,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册