Exemplo n.º 1
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            try
            {
                XSharpModel.ModelWalker.Suspend();
                if (!string.Equals(session.RelationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }
                //
                var tp = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);
                if (!tp.HasValue)
                {
                    return;
                }
                //
                var    triggerPoint = tp.Value;
                IToken stopToken;
                //
                // Check if we can get the member where we are
                XSharpModel.XTypeMember member           = XSharpLanguage.XSharpTokenTools.FindMember(triggerPoint.GetContainingLine().LineNumber, _file);
                XSharpModel.XType       currentNamespace = XSharpLanguage.XSharpTokenTools.FindNamespace(triggerPoint.Position, _file);

                var           lineNumber = triggerPoint.GetContainingLine().LineNumber;
                var           snapshot   = _textBuffer.CurrentSnapshot;
                List <String> tokenList  = XSharpTokenTools.GetTokenList(triggerPoint.Position, lineNumber, snapshot, out stopToken, false, _file, false, member);
                // LookUp for the BaseType, reading the TokenList (From left to right)
                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, _file.Project.Dialect);
                //
                if ((gotoElement != null) && (gotoElement.XSharpElement != null))
                {
                    peekableItems.Add(new XSharpDefinitionPeekItem(gotoElement.XSharpElement, _peekResultFactory));
                }
            }
            catch (Exception ex)
            {
                XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpPeekItemSource.AugmentPeekSession failed : ");
                XSharpProjectPackage.Instance.DisplayException(ex);
            }
            finally
            {
                XSharpModel.ModelWalker.Resume();
            }
        }
Exemplo n.º 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();
                }
            }
        }