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
                XMemberDefinition member           = XSharpLanguage.XSharpTokenTools.FindMember(triggerPoint.GetContainingLine().LineNumber, _file);
                XTypeDefinition   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, true, _file, false, member);
                // LookUp for the BaseType, reading the TokenList (From left to right)
                CompletionElement gotoElement;
                String            currentNS = "";
                if (currentNamespace != null)
                {
                    currentNS = currentNamespace.Name;
                }
                CompletionType cType = XSharpLanguage.XSharpTokenTools.RetrieveType(_file, tokenList, member, currentNS, stopToken, out gotoElement, snapshot, lineNumber, _file.Project.Dialect);
                //
                if ((gotoElement != null) && (gotoElement.IsSourceElement))
                {
                    peekableItems.Add(new XSharpDefinitionPeekItem(gotoElement.SourceElement, _peekResultFactory));
                }
            }
            catch (Exception ex)
            {
                XSettings.DisplayOutputMessage("XSharpPeekItemSource.AugmentPeekSession failed : ");
                XSettings.DisplayException(ex);
            }
            finally
            {
                ModelWalker.Resume();
            }
        }
        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;

                // LookUp for the BaseType, reading the TokenList (From left to right)
                var location = _textBuffer.FindLocation(triggerPoint);
                if (location == null)
                {
                    return;
                }

                CompletionState state;
                var             tokenList = XSharpTokenTools.GetTokensUnderCursor(location, out state);
                var             result    = new List <IXSymbol>();
                result.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out var notProcessed, true));
                //
                if (result.Count > 0)
                {
                    if (result[0] is XSourceSymbol symbol)
                    {
                        peekableItems.Add(new XSharpDefinitionPeekItem(symbol, _peekResultFactory));
                    }
                    else if (result[0] is XPESymbol pesymbol)
                    {
                        XPETypeSymbol petype;
                        if (pesymbol is XPETypeSymbol)
                        {
                            petype = (XPETypeSymbol)pesymbol;
                        }
                        else if (pesymbol is XPEMemberSymbol member)
                        {
                            petype = (XPETypeSymbol)member.Parent;
                        }
                        else
                        {
                            return;
                        }
                        var file   = XSharpGotoDefinition.CreateFileForSystemType(petype, pesymbol);
                        var entity = XSharpGotoDefinition.FindElementInFile(file, petype, pesymbol);
                        if (entity != null)
                        {
                            peekableItems.Add(new XSharpDefinitionPeekItem(entity, _peekResultFactory));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                XSettings.LogException(ex, "XSharpPeekItemSource.AugmentPeekSession failed : ");
            }
            finally
            {
                ModelWalker.Resume();
            }
        }
        //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);
        }
Beispiel #4
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();
            }
        }