Skip to content

Commit

Permalink
Batch all DesignerAttribute changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed May 2, 2017
1 parent 00a4e6b commit 23dd559
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Remote;
using Microsoft.CodeAnalysis.Shared.Extensions;

namespace Microsoft.CodeAnalysis.DesignerAttributes
{
internal struct DesignerAttributeResult
{
public string FilePath;
public string DesignerAttributeArgument;
public bool ContainsErrors;
public bool NotApplicable;

public DesignerAttributeResult(string designerAttributeArgument, bool containsErrors, bool notApplicable)
public DesignerAttributeResult(string filePath, string designerAttributeArgument, bool containsErrors, bool notApplicable)
{
FilePath = filePath;
DesignerAttributeArgument = designerAttributeArgument;
ContainsErrors = containsErrors;
NotApplicable = notApplicable;
Expand All @@ -30,32 +31,6 @@ internal abstract class AbstractDesignerAttributeService : IDesignerAttributeSer
protected abstract bool HasAttributesOrBaseTypeOrIsPartial(SyntaxNode typeNode);

public async Task<DesignerAttributeResult> ScanDesignerAttributesAsync(Document document, CancellationToken cancellationToken)
{
var workspace = document.Project.Solution.Workspace;

// same service run in both inproc and remote host, but remote host will not have RemoteHostClient service,
// so inproc one will always run
var client = await workspace.TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false);
if (client != null && !document.IsOpen())
{
// run designer attributes scanner on remote host
// we only run closed files to make open document to have better responsiveness.
// also we cache everything related to open files anyway, no saving by running
// them in remote host
return await ScanDesignerAttributesInRemoteHostAsync(client, document, cancellationToken).ConfigureAwait(false);
}

return await ScanDesignerAttributesInCurrentProcessAsync(document, cancellationToken).ConfigureAwait(false);
}

private async Task<DesignerAttributeResult> ScanDesignerAttributesInRemoteHostAsync(RemoteHostClient client, Document document, CancellationToken cancellationToken)
{
return await client.RunCodeAnalysisServiceOnRemoteHostAsync<DesignerAttributeResult>(
document.Project.Solution, nameof(IRemoteDesignerAttributeService.ScanDesignerAttributesAsync),
document.Id, cancellationToken).ConfigureAwait(false);
}

private async Task<DesignerAttributeResult> ScanDesignerAttributesInCurrentProcessAsync(Document document, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false);

Expand Down Expand Up @@ -83,7 +58,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(document.FilePath, designerAttributeArgument, documentHasError, notApplicable: true);
}
}

Expand Down Expand Up @@ -114,7 +89,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(document.FilePath, designerAttributeArgument, documentHasError, notApplicable: false);
}
}
}
Expand All @@ -126,7 +101,7 @@ private async Task<DesignerAttributeResult> ScanDesignerAttributesInCurrentProce
}
}

return new DesignerAttributeResult(designerAttributeArgument, documentHasError, notApplicable: false);
return new DesignerAttributeResult(document.FilePath, designerAttributeArgument, documentHasError, notApplicable: false);
}

private static string GetArgumentString(TypedConstant argument)
Expand All @@ -141,4 +116,4 @@ private static string GetArgumentString(TypedConstant argument)
return ((string)argument.Value).Trim();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace Microsoft.CodeAnalysis.DesignerAttributes
{
internal interface IRemoteDesignerAttributeService
{
Task<DesignerAttributeResult> ScanDesignerAttributesAsync(DocumentId documentId);
Task<DesignerAttributeResult[]> ScanDesignerAttributesAsync(ProjectId projectId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.DesignerAttributes;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.DesignerAttribute
{
internal class DesignerAttributeData
{
public readonly VersionStamp SemanticVersion;
public readonly ImmutableDictionary<string, DesignerAttributeResult> PathToResult;

public DesignerAttributeData(VersionStamp semanticVersion, ImmutableDictionary<string, DesignerAttributeResult> pathToResult)
{
SemanticVersion = semanticVersion;
PathToResult = pathToResult;
}
}
}
Loading

0 comments on commit 23dd559

Please sign in to comment.