Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EA layer for ASP.NET Core. #60948

Merged
merged 31 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
05babf3
Initial EA stubs for asp.net
CyrusNajmabadi Apr 25, 2022
7d472e2
Add EA api for Asp.net core classification of Route Syntaxes
CyrusNajmabadi Apr 25, 2022
52834c9
Rename
CyrusNajmabadi Apr 25, 2022
ca267b2
Need to run in remote for classification to work
CyrusNajmabadi Apr 26, 2022
1d5a1ee
model after razor
CyrusNajmabadi Apr 26, 2022
6ec7787
model after razor
CyrusNajmabadi Apr 26, 2022
7ce48e8
Merge remote-tracking branch 'upstream/main' into aspEA
CyrusNajmabadi May 2, 2022
3546034
In progress
CyrusNajmabadi May 2, 2022
18a2f6b
Move 'Identifiers' out of metadata about an embedded lang classifier
CyrusNajmabadi May 2, 2022
7273e7e
Merge branch 'classifierIdentifier' into aspEA
CyrusNajmabadi May 2, 2022
a4ebcb9
In progress
CyrusNajmabadi May 2, 2022
e9bb1bd
Revert "Merge branch 'classifierIdentifier' into aspEA"
CyrusNajmabadi May 2, 2022
f8733b9
In progress
CyrusNajmabadi May 2, 2022
697b37e
Publishing
CyrusNajmabadi May 2, 2022
7f85421
Use restricted IVT
CyrusNajmabadi May 2, 2022
940163c
Update src/Tools/ExternalAccess/AspNetCore/Microsoft.CodeAnalysis.Ext…
CyrusNajmabadi May 2, 2022
d487222
Use EA
CyrusNajmabadi May 2, 2022
ffac814
Merge branch 'aspEA' of https://github.com/CyrusNajmabadi/roslyn into…
CyrusNajmabadi May 2, 2022
b367814
Make optional
CyrusNajmabadi May 2, 2022
a724dc7
Simplify
CyrusNajmabadi May 2, 2022
854deef
Make normal EA ivt
CyrusNajmabadi May 2, 2022
171255c
Add docs
CyrusNajmabadi May 2, 2022
28fce58
Add docs
CyrusNajmabadi May 2, 2022
5f7cc41
Update src/Tools/ExternalAccess/AspNetCore/EmbeddedLanguages/AspNetCo…
CyrusNajmabadi May 3, 2022
134cd74
Merge remote-tracking branch 'upstream/main' into aspEA
CyrusNajmabadi May 3, 2022
b3b6d4d
Merge remote-tracking branch 'upstream/main' into aspEA
CyrusNajmabadi May 3, 2022
62468e7
Simplify
CyrusNajmabadi May 3, 2022
e63c46d
Simplify
CyrusNajmabadi May 3, 2022
0247986
Merge remote-tracking branch 'upstream/main' into aspEA
CyrusNajmabadi May 4, 2022
6e8ebd5
Fix
CyrusNajmabadi May 4, 2022
04af109
Fix
CyrusNajmabadi May 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 86 additions & 79 deletions Roslyn.sln

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions eng/config/PublishData.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Microsoft.CodeAnalysis.ExternalAccess.ProjectSystem": "vs-impl",
"Microsoft.CodeAnalysis.ExternalAccess.OmniSharp": "arcade",
"Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.CSharp": "arcade",
"Microsoft.CodeAnalysis.ExternalAccess.AspNetCore": "vs-impl",
"Microsoft.CodeAnalysis.ExternalAccess.Razor": "vs-impl",
"Microsoft.CodeAnalysis.ExternalAccess.TypeScript": "vs-impl",
"Microsoft.CodeAnalysis.ExternalAccess.UnitTesting": "vs-impl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<!-- BEGIN External Access -->
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.CSharp" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.OmniSharp.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.AspNetCore" />
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.Razor" />
<!-- END External Access -->
<!-- BEGIN MONODEVELOP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,8 @@ private static ImmutableArray<CodeRefactoringProvider> GetProjectRefactorings(Pr
private class ProjectCodeRefactoringProvider
: AbstractProjectExtensionProvider<ProjectCodeRefactoringProvider, CodeRefactoringProvider, ExportCodeRefactoringProviderAttribute>
{
protected override bool SupportsLanguage(ExportCodeRefactoringProviderAttribute exportAttribute, string language)
{
return exportAttribute.Languages == null
|| exportAttribute.Languages.Length == 0
|| exportAttribute.Languages.Contains(language);
}
protected override ImmutableArray<string> GetLanguages(ExportCodeRefactoringProviderAttribute exportAttribute)
=> exportAttribute.Languages.ToImmutableArray();

protected override bool TryGetExtensionsFromReference(AnalyzerReference reference, out ImmutableArray<CodeRefactoringProvider> extensions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Runtime.CompilerServices;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis
{
Expand All @@ -25,7 +26,7 @@ internal abstract class AbstractProjectExtensionProvider<TProvider, TExtension,
private AnalyzerReference Reference { get; init; } = null!;
private ImmutableDictionary<string, ImmutableArray<TExtension>> _extensionsPerLanguage = ImmutableDictionary<string, ImmutableArray<TExtension>>.Empty;

protected abstract bool SupportsLanguage(TExportAttribute exportAttribute, string language);
protected abstract ImmutableArray<string> GetLanguages(TExportAttribute exportAttribute);
protected abstract bool TryGetExtensionsFromReference(AnalyzerReference reference, out ImmutableArray<TExtension> extensions);

public static ImmutableArray<TExtension> GetExtensions(Project? project)
Expand Down Expand Up @@ -83,9 +84,11 @@ private ImmutableArray<TExtension> CreateExtensions(string language)
try
{
var attribute = typeInfo.GetCustomAttribute<TExportAttribute>();
if (attribute is not null && SupportsLanguage(attribute, language))
if (attribute is not null)
{
builder.AddIfNotNull((TExtension?)Activator.CreateInstance(typeInfo.AsType()));
var languages = GetLanguages(attribute);
if (languages.Contains(language))
builder.AddIfNotNull((TExtension?)Activator.CreateInstance(typeInfo.AsType()));
}
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,8 @@ int IEqualityComparer<ImmutableHashSet<string>>.GetHashCode([DisallowNull] Immut
private sealed class ProjectCompletionProvider
: AbstractProjectExtensionProvider<ProjectCompletionProvider, CompletionProvider, ExportCompletionProviderAttribute>
{
protected override bool SupportsLanguage(ExportCompletionProviderAttribute exportAttribute, string language)
{
return exportAttribute.Language == null
|| exportAttribute.Language.Length == 0
|| exportAttribute.Language.Contains(language);
}
protected override ImmutableArray<string> GetLanguages(ExportCompletionProviderAttribute exportAttribute)
=> ImmutableArray.Create(exportAttribute.Language);

protected override bool TryGetExtensionsFromReference(AnalyzerReference reference, out ImmutableArray<CompletionProvider> extensions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<RestrictedInternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServerClient.Razor" Partner="Razor" Key="$(RazorKey)" />
<RestrictedInternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServerClient.Razor.Test" Partner="Razor" Key="$(RazorKey)" />
<InternalsVisibleTo Include="IdeCoreBenchmarks" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.AspNetCore" />
Copy link
Contributor

@mavasani mavasani Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, should be RestrictedInternalsVisibleTo similar to two lines above, otherwise this is just a regular IVT with access to full internal surface area, and having an ExternalAccess layer serves no purpose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrmm... i couldn't get thsi to work. are you sure that's the right pattern here? i'm creating a new EA lib that should have IVT to our libs. but it's that lib htat we can then audit to make sure it is not further exposing things outwards that it shoudln't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ RestrictedInternalsVisibleTo is only applicable to cases where we cannot create a new assembly. (marking unresolved just for visibility)

<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.Razor" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.Razor.UnitTests" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ internal partial class CodeFixService
private class ProjectCodeFixProvider
: AbstractProjectExtensionProvider<ProjectCodeFixProvider, CodeFixProvider, ExportCodeFixProviderAttribute>
{
protected override bool SupportsLanguage(ExportCodeFixProviderAttribute exportAttribute, string language)
{
return exportAttribute.Languages == null
|| exportAttribute.Languages.Length == 0
|| exportAttribute.Languages.Contains(language);
}
protected override ImmutableArray<string> GetLanguages(ExportCodeFixProviderAttribute exportAttribute)
=> exportAttribute.Languages.ToImmutableArray();

protected override bool TryGetExtensionsFromReference(AnalyzerReference reference, out ImmutableArray<CodeFixProvider> extensions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.EditorFeatures.Test.Utilities2" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.EditorFeatures.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.EditorFeatures2.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.AspNetCore" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.Razor" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.FSharp" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.CSharp.EditorFeatures" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<ProjectReference Include="..\..\Scripting\CSharp\Microsoft.CodeAnalysis.CSharp.Scripting.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Tools\ExternalAccess\Apex\Microsoft.CodeAnalysis.ExternalAccess.Apex.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Tools\ExternalAccess\Debugger\Microsoft.CodeAnalysis.ExternalAccess.Debugger.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Tools\ExternalAccess\AspNetCore\Microsoft.CodeAnalysis.ExternalAccess.AspNetCore.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Tools\ExternalAccess\FSharp\Microsoft.CodeAnalysis.ExternalAccess.FSharp.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\Tools\ExternalAccess\Razor\Microsoft.CodeAnalysis.ExternalAccess.Razor.csproj" PrivateAssets="all" />
<ProjectReference Include="..\..\VisualStudio\LiveShare\Impl\Microsoft.VisualStudio.LanguageServices.LiveShare.csproj" PrivateAssets="all" />
Expand Down Expand Up @@ -75,6 +76,7 @@
<_File Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.EditorFeatures\$(Configuration)\netstandard2.0\Microsoft.CodeAnalysis.EditorFeatures.dll" TargetDir="" />
<_File Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.ExternalAccess.Apex\$(Configuration)\net472\Microsoft.CodeAnalysis.ExternalAccess.Apex.dll" TargetDir="" />
<_File Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.ExternalAccess.Debugger\$(Configuration)\netstandard2.0\Microsoft.CodeAnalysis.ExternalAccess.Debugger.dll" TargetDir="" />
<_File Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.ExternalAccess.AspNetCore\$(Configuration)\netstandard2.0\Microsoft.CodeAnalysis.ExternalAccess.AspNetCore.dll" TargetDir="" />
<_File Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.ExternalAccess.FSharp\$(Configuration)\net472\Microsoft.CodeAnalysis.ExternalAccess.FSharp.dll" TargetDir="" />
<_File Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.ExternalAccess.Razor\$(Configuration)\netstandard2.0\Microsoft.CodeAnalysis.ExternalAccess.Razor.dll" TargetDir="" />
<_File Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.Features\$(Configuration)\netstandard2.0\Microsoft.CodeAnalysis.Features.dll" TargetDir="" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.ExternalAccess.AspNetCore.EmbeddedLanguages
{
internal readonly struct AspNetCoreEmbeddedLanguageClassificationContext
{
private readonly EmbeddedLanguageClassificationContext _context;

public AspNetCoreEmbeddedLanguageClassificationContext(EmbeddedLanguageClassificationContext context)
{
_context = context;
}

/// <inheritdoc cref="EmbeddedLanguageClassificationContext.SyntaxToken"/>
public SyntaxToken SyntaxToken => _context.SyntaxToken;

/// <inheritdoc cref="EmbeddedLanguageClassificationContext.SemanticModel"/>
public SemanticModel SemanticModel => _context.SemanticModel;

/// <inheritdoc cref="EmbeddedLanguageClassificationContext.CancellationToken"/>
public CancellationToken CancellationToken => _context.CancellationToken;

public void AddClassification(string classificationType, TextSpan span)
=> _context.AddClassification(classificationType, span);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Composition;

namespace Microsoft.CodeAnalysis.ExternalAccess.AspNetCore.EmbeddedLanguages
{
/// <summary>
/// Use this attribute to export a <see cref="IAspNetCoreEmbeddedLanguageClassifier"/>.
/// </summary>
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class)]
internal class ExportAspNetCoreEmbeddedLanguageClassifierAttribute : ExportAttribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
internal class ExportAspNetCoreEmbeddedLanguageClassifierAttribute : ExportAttribute
internal sealed class ExportAspNetCoreEmbeddedLanguageClassifierAttribute : ExportAttribute

{
/// <summary>
/// Name of the classifier.
/// </summary>
public string Name { get; }

/// <summary>
/// Name of the containing language hosting the embedded language. e.g. C# or VB.
/// </summary>
public string Language { get; }

public ExportAspNetCoreEmbeddedLanguageClassifierAttribute(
string name, string language)
: base(typeof(IAspNetCoreEmbeddedLanguageClassifier))
{
Name = name ?? throw new ArgumentNullException(nameof(name));
Language = language ?? throw new ArgumentNullException(nameof(language));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CodeAnalysis.Classification;

namespace Microsoft.CodeAnalysis.ExternalAccess.AspNetCore.EmbeddedLanguages
{
/// <inheritdoc cref="IEmbeddedLanguageClassifier"/>
internal interface IAspNetCoreEmbeddedLanguageClassifier
{
/// <inheritdoc cref="IEmbeddedLanguageClassifier.RegisterClassifications"/>
void RegisterClassifications(AspNetCoreEmbeddedLanguageClassificationContext context);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading