未验证 提交 715aa4a6 编写于 作者: H Heejae Chang 提交者: GitHub

improve error case handling. (#23243)

when OOP is killed by users, default(DesignerAttributeResult) is returned. it was okay when it was class, but not it being struct, it cause issue because NotApplicable return false rather than true in error case.

so, change NotApplicable to Applicable so that it can handle the error case better.
上级 c125bae3
......@@ -103,7 +103,7 @@ private async Task<DesignerAttributeResult> ScanDesignerAttributesInCurrentProce
{
// The DesignerCategoryAttribute doesn't exist. either not applicable or
// no idea on design attribute status, just leave things as it is.
return new DesignerAttributeResult(designerAttributeArgument, documentHasError, notApplicable: true);
return new DesignerAttributeResult(designerAttributeArgument, documentHasError, applicable: false);
}
}
......@@ -134,7 +134,7 @@ private async Task<DesignerAttributeResult> ScanDesignerAttributesInCurrentProce
if (attribute != null && attribute.ConstructorArguments.Length == 1)
{
designerAttributeArgument = GetArgumentString(attribute.ConstructorArguments[0]);
return new DesignerAttributeResult(designerAttributeArgument, documentHasError, notApplicable: false);
return new DesignerAttributeResult(designerAttributeArgument, documentHasError, applicable: true);
}
}
}
......@@ -146,7 +146,7 @@ private async Task<DesignerAttributeResult> ScanDesignerAttributesInCurrentProce
}
}
return new DesignerAttributeResult(designerAttributeArgument, documentHasError, notApplicable: false);
return new DesignerAttributeResult(designerAttributeArgument, documentHasError, applicable: true);
}
private static string GetArgumentString(TypedConstant argument)
......
......@@ -15,15 +15,15 @@ internal struct DesignerAttributeResult
public bool ContainsErrors { get; }
/// <summary>
/// The document asked is not applicable for the designer attribute
/// The document asked is applicable for the designer attribute
/// </summary>
public bool NotApplicable { get; }
public bool Applicable { get; }
public DesignerAttributeResult(string designerAttributeArgument, bool containsErrors, bool notApplicable)
public DesignerAttributeResult(string designerAttributeArgument, bool containsErrors, bool applicable)
{
DesignerAttributeArgument = designerAttributeArgument;
ContainsErrors = containsErrors;
NotApplicable = notApplicable;
Applicable = applicable;
}
}
}
......@@ -99,7 +99,7 @@ public async Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, In
}
var result = await ScanDesignerAttributesOnRemoteHostIfPossibleAsync(document, cancellationToken).ConfigureAwait(false);
if (result.NotApplicable)
if (!result.Applicable)
{
_state.Remove(document.Id);
return;
......@@ -127,7 +127,7 @@ private async Task<DesignerAttributeResult> ScanDesignerAttributesOnRemoteHostIf
var service = document.GetLanguageService<IDesignerAttributeService>();
if (service == null)
{
return new DesignerAttributeResult(designerAttributeArgument: null, containsErrors: true, notApplicable: true);
return new DesignerAttributeResult(designerAttributeArgument: null, containsErrors: true, applicable: false);
}
return await service.ScanDesignerAttributesAsync(document, cancellationToken).ConfigureAwait(false);
......
......@@ -35,7 +35,7 @@ public Task<DesignerAttributeResult> ScanDesignerAttributesAsync(PinnedSolutionI
return await service.ScanDesignerAttributesAsync(document, token).ConfigureAwait(false);
}
return new DesignerAttributeResult(designerAttributeArgument: null, containsErrors: true, notApplicable: true);
return new DesignerAttributeResult(designerAttributeArgument: null, containsErrors: true, applicable: false);
}
}, cancellationToken);
}
......
......@@ -108,12 +108,12 @@ protected override DesignerAttributeResult ReadValue(JsonReader reader, JsonSeri
var designerAttributeArgument = ReadProperty<string>(reader);
var containsErrors = ReadProperty<bool>(reader);
var notApplicable = ReadProperty<bool>(reader);
var applicable = ReadProperty<bool>(reader);
Contract.ThrowIfFalse(reader.Read());
Contract.ThrowIfFalse(reader.TokenType == JsonToken.EndObject);
return new DesignerAttributeResult(designerAttributeArgument, containsErrors, notApplicable);
return new DesignerAttributeResult(designerAttributeArgument, containsErrors, applicable);
}
protected override void WriteValue(JsonWriter writer, DesignerAttributeResult result, JsonSerializer serializer)
......@@ -126,8 +126,8 @@ protected override void WriteValue(JsonWriter writer, DesignerAttributeResult re
writer.WritePropertyName(nameof(DesignerAttributeResult.ContainsErrors));
writer.WriteValue(result.ContainsErrors);
writer.WritePropertyName(nameof(DesignerAttributeResult.NotApplicable));
writer.WriteValue(result.NotApplicable);
writer.WritePropertyName(nameof(DesignerAttributeResult.Applicable));
writer.WriteValue(result.Applicable);
writer.WriteEndObject();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册