Ejemplo n.º 1
0
        private static IEnumerable <ISignature> TransformSignatures(ITextBuffer textBuffer, List <Protocol.Response.ParamHelpResponse.Signature> list, ITrackingSpan applicableTo, int selectedParameterIndex)
        {
            foreach (var item in list)
            {
                var sig           = new JavaMethodSignature(textBuffer);
                var parameterList = new List <IParameter>();

                var content = new StringBuilder();
                content.Append(item.returnValue);
                content.Append(" ");
                content.Append(item.name);

                bool first = true;
                foreach (var param in item.parameters)
                {
                    if (first)
                    {
                        content.Append("(");
                        first = false;
                    }
                    else
                    {
                        content.Append(", ");
                    }
                    content.Append(param.name);

                    var parameter = new JavaMethodParameter(item.description, new Span(content.Length - param.name.Length, param.name.Length), param.name, sig);
                    parameterList.Add(parameter);
                }
                if (first) // no params
                {
                    content.Append("(");
                }
                content.Append(")");

                sig.ApplicableToSpan = applicableTo;
                sig.Content          = content.ToString();
                sig.Parameters       = parameterList.AsReadOnly();
                sig.CurrentParameter = parameterList.Count > 0 ? parameterList.First() : null;
                sig.CurrentParameter = parameterList.Count > selectedParameterIndex ? parameterList[selectedParameterIndex] : null;
                sig.Documentation    = item.description;
                yield return(sig);
            }
        }
Ejemplo n.º 2
0
        public async Task UpdateParameterCount(JavaMethodSignature signature, int position)
        {
            if (signature == null || signature.Parameters.Count == 0)
            {
                return;
            }

            JavaEditor javaEditor = null;

            if (TextBuffer.Properties.TryGetProperty <JavaEditor>(typeof(JavaEditor), out javaEditor))
            {
                var paramsSpan = signature.ApplicableToSpan.GetSpan(TextBuffer.CurrentSnapshot);
                var callSpan   = new Span(paramsSpan.Start - 1, paramsSpan.Length + 2);

                var callText      = TextBuffer.CurrentSnapshot.GetText(callSpan);
                var callPosition  = position - callSpan.Start; // position is relative to the whole document
                var updateRequest = ProtocolHandlers.CreateParamHelpPositionUpdateRequest(callText, callPosition);
                try
                {
                    var updateResponse = await javaEditor.JavaPkgServer.Send(javaEditor, updateRequest);

                    if (updateResponse.responseType == Protocol.Response.ResponseType.ParamHelpPositionUpdate &&
                        updateResponse.paramHelpPositionUpdateResponse != null)
                    {
                        if (updateResponse.paramHelpPositionUpdateResponse.status)
                        {
                            if (signature.Parameters.Count > updateResponse.paramHelpPositionUpdateResponse.paramCount)
                            {
                                signature.CurrentParameter = signature.Parameters[updateResponse.paramHelpPositionUpdateResponse.paramCount];
                            }
                            else
                            {
                                signature.CurrentParameter = signature.Parameters.Last();
                            }
                        }
                    }
                }
                catch (TaskCanceledException tce)
                {
                    // Repeated cursor movement may lead to many update requests. Some will get cancelled by the ServerProxy
                }
            }
        }
Ejemplo n.º 3
0
        public async Task UpdateParameterCount(JavaMethodSignature signature, int position)
        {
            if (signature == null || signature.Parameters.Count == 0)
                return;

            JavaEditor javaEditor = null;
            if (TextBuffer.Properties.TryGetProperty<JavaEditor>(typeof(JavaEditor), out javaEditor))
            {
                var paramsSpan = signature.ApplicableToSpan.GetSpan(TextBuffer.CurrentSnapshot);
                var callSpan = new Span(paramsSpan.Start - 1, paramsSpan.Length + 2);
                
                var callText = TextBuffer.CurrentSnapshot.GetText(callSpan);
                var callPosition = position - callSpan.Start; // position is relative to the whole document
                var updateRequest = ProtocolHandlers.CreateParamHelpPositionUpdateRequest(callText, callPosition);
                try
                {
                    var updateResponse = await javaEditor.JavaPkgServer.Send(javaEditor, updateRequest);

                    if (updateResponse.responseType == Protocol.Response.ResponseType.ParamHelpPositionUpdate &&
                        updateResponse.paramHelpPositionUpdateResponse != null)
                    {
                        if (updateResponse.paramHelpPositionUpdateResponse.status)
                        {
                            if (signature.Parameters.Count > updateResponse.paramHelpPositionUpdateResponse.paramCount)
                                signature.CurrentParameter = signature.Parameters[updateResponse.paramHelpPositionUpdateResponse.paramCount];
                            else
                                signature.CurrentParameter = signature.Parameters.Last();
                        }
                    }
                }
                catch(TaskCanceledException tce)
                {
                    // Repeated cursor movement may lead to many update requests. Some will get cancelled by the ServerProxy
                }
            }
        }
Ejemplo n.º 4
0
        private static IEnumerable<ISignature> TransformSignatures(ITextBuffer textBuffer, List<Protocol.Response.ParamHelpResponse.Signature> list, ITrackingSpan applicableTo, int selectedParameterIndex)
        {
            foreach(var item in list)
            {
                var sig = new JavaMethodSignature(textBuffer);
                var parameterList = new List<IParameter>();

                var content = new StringBuilder();
                content.Append(item.returnValue); 
                content.Append(" ");
                content.Append(item.name);
                
                bool first = true;
                foreach(var param in item.parameters)
                {
                    if (first) 
                    { 
                        content.Append("("); 
                        first = false; 
                    }
                    else 
                        content.Append(", ");
                    content.Append(param.name);
                    
                    var parameter = new JavaMethodParameter(item.description, new Span(content.Length - param.name.Length, param.name.Length), param.name, sig);
                    parameterList.Add(parameter);
                }
                if (first) // no params
                    content.Append("("); 
                content.Append(")");

                sig.ApplicableToSpan = applicableTo;
                sig.Content = content.ToString();
                sig.Parameters = parameterList.AsReadOnly();
                sig.CurrentParameter = parameterList.Count > 0 ? parameterList.First() : null;
                sig.CurrentParameter = parameterList.Count > selectedParameterIndex ? parameterList[selectedParameterIndex] : null;
                sig.Documentation = item.description;
                yield return sig;
            }
        }