public override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf <InvocationExpressionSyntax>(root, context.Span, out var invocation))
            {
                return;
            }

            if (invocation.Expression is MemberAccessExpressionSyntax expression)
            {
                var sm = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);

                var receiver = expression.Expression;
                var t        = ModelExtensions.GetTypeInfo(sm, receiver);
                var document = context.Document.Project.Solution.GetDocument(t.Type.Locations.FirstOrDefault()?.SourceTree);
                if (document == null)
                {
                    return;
                }

                var symbol       = ModelExtensions.GetSymbolInfo(sm, invocation);
                var targetMethod = UdonMethodInvoker.GetTargetMethodName(symbol.Symbol, invocation);

                var diagnostic = context.Diagnostics[0];
                var action     = CreateCodeAction(CodeFixResources.URA0042CodeFixTitle, ct => MakeMethodAsPublic(document, targetMethod, ct), diagnostic.Id);
                context.RegisterCodeFix(action, diagnostic);
            }
        }
예제 #2
0
        private static string GetMissingMethodName(InvocationExpressionSyntax invocation, SemanticModel semanticModel)
        {
            var s = semanticModel.GetSymbolInfo(invocation);

            if (s.Symbol is not IMethodSymbol m)
            {
                return(string.Empty); // UNREACHABLE
            }
            return(UdonMethodInvoker.GetTargetMethodName(m, invocation));
        }