diff --git a/src/NadekoBot.Generators/Command/CommandAttributesGenerator.cs b/src/NadekoBot.Generators/Command/CommandAttributesGenerator.cs index 53bb53d32..9fee9d79c 100644 --- a/src/NadekoBot.Generators/Command/CommandAttributesGenerator.cs +++ b/src/NadekoBot.Generators/Command/CommandAttributesGenerator.cs @@ -64,7 +64,9 @@ public class CmdAttribute : System.Attribute public void Initialize(IncrementalGeneratorInitializationContext context) { // #if DEBUG -// SpinWait.SpinUntil(() => Debugger.IsAttached); +// if (!Debugger.IsAttached) +// Debugger.Launch(); +// // SpinWait.SpinUntil(() => Debugger.IsAttached); // #endif context.RegisterPostInitializationOutput(static ctx => ctx.AddSource( "CmdAttribute.g.cs", @@ -157,7 +159,8 @@ public class CmdAttribute : System.Attribute .Distinct(); var methodModels = methods - .Select(x => MethodDeclarationToMethodModel(compilation, x!)); + .Select(x => MethodDeclarationToMethodModel(compilation, x!)) + .Where(static x => x is not null); var groups = methodModels .GroupBy(static x => $"{x.Namespace}.{string.Join(".", x.Classes)}"); @@ -187,11 +190,21 @@ public class CmdAttribute : System.Attribute return models; } - private static MethodModel MethodDeclarationToMethodModel(Compilation comp, MethodDeclarationSyntax decl) + private static MethodModel? MethodDeclarationToMethodModel(Compilation comp, MethodDeclarationSyntax decl) { // 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( @params: decl.ParameterList.Parameters .Where(p => p.Type is not null)