//static bool skipFirst = true;

        public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken)
        {
            if (XSettings.DebuggerIsRunning || XSettings.DisableQuickInfo)
            {
                await session.DismissAsync();

                return(null);
            }
            var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);

            if (triggerPoint == null)
            {
                await session.DismissAsync();

                return(null);
            }
            try
            {
                ModelWalker.Suspend();
                var ssp = triggerPoint.Value;
                // Map the trigger point down to our buffer.
                ITextSnapshot currentSnapshot = ssp.Snapshot;
                bool          abort           = false;
                var           tokens          = _textBuffer.GetDocument();
                if (tokens == null)
                {
                    return(null);
                }
                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }
                if (!abort)
                {
                    WriteOutputMessage($"Triggerpoint: {triggerPoint.Value.Position}");
                    // We don't want to lex the buffer. So get the tokens from the last lex run
                    // and when these are too old, then simply bail out
                    abort = tokens == null || tokens.SnapShot.Version != currentSnapshot.Version;
                }
                if (abort)
                {
                    await session.DismissAsync();

                    return(null);
                }
                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }
                var             location = _textBuffer.FindLocation(ssp);
                CompletionState state;
                var             tokenList = XSharpTokenTools.GetTokensUnderCursor(location, out state);
                // LookUp for the BaseType, reading the TokenList (From left to right)
                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }
                var lookupresult = new List <IXSymbol>();
                lookupresult.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out var notProcessed, true));
                var lastToken = tokenList.LastOrDefault();
                //
                if (lookupresult.Count > 0)
                {
                    var element   = lookupresult[0];
                    var qiContent = new List <object>();

                    if (element.Kind == Kind.Constructor && lastToken?.Type != XSharpLexer.CONSTRUCTOR && lastToken?.Type != XSharpLexer.LPAREN)
                    {
                        if (element.Parent != null)
                        {
                            var xtype = element.Parent as IXTypeSymbol;
                            var qitm  = new XTypeAnalysis(xtype);
                            AddImage(qiContent, qitm.Image);
                            var description = new ClassifiedTextElement(qitm.WPFDescription);
                            qiContent.Add(description);
                        }
                    }
                    else if (element is IXMemberSymbol mem)
                    {
                        QuickInfoTypeMember qitm = new QuickInfoTypeMember(mem);
                        AddImage(qiContent, qitm.Image);
                        var description = new ClassifiedTextElement(qitm.WPFDescription);
                        qiContent.Add(description);
                    }
                    else if (element is IXVariableSymbol var)
                    {
                        QuickInfoVariable qitm = new QuickInfoVariable(var);
                        AddImage(qiContent, qitm.Image);
                        var description = new ClassifiedTextElement(qitm.WPFDescription);
                        qiContent.Add(description);
                    }
                    else if (element is IXTypeSymbol xtype)
                    {
                        var qitm = new XTypeAnalysis(xtype);
                        AddImage(qiContent, qitm.Image);
                        var description = new ClassifiedTextElement(qitm.WPFDescription);
                        qiContent.Add(description);
                    }
                    else
                    {
                        var qitm = new XAnalysis(element);
                        AddImage(qiContent, qitm.Image);
                        var description = new ClassifiedTextElement(qitm.WPFDescription);
                        qiContent.Add(description);
                    }
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return(null);
                    }
                    var result   = new ContainerElement(ContainerElementStyle.Wrapped, qiContent);
                    var line     = ssp.GetContainingLine();
                    var lineSpan = _textBuffer.CurrentSnapshot.CreateTrackingSpan(line.Extent, SpanTrackingMode.EdgeInclusive);

                    return(new QuickInfoItem(lineSpan, result));
                }
            }
            catch (Exception ex)
            {
                XSettings.LogException(ex, "XSharpQuickInfo.AugmentQuickInfoSession failed : ");
            }
            finally
            {
                ModelWalker.Resume();
            }
            await session.DismissAsync();

            return(null);
        }
Exemple #2
0
        internal static void GotoDefn(ITextView TextView)
        {
            try
            {
                if (XSettings.DisableGotoDefinition)
                {
                    return;
                }
                var file = TextView.TextBuffer.GetFile();
                if (file == null || file.XFileType != XFileType.SourceCode)
                {
                    return;
                }
                WriteOutputMessage("CommandFilter.GotoDefn()");
                ModelWalker.Suspend();


                var snapshot = TextView.TextBuffer.CurrentSnapshot;

                // We don't want to lex the buffer. So get the tokens from the last lex run
                // and when these are too old, then simply bail out
                var tokens = TextView.TextBuffer.GetDocument();
                if (tokens != null)
                {
                    if (tokens.SnapShot.Version != snapshot.Version)
                    {
                        return;
                    }
                }
                string currentNS = TextView.FindNamespace();
                var    location  = TextView.FindLocation();
                var    state     = CompletionState.General | CompletionState.Types | CompletionState.Namespaces;
                var    tokenList = XSharpTokenTools.GetTokensUnderCursor(location, out state);

                // LookUp for the BaseType, reading the TokenList (From left to right)
                var result = new List <IXSymbol>();

                result.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out var notProcessed));
                //
                Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
                if (result.Count > 0)
                {
                    var element = result[0];
                    if (element is XSourceEntity source)
                    {
                        source.OpenEditor();
                    }
                    else if (element is XPETypeSymbol petype)
                    {
                        GotoSystemType(TextView, petype, petype);
                    }
                    else if (element is XPEMemberSymbol pemember)
                    {
                        var petype2 = pemember.Parent as XPETypeSymbol;
                        GotoSystemType(TextView, petype2, pemember);
                    }
                    return;
                }
                //
                if (tokenList.Count > 1)
                {
                    // try again with just the last element in the list
                    var token = tokenList[tokenList.Count - 1];
                    tokenList.Clear();
                    tokenList.Add(token);
                    location = location.With(currentNS);
                    result.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out notProcessed));
                }
                if (result.Count > 0)
                {
                    var element = result[0];
                    if (element is XSourceEntity source)
                    {
                        source.OpenEditor();
                    }
                    //else
                    //{
                    //    openInObjectBrowser(element.FullName);
                    //}
                    //return;
                }
            }
            catch (Exception ex)
            {
                XSettings.LogException(ex, "Goto failed");
            }
            finally
            {
                ModelWalker.Resume();
            }
        }