Fix sample build and rename ScmVisitor to ScmLibraryVisitor (#4125)

This commit is contained in:
JoshLove-msft 2024-08-08 12:10:29 -07:00 коммит произвёл GitHub
Родитель 5abf6dcee0
Коммит 630bdd4041
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
12 изменённых файлов: 22 добавлений и 35 удалений

Просмотреть файл

@ -151,6 +151,7 @@ if ($null -eq $filter) {
$mgcExe = "`$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe"
$sampleExe = "`$(SolutionDir)/../generator/artifacts/bin/SamplePlugin/Debug/net8.0/Microsoft.Generator.CSharp.exe"
$unbrandedSpec = "TestProjects/Local/Unbranded-TypeSpec"
$unbrandedPluginSpec = "TestProjects/Plugin/Unbranded-TypeSpec"
$launchSettings = @{}
$launchSettings.Add("profiles", @{})
@ -159,7 +160,7 @@ if ($null -eq $filter) {
$launchSettings["profiles"]["Unbranded-TypeSpec"].Add("commandName", "Executable")
$launchSettings["profiles"]["Unbranded-TypeSpec"].Add("executablePath", $mgcExe)
$launchSettings["profiles"].Add("Debug-Plugin-Test-TypeSpec", @{})
$launchSettings["profiles"]["Debug-Plugin-Test-TypeSpec"].Add("commandLineArgs", "`$(SolutionDir)/$unbrandedSpec -p SampleCodeModelPlugin")
$launchSettings["profiles"]["Debug-Plugin-Test-TypeSpec"].Add("commandLineArgs", "`$(SolutionDir)/$unbrandedPluginSpec -p SampleCodeModelPlugin")
$launchSettings["profiles"]["Debug-Plugin-Test-TypeSpec"].Add("commandName", "Executable")
$launchSettings["profiles"]["Debug-Plugin-Test-TypeSpec"].Add("executablePath", $sampleExe)

Просмотреть файл

@ -14,7 +14,7 @@ namespace Microsoft.Generator.CSharp.ClientModel.StubLibrary
public override void Configure()
{
AddVisitor(new StubVisitor());
AddVisitor(new StubLibraryVisitor());
}
}
}

Просмотреть файл

@ -9,7 +9,7 @@ using static Microsoft.Generator.CSharp.Snippets.Snippet;
namespace Microsoft.Generator.CSharp.ClientModel.StubLibrary
{
internal class StubVisitor : ScmVisitor
internal class StubLibraryVisitor : ScmLibraryVisitor
{
private readonly ValueExpression _throwNull = ThrowExpression(Null);
private readonly XmlDocProvider _emptyDocs = new();

Просмотреть файл

@ -33,7 +33,7 @@ namespace Microsoft.Generator.CSharp.ClientModel
public override void Configure()
{
AddVisitor(new DefaultScmVisitor());
AddVisitor(new DefaultScmLibraryVisitor());
}
}
}

Просмотреть файл

@ -3,7 +3,7 @@
namespace Microsoft.Generator.CSharp.ClientModel
{
internal class DefaultScmVisitor : ScmVisitor
internal class DefaultScmLibraryVisitor : ScmLibraryVisitor
{
}
}

Просмотреть файл

@ -7,7 +7,7 @@ using Microsoft.Generator.CSharp.Providers;
namespace Microsoft.Generator.CSharp.ClientModel
{
public abstract class ScmVisitor : LibraryVisitor
public abstract class ScmLibraryVisitor : LibraryVisitor
{
protected internal virtual MethodProviderCollection? Visit(InputOperation operation,
TypeProvider enclosingType,

Просмотреть файл

@ -75,7 +75,7 @@ namespace Microsoft.Generator.CSharp.ClientModel
foreach (var visitor in visitors)
{
if (visitor is ScmVisitor scmVisitor)
if (visitor is ScmLibraryVisitor scmVisitor)
{
methods = scmVisitor.Visit(operation, enclosingType, methods);
}

Просмотреть файл

@ -16,7 +16,7 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private Mock<ClientModelPlugin> _mockPlugin;
private Mock<ScmVisitor> _mockVisitor;
private Mock<ScmLibraryVisitor> _mockVisitor;
private Mock<InputLibrary> _mockInputLibrary;
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
@ -25,7 +25,7 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests
{
_mockInputLibrary = new Mock<InputLibrary>();
_mockPlugin = MockHelpers.LoadMockPlugin(createInputLibrary: () => _mockInputLibrary.Object);
_mockVisitor = new Mock<ScmVisitor> { CallBase = true };
_mockVisitor = new Mock<ScmLibraryVisitor> { CallBase = true };
}
[Test]

Просмотреть файл

@ -1,7 +1,7 @@
{
"profiles": {
"Debug-Plugin-Test-TypeSpec": {
"commandLineArgs": "$(SolutionDir)/TestProjects/Local/Unbranded-TypeSpec -p SampleCodeModelPlugin",
"commandLineArgs": "$(SolutionDir)/TestProjects/Plugin/Unbranded-TypeSpec -p SampleCodeModelPlugin",
"commandName": "Executable",
"executablePath": "$(SolutionDir)/../generator/artifacts/bin/SamplePlugin/Debug/net8.0/Microsoft.Generator.CSharp.exe"
},

Просмотреть файл

@ -2,14 +2,16 @@
// Licensed under the MIT License.
using Microsoft.Generator.CSharp;
using Microsoft.Generator.CSharp.ClientModel;
using Microsoft.Generator.CSharp.ClientModel.Providers;
using Microsoft.Generator.CSharp.Input;
using Microsoft.Generator.CSharp.Primitives;
using Microsoft.Generator.CSharp.Providers;
using SamplePlugin.Providers;
namespace SamplePlugin
{
public class SamplePluginLibraryVisitor : LibraryVisitor
public class SamplePluginLibraryLibraryVisitor : ScmLibraryVisitor
{
protected override MethodProvider Visit(TypeProvider typeProvider, MethodProvider methodProvider)
{
@ -26,5 +28,12 @@ namespace SamplePlugin
{
return new SamplePluginPropertyProvider(property);
}
protected override MethodProviderCollection Visit(InputOperation operation,
TypeProvider enclosingType,
MethodProviderCollection? methodProvider)
{
return new SamplePluginMethodProviderCollection(operation, enclosingType);
}
}
}

Просмотреть файл

@ -12,11 +12,9 @@ namespace SamplePlugin
[method: ImportingConstructor]
public class SampleCodeModelPlugin(GeneratorContext context) : ClientModelPlugin(context)
{
public override SamplePluginTypeFactory TypeFactory { get; } = new SamplePluginTypeFactory();
public override void Configure()
{
AddVisitor(new SamplePluginLibraryVisitor());
AddVisitor(new SamplePluginLibraryLibraryVisitor());
}
}
}

Просмотреть файл

@ -1,21 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.Generator.CSharp.ClientModel;
using Microsoft.Generator.CSharp.Input;
using Microsoft.Generator.CSharp.Providers;
using SamplePlugin.Providers;
namespace SamplePlugin
{
public class SamplePluginTypeFactory : ScmTypeFactory
{
/// <summary>
/// Creates a <see cref="MethodProviderCollection"/> for the given operation. If the operation is a <see cref="InputOperationKinds.DefaultValue"/> operation,
/// a method collection will be created. Otherwise, <c>null</c> will be returned.
/// </summary>
/// <param name="operation">The input operation to create methods for.</param>
/// <param name="enclosingType">The enclosing type of the operation.</param>
public override MethodProviderCollection CreateMethods(InputOperation operation, TypeProvider enclosingType) => new SamplePluginMethodProviderCollection(operation, enclosingType);
}
}