Skip to content

Commit 23dd559

Browse files
Batch all DesignerAttribute changes
1 parent 00a4e6b commit 23dd559

File tree

10 files changed

+264
-249
lines changed

10 files changed

+264
-249
lines changed

src/Features/Core/Portable/DesignerAttributes/AbstractDesignerAttributeService.cs

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
using System.Linq;
55
using System.Threading;
66
using System.Threading.Tasks;
7-
using Microsoft.CodeAnalysis.Remote;
87
using Microsoft.CodeAnalysis.Shared.Extensions;
98

109
namespace Microsoft.CodeAnalysis.DesignerAttributes
1110
{
1211
internal struct DesignerAttributeResult
1312
{
13+
public string FilePath;
1414
public string DesignerAttributeArgument;
1515
public bool ContainsErrors;
1616
public bool NotApplicable;
1717

18-
public DesignerAttributeResult(string designerAttributeArgument, bool containsErrors, bool notApplicable)
18+
public DesignerAttributeResult(string filePath, string designerAttributeArgument, bool containsErrors, bool notApplicable)
1919
{
20+
FilePath = filePath;
2021
DesignerAttributeArgument = designerAttributeArgument;
2122
ContainsErrors = containsErrors;
2223
NotApplicable = notApplicable;
@@ -30,32 +31,6 @@ internal abstract class AbstractDesignerAttributeService : IDesignerAttributeSer
3031
protected abstract bool HasAttributesOrBaseTypeOrIsPartial(SyntaxNode typeNode);
3132

3233
public async Task<DesignerAttributeResult> ScanDesignerAttributesAsync(Document document, CancellationToken cancellationToken)
33-
{
34-
var workspace = document.Project.Solution.Workspace;
35-
36-
// same service run in both inproc and remote host, but remote host will not have RemoteHostClient service,
37-
// so inproc one will always run
38-
var client = await workspace.TryGetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false);
39-
if (client != null && !document.IsOpen())
40-
{
41-
// run designer attributes scanner on remote host
42-
// we only run closed files to make open document to have better responsiveness.
43-
// also we cache everything related to open files anyway, no saving by running
44-
// them in remote host
45-
return await ScanDesignerAttributesInRemoteHostAsync(client, document, cancellationToken).ConfigureAwait(false);
46-
}
47-
48-
return await ScanDesignerAttributesInCurrentProcessAsync(document, cancellationToken).ConfigureAwait(false);
49-
}
50-
51-
private async Task<DesignerAttributeResult> ScanDesignerAttributesInRemoteHostAsync(RemoteHostClient client, Document document, CancellationToken cancellationToken)
52-
{
53-
return await client.RunCodeAnalysisServiceOnRemoteHostAsync<DesignerAttributeResult>(
54-
document.Project.Solution, nameof(IRemoteDesignerAttributeService.ScanDesignerAttributesAsync),
55-
document.Id, cancellationToken).ConfigureAwait(false);
56-
}
57-
58-
private async Task<DesignerAttributeResult> ScanDesignerAttributesInCurrentProcessAsync(Document document, CancellationToken cancellationToken)
5934
{
6035
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
6136

@@ -83,7 +58,7 @@ private async Task<DesignerAttributeResult> ScanDesignerAttributesInCurrentProce
8358
{
8459
// The DesignerCategoryAttribute doesn't exist. either not applicable or
8560
// no idea on design attribute status, just leave things as it is.
86-
return new DesignerAttributeResult(designerAttributeArgument, documentHasError, notApplicable: true);
61+
return new DesignerAttributeResult(document.FilePath, designerAttributeArgument, documentHasError, notApplicable: true);
8762
}
8863
}
8964

@@ -114,7 +89,7 @@ private async Task<DesignerAttributeResult> ScanDesignerAttributesInCurrentProce
11489
if (attribute != null && attribute.ConstructorArguments.Length == 1)
11590
{
11691
designerAttributeArgument = GetArgumentString(attribute.ConstructorArguments[0]);
117-
return new DesignerAttributeResult(designerAttributeArgument, documentHasError, notApplicable: false);
92+
return new DesignerAttributeResult(document.FilePath, designerAttributeArgument, documentHasError, notApplicable: false);
11893
}
11994
}
12095
}
@@ -126,7 +101,7 @@ private async Task<DesignerAttributeResult> ScanDesignerAttributesInCurrentProce
126101
}
127102
}
128103

129-
return new DesignerAttributeResult(designerAttributeArgument, documentHasError, notApplicable: false);
104+
return new DesignerAttributeResult(document.FilePath, designerAttributeArgument, documentHasError, notApplicable: false);
130105
}
131106

132107
private static string GetArgumentString(TypedConstant argument)
@@ -141,4 +116,4 @@ private static string GetArgumentString(TypedConstant argument)
141116
return ((string)argument.Value).Trim();
142117
}
143118
}
144-
}
119+
}

src/Features/Core/Portable/DesignerAttributes/IRemoteDesignerAttributeService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace Microsoft.CodeAnalysis.DesignerAttributes
66
{
77
internal interface IRemoteDesignerAttributeService
88
{
9-
Task<DesignerAttributeResult> ScanDesignerAttributesAsync(DocumentId documentId);
9+
Task<DesignerAttributeResult[]> ScanDesignerAttributesAsync(ProjectId projectId);
1010
}
1111
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
3+
using System.Collections.Immutable;
4+
using Microsoft.CodeAnalysis;
5+
using Microsoft.CodeAnalysis.DesignerAttributes;
6+
7+
namespace Microsoft.VisualStudio.LanguageServices.Implementation.DesignerAttribute
8+
{
9+
internal class DesignerAttributeData
10+
{
11+
public readonly VersionStamp SemanticVersion;
12+
public readonly ImmutableDictionary<string, DesignerAttributeResult> PathToResult;
13+
14+
public DesignerAttributeData(VersionStamp semanticVersion, ImmutableDictionary<string, DesignerAttributeResult> pathToResult)
15+
{
16+
SemanticVersion = semanticVersion;
17+
PathToResult = pathToResult;
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)