コード例 #1
0
        private void SystemNameSake(System.Type sType, IList <ISignature> signatures, String elementName, String elementPrototype, bool comma)
        {
            XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpSignatureHelpSource.SystemNameSake()");
            MemberInfo[] members;
            // Get Public, Internal, Protected & Private Members, we also get Instance vars, Static members...all that WITHOUT inheritance
            members = sType.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance
                                       | BindingFlags.Static | BindingFlags.DeclaredOnly);
            //
            bool ctor = false;

            foreach (var member in members.Where(x => nameEquals(x.Name, elementName)))
            {
                if (member.MemberType == MemberTypes.Constructor)
                {
                    ctor = true;
                }
                XSharpLanguage.MemberAnalysis analysis = new XSharpLanguage.MemberAnalysis(member);
                if (analysis.IsInitialized)
                {
                    // But don't add the current one
                    if (String.Compare(elementPrototype, analysis.Prototype, true) != 0)
                    {
                        signatures.Add(CreateSignature(m_textBuffer, analysis.Prototype, "", ApplicableToSpan, comma));
                    }
                }
            }
            // fill members of parent class,but not for constructorsS
            if (sType.BaseType != null && !ctor)
            {
                SystemNameSake(sType.BaseType, signatures, elementName, elementPrototype, comma);
            }
        }
コード例 #2
0
        public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> qiContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;
            if (!XSharpProjectPackage.Instance.DebuggerIsRunning)
            {
                try
                {
                    XSharpModel.ModelWalker.Suspend();
                    var package     = XSharp.Project.XSharpProjectPackage.Instance;
                    var optionsPage = package.GetIntellisenseOptionsPage();
                    if (optionsPage.DisableQuickInfo)
                    {
                        return;
                    }


                    // Map the trigger point down to our buffer.
                    SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(_subjectBuffer.CurrentSnapshot);
                    if (!subjectTriggerPoint.HasValue)
                    {
                        return;
                    }
                    ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot;
                    if (subjectTriggerPoint.Value.Position == lastTriggerPoint)
                    {
                        if (!string.IsNullOrEmpty(lastHelp))
                        {
                            qiContent.Add(lastHelp);
                        }
                        if (lastSpan != null)
                        {
                            applicableToSpan = currentSnapshot.CreateTrackingSpan(
                                lastSpan.GetSpan(currentSnapshot), SpanTrackingMode.EdgeInclusive);
                        }
                        return;
                    }

                    lastTriggerPoint = subjectTriggerPoint.Value.Position;

                    //look for occurrences of our QuickInfo words in the span
                    ITextStructureNavigator navigator = _provider.NavigatorService.GetTextStructureNavigator(_subjectBuffer);
                    TextExtent extent     = navigator.GetExtentOfWord(subjectTriggerPoint.Value);
                    string     searchText = extent.Span.GetText();

                    // First, where are we ?
                    int caretPos   = subjectTriggerPoint.Value.Position;
                    int lineNumber = subjectTriggerPoint.Value.GetContainingLine().LineNumber;
                    var snapshot   = session.TextView.TextBuffer.CurrentSnapshot;
                    if (_file == null)
                    {
                        return;
                    }
                    // Then, the corresponding Type/Element if possible
                    IToken stopToken;
                    //ITokenStream tokenStream;
                    XSharpModel.XTypeMember member           = XSharpLanguage.XSharpTokenTools.FindMember(lineNumber, _file);
                    XSharpModel.XType       currentNamespace = XSharpLanguage.XSharpTokenTools.FindNamespace(caretPos, _file);
                    // adjust caretpos, for other completions we need to stop before the caret. Now we include the caret
                    List <String> tokenList = XSharpLanguage.XSharpTokenTools.GetTokenList(caretPos + 1, lineNumber, snapshot, out stopToken, true, _file, false, member);
                    // Check if we can get the member where we are
                    //if (tokenList.Count > 1)
                    //{
                    //    tokenList.RemoveRange(0, tokenList.Count - 1);
                    //}
                    // LookUp for the BaseType, reading the TokenList (From left to right)
                    XSharpLanguage.CompletionElement gotoElement;
                    String currentNS = "";
                    if (currentNamespace != null)
                    {
                        currentNS = currentNamespace.Name;
                    }

                    XSharpModel.CompletionType cType = XSharpLanguage.XSharpTokenTools.RetrieveType(_file, tokenList, member, currentNS, stopToken, out gotoElement, snapshot, lineNumber);
                    //
                    //
                    if ((gotoElement != null) && (gotoElement.IsInitialized))
                    {
                        // Ok, find it ! Let's go ;)
                        applicableToSpan = currentSnapshot.CreateTrackingSpan
                                           (
                            extent.Span.Start, searchText.Length, SpanTrackingMode.EdgeInclusive
                                           );

                        if (gotoElement.XSharpElement != null)
                        {
                            if (gotoElement.XSharpElement.Kind == XSharpModel.Kind.Constructor)
                            {
                                if (gotoElement.XSharpElement.Parent != null)
                                {
                                    qiContent.Add(gotoElement.XSharpElement.Parent.Description);
                                }
                            }
                            else
                            {
                                qiContent.Add(gotoElement.XSharpElement.Description);
                            }
                        }
                        else if (gotoElement.SystemElement is TypeInfo)
                        {
                            XSharpLanguage.TypeAnalysis analysis = new XSharpLanguage.TypeAnalysis((TypeInfo)gotoElement.SystemElement);
                            qiContent.Add(analysis.Description);
                        }
                        else
                        {
                            // This works with System.MemberInfo AND
                            XSharpLanguage.MemberAnalysis analysis = null;
                            if (gotoElement.SystemElement is MemberInfo)
                            {
                                analysis = new XSharpLanguage.MemberAnalysis(gotoElement.SystemElement);
                                if (analysis.IsInitialized)
                                {
                                    if ((analysis.Kind == XSharpModel.Kind.Constructor) && (cType != null) && (cType.SType != null))
                                    {
                                        XSharpLanguage.TypeAnalysis typeAnalysis;
                                        typeAnalysis = new XSharpLanguage.TypeAnalysis(cType.SType.GetTypeInfo());
                                        if (typeAnalysis.IsInitialized)
                                        {
                                            qiContent.Add(typeAnalysis.Description);
                                        }
                                    }
                                    else
                                    {
                                        qiContent.Add(analysis.Description);
                                    }
                                }
                            }
                        }
                        if (qiContent.Count > 0)
                        {
                            lastHelp = (string)qiContent[0];
                            lastSpan = applicableToSpan;
                        }
                        return;
                    }
                }
                catch (Exception ex)
                {
                    XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpQuickInfo.AugmentQuickInfoSession failed : ");
                    XSharpProjectPackage.Instance.DisplayException(ex);
                }
                finally
                {
                    XSharpModel.ModelWalker.Resume();
                }
            }
        }
コード例 #3
0
        public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures)
        {
            try
            {
                XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpSignatureHelpSource.AugmentSignatureHelpSession()");
                XSharpModel.ModelWalker.Suspend();
                ITextSnapshot snapshot = m_textBuffer.CurrentSnapshot;
                int           position = session.GetTriggerPoint(m_textBuffer).GetPosition(snapshot);
                int           start    = (int)session.Properties["Start"];
                int           length   = (int)session.Properties["Length"];
                var           comma    = (bool)session.Properties["Comma"];
                m_applicableToSpan = m_textBuffer.CurrentSnapshot.CreateTrackingSpan(
                    new Span(start, length), SpanTrackingMode.EdgeInclusive, 0);

                object elt = session.Properties["Element"];
                m_session = session;
                if (elt is XSharpModel.XElement)
                {
                    XSharpModel.XElement element = elt as XSharpModel.XElement;
                    signatures.Add(CreateSignature(m_textBuffer, element.Prototype, "", ApplicableToSpan, comma));
                    //
                    if (elt is XSharpModel.XTypeMember)
                    {
                        XSharpModel.XTypeMember        xMember  = elt as XSharpModel.XTypeMember;
                        List <XSharpModel.XTypeMember> namesake = xMember.Namesake();
                        foreach (var member in namesake)
                        {
                            signatures.Add(CreateSignature(m_textBuffer, member.Prototype, "", ApplicableToSpan, comma));
                        }
                        //
                    }
                    // why not ?
                    int paramCount = int.MaxValue;
                    foreach (ISignature sig in signatures)
                    {
                        if (sig.Parameters.Count < paramCount)
                        {
                            paramCount = sig.Parameters.Count;
                        }
                    }
                    //
                    m_textBuffer.Changed += new EventHandler <TextContentChangedEventArgs>(OnSubjectBufferChanged);
                }
                else if (elt is System.Reflection.MemberInfo)
                {
                    System.Reflection.MemberInfo  element  = elt as System.Reflection.MemberInfo;
                    XSharpLanguage.MemberAnalysis analysis = new XSharpLanguage.MemberAnalysis(element);
                    if (analysis.IsInitialized)
                    {
                        signatures.Add(CreateSignature(m_textBuffer, analysis.Prototype, "", ApplicableToSpan, comma));
                        // Any other member with the same name in the current Type and in the Parent(s) ?
                        SystemNameSake(element.DeclaringType, signatures, element.Name, analysis.Prototype, comma);
                        //
                        m_textBuffer.Changed += new EventHandler <TextContentChangedEventArgs>(OnSubjectBufferChanged);
                    }
                }
                session.Dismissed += OnSignatureHelpSessionDismiss;
            }
            catch (Exception ex)
            {
                XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpSignatureHelpSource.AugmentSignatureHelpSession Exception failed ");
                XSharpProjectPackage.Instance.DisplayException(ex);
            }
            finally
            {
                XSharpModel.ModelWalker.Resume();
            }
        }