Exemplo n.º 1
0
        string GetSignatures(string json)
        {
            PosData posData = GetPosData(json);

            if (posData == null)
            {
                return(null);
            }

            MethodNode methodNode = null;

            SignatureHelp signatures = null;

            int methodIndex = 0;
            int parameterIndex;

            if (posData.SelectedNode != null)
            {
                // Get the signature for the method the cursor is on.
                // Check if the selected node is a method node.
                if (posData.SelectedNode.ElementAtOrDefault(0) is MethodNode)
                {
                    methodNode = (MethodNode)posData.SelectedNode[0];

                    // If the parameters of the method node is not selected and the parent is a method node,
                    // select the parent method node.
                    if (!methodNode.IsParametersSelected(posData.Caret) && posData.SelectedNode.ElementAtOrDefault(1) is MethodNode)
                    {
                        methodNode = (MethodNode)posData.SelectedNode[1];
                        // Get the index of the selected node.
                        parameterIndex = Array.IndexOf(methodNode.Parameters, posData.SelectedNode[0]);
                    }
                    else
                    {
                        if (methodNode.IsNameSelected(posData.Caret))
                        {
                            // If the name is selected, -1 will not highlight any parameters.
                            parameterIndex = -1;
                        }
                        else
                        {
                            // The last parameter is selected.
                            parameterIndex = methodNode.Parameters.Length;
                        }
                    }
                }
                else if (/*parser.Bav.SelectedNode.ElementAtOrDefault(0) is IExpressionNode
                          * &&*/posData.SelectedNode.ElementAtOrDefault(1) is MethodNode)
                {
                    methodNode = (MethodNode)posData.SelectedNode[1];
                    // Get the index of the selected node.
                    parameterIndex = Array.IndexOf(methodNode.Parameters, posData.SelectedNode[0]);
                }
                else
                {
                    parameterIndex = 0;
                }

                SignatureInformation information = null;
                if (methodNode != null)
                {
                    IMethod method = parserData.GetMethod(methodNode.Name);

                    if (method != null)
                    {
                        ParameterInformation[] parameterInfo = new ParameterInformation[method.Parameters.Length];
                        for (int i = 0; i < parameterInfo.Length; i++)
                        {
                            parameterInfo[i] = new ParameterInformation(
                                method.Parameters[i].GetLabel(false),
                                // Every value in the tree can potentially be null.
                                method.Wiki?.Parameters?.ElementAtOrDefault(i)?.Description
                                );
                        }

                        information = new SignatureInformation(
                            method.GetLabel(false),
                            // Get the method's documentation
                            method.Wiki?.Description,
                            // Get the parameter data
                            parameterInfo
                            //method.Wiki?.Parameters?.Select(v => v.ToParameterInformation())
                            //    .ToArray()
                            );
                    }
                }

                signatures = new SignatureHelp
                             (
                    new SignatureInformation[] { information },
                    methodIndex,
                    parameterIndex
                             );
            }

            return(JsonConvert.SerializeObject(signatures));
        }