mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04:00
Possible fix for constant source generator crashes
This commit is contained in:
@@ -64,7 +64,9 @@ public class CmdAttribute : System.Attribute
|
|||||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||||
{
|
{
|
||||||
// #if DEBUG
|
// #if DEBUG
|
||||||
// SpinWait.SpinUntil(() => Debugger.IsAttached);
|
// if (!Debugger.IsAttached)
|
||||||
|
// Debugger.Launch();
|
||||||
|
// // SpinWait.SpinUntil(() => Debugger.IsAttached);
|
||||||
// #endif
|
// #endif
|
||||||
context.RegisterPostInitializationOutput(static ctx => ctx.AddSource(
|
context.RegisterPostInitializationOutput(static ctx => ctx.AddSource(
|
||||||
"CmdAttribute.g.cs",
|
"CmdAttribute.g.cs",
|
||||||
@@ -157,7 +159,8 @@ public class CmdAttribute : System.Attribute
|
|||||||
.Distinct();
|
.Distinct();
|
||||||
|
|
||||||
var methodModels = methods
|
var methodModels = methods
|
||||||
.Select(x => MethodDeclarationToMethodModel(compilation, x!));
|
.Select(x => MethodDeclarationToMethodModel(compilation, x!))
|
||||||
|
.Where(static x => x is not null);
|
||||||
|
|
||||||
var groups = methodModels
|
var groups = methodModels
|
||||||
.GroupBy(static x => $"{x.Namespace}.{string.Join(".", x.Classes)}");
|
.GroupBy(static x => $"{x.Namespace}.{string.Join(".", x.Classes)}");
|
||||||
@@ -187,11 +190,21 @@ public class CmdAttribute : System.Attribute
|
|||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodModel MethodDeclarationToMethodModel(Compilation comp, MethodDeclarationSyntax decl)
|
private static MethodModel? MethodDeclarationToMethodModel(Compilation comp, MethodDeclarationSyntax decl)
|
||||||
{
|
{
|
||||||
// SpinWait.SpinUntil(static () => Debugger.IsAttached);
|
// SpinWait.SpinUntil(static () => Debugger.IsAttached);
|
||||||
|
|
||||||
var semanticModel = comp.GetSemanticModel(decl.SyntaxTree);
|
SemanticModel semanticModel;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
semanticModel = comp.GetSemanticModel(decl.SyntaxTree);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// for some reason this method can throw "Not part of this compilation" argument exception
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var methodModel = new MethodModel(
|
var methodModel = new MethodModel(
|
||||||
@params: decl.ParameterList.Parameters
|
@params: decl.ParameterList.Parameters
|
||||||
.Where(p => p.Type is not null)
|
.Where(p => p.Type is not null)
|
||||||
|
Reference in New Issue
Block a user