Ejemplo n.º 1
0
        internal void AddPETypeNames(XCompletionList compList, XSharpSearchLocation location, string startWith,
                                     bool onlyInterfaces = false, bool afterDot = false)
        {
            IList <XPETypeSymbol> types;

            if (afterDot)
            {
                types = location.Project.GetAssemblyTypesInNamespace(startWith, location.Usings.ToArray());
            }
            else
            {
                // where is this called ?
                types = new List <XPETypeSymbol>();
            }

            foreach (var type in types)
            {
                if (onlyInterfaces && type.Kind != Kind.Interface)
                {
                    continue;
                }
                if (isHiddenTypeSymbol(type, out var displayName))
                {
                    continue;
                }

                if (!afterDot && !displayName.StartsWith(startWith))
                {
                    continue;
                }
                var typeAnalysis = new XTypeAnalysis(type);

                ImageSource icon = _glyphService.GetGlyph(typeAnalysis.GlyphGroup, typeAnalysis.GlyphItem);
                if (!compList.Add(new XSCompletion(displayName, displayName, typeAnalysis.Prototype, icon, null, Kind.Class, "")))
                {
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        //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);
        }