/// <summary>
        /// Determines if the completion string is a valid type and
        /// enumerates the list of completion members on the type
        /// </summary>
        /// <param name="code"> code typed in the code block </param>
        /// <param name="stringToComplete"> Class name or declared variable </param>
        /// <returns> list of method and property members of the type </returns>
        internal IEnumerable <CompletionData> GetCompletionsOnType(string code, string stringToComplete)
        {
            IEnumerable <StaticMirror> members = null;

            // Determine if the string to be completed is a class
            var type = GetClassType(stringToComplete);

            if (type != null)
            {
                members = type.GetMembers();
            }
            // If not of class type
            else
            {
                // Check if the string to be completed is a declared variable
                string typeName = CodeCompletionParser.GetVariableType(code, stringToComplete);
                if (typeName != null)
                {
                    type = GetClassType(typeName);
                }

                if (type != null)
                {
                    members = type.GetInstanceMembers();
                }
            }

            return(members.Select(x => CompletionData.ConvertMirrorToCompletionData(x)));
        }
Beispiel #2
0
        public void TestCodeCompletionParserForVariableType()
        {
            string code         = "a : Point;";
            string variableName = "a";

            Assert.AreEqual("Point", CodeCompletionParser.GetVariableType(code, variableName));

            code = @"a : Point = Point.ByCoordinates();";
            Assert.AreEqual("Point", CodeCompletionParser.GetVariableType(code, variableName));
        }
Beispiel #3
0
        /// <summary>
        /// Returns the list of function signatures of all overloads of a given method
        /// </summary>
        /// <param name="code"> code being typed in code block </param>
        /// <param name="functionName"> given method name for which signature is queried </param>
        /// <param name="functionPrefix"> class name in case of constructor or static method, OR
        /// declared instance variable on which method is invoked </param>
        /// <param name="resolver"></param>
        /// <returns> list of method overload signatures </returns>
        internal IEnumerable <CompletionData> GetFunctionSignatures(string code, string functionName, string functionPrefix,
                                                                    ElementResolver resolver = null)
        {
            IEnumerable <MethodMirror> candidates = null;

            // if function is global, search for function in Built-ins
            if (string.IsNullOrEmpty(functionPrefix))
            {
                return(StaticMirror.GetOverloadsOnBuiltIns(core, functionName).
                       Select(x =>
                {
                    return new CompletionData(x.MethodName, CompletionData.CompletionType.Method)
                    {
                        Stub = x.ToString()
                    };
                }));
            }

            // Determine if the function prefix is a class name
            if (resolver != null)
            {
                functionPrefix = resolver.LookupResolvedName(functionPrefix) ?? functionPrefix;
            }

            var type = GetClassType(functionPrefix);

            if (type != null)
            {
                candidates = type.GetOverloadsOnType(functionName);
            }
            // If not of class type
            else
            {
                // Check if the function prefix is a typed identifier
                string typeName = CodeCompletionParser.GetVariableType(code, functionPrefix);
                if (typeName != null)
                {
                    type = GetClassType(typeName);
                }

                if (type != null)
                {
                    candidates = type.GetOverloadsOnInstance(functionName);
                }
            }
            return(candidates.Select(x => CompletionData.ConvertMirrorToCompletionData(x)));
        }