public static ParameterProvider[] GetParameterProviders(ParseInfo parseInfo, Scope methodScope, List <VariableDeclaration> context, bool subroutineParameter)
        {
            if (context == null)
            {
                return(new ParameterProvider[0]);
            }

            var parameters = new ParameterProvider[context.Count];

            for (int i = 0; i < parameters.Length; i++)
            {
                Var newVar;

                ParameterProvider parameter = new ParameterProvider(context[i].Identifier.GetText());

                // Set up the context handler.
                IVarContextHandler contextHandler = new DefineContextHandler(parseInfo.SetRestrictedCallHandler(parameter), context[i]);

                // Normal parameter
                if (!subroutineParameter)
                {
                    newVar = (Var) new ParameterVariable(methodScope, contextHandler, parameter._invoked).GetVar();
                }
                // Subroutine parameter.
                else
                {
                    newVar = (Var) new SubroutineParameterVariable(methodScope, contextHandler).GetVar();
                }

                parameter.Var        = newVar;
                parameter.Type       = newVar.CodeType;
                parameter.Attributes = new ParameterAttributes(newVar.Ref, newVar.VariableType == VariableType.ElementReference);

                if (newVar.InitialValue != null)
                {
                    parameter.DefaultValue = new ExpressionOrWorkshopValue(newVar.InitialValue);
                }

                parameters[i] = parameter;
            }

            return(parameters);
        }
        private DefinedMethodProvider(ParseInfo parseInfo, IScopeHandler scopeProvider, FunctionContext context, IDefinedTypeInitializer containingType)
        {
            _parseInfo     = parseInfo;
            Context        = context;
            ContainingType = containingType;
            CallInfo       = new CallInfo(new RecursiveCallHandler(this, context.Subroutine || context.Attributes.Recursive), parseInfo.Script, ContentReady);

            DocRange nameRange = context.Identifier.Range;

            // Get the attributes.
            var attributes = new GenericAttributeAppender(AttributeType.Ref, AttributeType.In, AttributeType.GlobalVar, AttributeType.PlayerVar);

            AttributesGetter.GetAttributes(parseInfo.Script.Diagnostics, context.Attributes, attributes);

            // Set the attributes.
            Static      = attributes.IsStatic;
            Recursive   = attributes.IsRecursive;
            Virtual     = attributes.IsVirtual;
            AccessLevel = attributes.Accessor;
            Recursive   = attributes.IsRecursive;

            // Get subroutine info.
            if (context.Subroutine)
            {
                IsSubroutine            = true;
                SubroutineName          = context.Subroutine.Text.RemoveQuotes();
                SubroutineDefaultGlobal = !context.PlayerVar;
            }

            // Setup the scope.
            var containingScope = scopeProvider.GetScope(Static);

            containingScope.MethodContainer = true;
            _methodScope = containingScope.Child(true);

            // Get the generics.
            GenericTypes = AnonymousType.GetGenerics(parseInfo, context.TypeArguments, this);
            foreach (var type in GenericTypes)
            {
                _methodScope.AddType(new GenericCodeTypeInitializer(type));
            }

            // Get the type.
            if (!context.Type.IsVoid)
            {
                ReturnType = TypeFromContext.GetCodeTypeFromContext(parseInfo, _methodScope, context.Type);
            }

            // Setup the parameters.
            ParameterProviders = ParameterProvider.GetParameterProviders(parseInfo, _methodScope, context.Parameters, IsSubroutine);
            ParameterTypes     = ParameterProviders.Select(p => p.Type).ToArray();

            // Override
            if (attributes.IsOverride)
            {
                OverridingFunction = (DefinedMethodInstance)scopeProvider.GetOverridenFunction(parseInfo.TranslateInfo, new FunctionOverrideInfo(Name, ParameterTypes));
                if (OverridingFunction == null)
                {
                    SemanticsHelper.CouldNotOverride(parseInfo, nameRange, "method");
                }
            }

            // Check conflicts and add to scope.
            scopeProvider.CheckConflict(parseInfo, new(Name, ParameterTypes), nameRange);
            scopeProvider.Add(GetDefaultInstance(scopeProvider.DefinedIn()), Static);

            // Add LSP elements
            // Hover
            parseInfo.Script.AddHover(nameRange, GetLabel(parseInfo.TranslateInfo, LabelInfo.Hover));
            // 'references' code lens
            parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.Function, DefinedAt.range));
            // Rename & go-to-definition
            parseInfo.Script.Elements.AddDeclarationCall(this, new DeclarationCall(nameRange, true));
            // todo: 'override' code lens
            // if (Attributes.IsOverrideable)
            //     parseInfo.Script.AddCodeLensRange(new ImplementsCodeLensRange(this, parseInfo.Script, CodeLensSourceType.Function, nameRange));

            // Add the CallInfo to the recursion check.
            parseInfo.TranslateInfo.GetComponent <RecursionCheckComponent>().AddCheck(CallInfo);

            // Queue content for staged initiation.
            parseInfo.TranslateInfo.StagedInitiation.On(this);
        }