예제 #1
0
 internal void AddGenericLocals(XCompletionList compList, XSharpSearchLocation location, string startWith)
 {
     if (location.Member == null)
     {
         return;
     }
     // We assume the calling code checks to see if this is allowed
     // First, look after Parameters
     foreach (var paramVar in location.Member.Parameters.Where(p => nameStartsWith(p.Name, startWith)))
     {
         ImageSource icon = _glyphService.GetGlyph(paramVar.getGlyphGroup(), paramVar.getGlyphItem());
         if (!compList.Add(new XSCompletion(paramVar.Name, paramVar.Name, paramVar.Prototype, icon, null, Kind.Parameter, "")))
         {
             break;
         }
     }
     // Then, look for Locals
     // line numbers in the range are 1 based. currentLine = 0 based !
     foreach (var localVar in location.Member.GetLocals(location).Where(l => nameStartsWith(l.Name, startWith) && l.Range.StartLine - 1 <= location.LineNumber))
     {
         ImageSource icon = _glyphService.GetGlyph(localVar.getGlyphGroup(), localVar.getGlyphItem());
         if (!compList.Add(new XSCompletion(localVar.Name, localVar.Name, localVar.Prototype, icon, null, Kind.Local, "")))
         {
             break;
         }
     }
 }
예제 #2
0
        internal void AddXSharpNamespaces(XCompletionList compList, XSharpSearchLocation location, string startWith, ImageSource icon)
        {
            // Calculate the length we must remove
            int startLen = 0;
            int dotPos   = startWith.LastIndexOf('.');

            if (dotPos != -1)
            {
                startLen = dotPos + 1;
            }
            // And our own Namespaces
            var xsNamespaces = location.Project.ProjectNamespaces;

            foreach (string nameSpace in xsNamespaces.Where(ns => nameStartsWith(ns, startWith)))
            {
                string realNamespace = nameSpace;
                // remove the start
                if (startLen > 0)
                {
                    realNamespace = realNamespace.Substring(startLen);
                }
                // Do we have another part
                dotPos = realNamespace.IndexOf('.');
                // Then remove it
                if (dotPos > 0)
                {
                    realNamespace = realNamespace.Substring(0, dotPos);
                }
                if (!compList.Add(new XSCompletion(realNamespace, realNamespace, nameSpace, icon, null, Kind.Namespace, "")))
                {
                    break;
                }
            }
        }
예제 #3
0
 internal void AddGenericInheritedMembers(XCompletionList compList, XSharpSearchLocation location, string startWith)
 {
     if (location.Member == null)
     {
         return;
     }
     if (location.Member.Kind.IsClassMember(_dialect))
     {
         var type = location.Member.Parent as XSourceTypeSymbol;
         if (type == null)
         {
             return;
         }
         type.ForceComplete();
         var baseType = type.BaseType;
         if (baseType == null)
         {
             return;
         }
         foreach (var member in baseType.GetMembers(startWith))
         {
             ImageSource icon = _glyphService.GetGlyph(member.getGlyphGroup(), member.getGlyphItem());
             if (!compList.Add(new XSCompletion(member.Name, member.Name, member.Prototype, icon, null, Kind.Field, "")))
             {
                 break;
             }
         }
     }
 }
예제 #4
0
        internal void AddGenericSelfMembers(XCompletionList compList, XSharpSearchLocation location, string startWith)
        {
            if (location.Member == null)
            {
                return;
            }
            // Ok, now look for Members of the Owner of the member... So, the class a Method
            //
            // We assume the calling code checks to see if this is allowed

            if (location.Member.Kind.IsClassMember(_dialect))
            {
                var type = location.Member.Parent as XSourceTypeSymbol;
                if (type == null)
                {
                    return;
                }
                foreach (var member in type.GetMembers(startWith))
                {
                    ImageSource icon = _glyphService.GetGlyph(member.getGlyphGroup(), member.getGlyphItem());
                    if (!compList.Add(new XSCompletion(member.Name, member.Name, member.Prototype, icon, null, Kind.Field, "")))
                    {
                        break;
                    }
                }
            }
        }
예제 #5
0
 internal void AddXSharpKeywords(XCompletionList compList, string startWith)
 {
     foreach (var kw in XSharpSyntax.GetKeywords().Where(ti => nameStartsWith(ti.Name, startWith)))
     {
         ImageSource icon = _glyphService.GetGlyph(kw.getGlyphGroup(), kw.getGlyphItem());
         compList.Add(new XSCompletion(kw.Name, kw.Name, kw.Prototype, icon, null, Kind.Keyword, ""));
     }
 }
예제 #6
0
        internal void AddTypeNames(XCompletionList compList, XSharpSearchLocation location, string startWith,
                                   bool onlyInterfaces = false, bool afterDot = false)
        {
            if (startWith == null)
            {
                return;
            }
            // PE Types
            AddPETypeNames(compList, location, startWith, onlyInterfaces, afterDot);
            // Find Source Types
            AddSourceTypeNames(compList, location, startWith, onlyInterfaces, afterDot);

            // And our own Types
            AddXSharpTypeNames(compList, location, startWith);
        }
예제 #7
0
 internal void FillExtensions(XSharpSearchLocation location, XCompletionList compList, IXTypeSymbol type, string startWith)
 {
     WriteOutputMessage($"FillExtensions for type {type?.FullName}");
     if (type != null)
     {
         var extensions = _file.Project.GetExtensions(type.FullName);
         IEnumerable <IXMemberSymbol> selection = extensions;
         if (!string.IsNullOrEmpty(startWith))
         {
             selection = extensions.Where(x => nameStartsWith(x.Name, startWith));
         }
         if (selection.Count() > 0)
         {
             FillMembers(location, compList, null, selection, Modifiers.Public, true);
         }
         foreach (var ifname in type.Interfaces)
         {
             var lifname       = ifname;
             var lookupproject = _file.Project;
             if (type is XSourceTypeSymbol sourceType)
             {
                 var typedef  = sourceType;
                 var origfile = XSolution.FindFullPath(typedef.File.FullPath);
                 lookupproject = origfile.Project;
                 var reftype = SystemTypeController.FindType(lifname, typedef.FileUsings, lookupproject.AssemblyReferences);
                 if (reftype != null)
                 {
                     lifname = reftype.FullName;
                 }
             }
             extensions = lookupproject.GetExtensions(lifname);
             selection  = extensions;
             if (!string.IsNullOrEmpty(startWith))
             {
                 selection = extensions.Where(x => nameStartsWith(x.Name, startWith));
             }
             if (selection.Count() > 0)
             {
                 FillMembers(location, compList, null, selection, Modifiers.Public, true);
             }
         }
     }
     //WriteOutputMessage($"FillExtensions complete for type {sType.FullName}");
 }
예제 #8
0
        internal void BuildTabs(XCompletionList compList, IList <CompletionSet> completionSets, ITrackingSpan applicableTo)
        {
            var values = compList.Values;

            if (compList.HasEnumMembers)
            {
                var sub = values.Where(item => item.Kind == Kind.EnumMember);
                completionSets.Add(new CompletionSet("Values", "Values", applicableTo, sub, Enumerable.Empty <Completion>()));
            }
            if (compList.HasMethods)
            {
                var sub = values.Where(item => item.Kind == Kind.Method);
                completionSets.Add(new CompletionSet("Methods", "Methods", applicableTo, sub, Enumerable.Empty <Completion>()));
            }
            if (compList.HasFields)
            {
                var sub = values.Where(item => item.Kind.IsField());
                completionSets.Add(new CompletionSet("Fields", "Fields", applicableTo, sub, Enumerable.Empty <Completion>()));
            }
            if (compList.HasProperties)
            {
                var sub = values.Where(item => item.Kind == Kind.Property);
                completionSets.Add(new CompletionSet("Properties", "Properties", applicableTo, sub, Enumerable.Empty <Completion>()));
            }
            if (compList.HasEvents)
            {
                var sub = compList.Values.Where(item => item.Kind == Kind.Event);
                completionSets.Add(new CompletionSet("Events", "Events", applicableTo, sub, Enumerable.Empty <Completion>()));
            }
            if (compList.HasTypes)
            {
                var sub = values.Where(item => item.Kind.IsType());
                completionSets.Add(new CompletionSet("Types", "Types", applicableTo, sub, Enumerable.Empty <Completion>()));
            }
            if (compList.HasNamespaces)
            {
                var sub = values.Where(item => item.Kind == Kind.Namespace);
                completionSets.Add(new CompletionSet("Namespaces", "Namespaces", applicableTo, sub, Enumerable.Empty <Completion>()));
            }
        }
예제 #9
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;
                }
            }
        }
예제 #10
0
        internal void AddXSharpTypeNames(XCompletionList compList, XSharpSearchLocation location, string startWith, IList <string> usings = null, string NameToExclude = "")
        {
            if (usings == null)
            {
                usings = location.Usings;
            }
            var list = location.Project.GetTypes(startWith, usings);

            foreach (var typeInfo in list)
            {
                if (String.Compare(typeInfo.FullName, NameToExclude) == 0)
                {
                    continue;
                }

                // Then remove it
                ImageSource icon = _glyphService.GetGlyph(typeInfo.getGlyphGroup(), typeInfo.getGlyphItem());
                if (!compList.Add(new XSCompletion(typeInfo.Name, typeInfo.Name, typeInfo.FullName, icon, null, typeInfo.Kind, "")))
                {
                    break;
                }
            }
        }
예제 #11
0
        internal void AddXSharpKeywordTypeNames(XCompletionList compList, string startWith)
        {
            //
            int startLen = 0;
            int dotPos   = startWith.LastIndexOf('.');

            if (dotPos != -1)
            {
                startLen = dotPos + 1;
            }
            //
            // And our own Types
            var xsharpTypes = XSharpSyntax.GetTypes();

            foreach (var typeInfo in xsharpTypes.Where(ti => nameStartsWith(ti.Name, startWith)))
            {
                string realTypeName = typeInfo.FullName;
                // remove the start
                if (startLen > 0)
                {
                    realTypeName = realTypeName.Substring(startLen);
                }
                // Do we have another part
                dotPos = realTypeName.IndexOf('.');
                // Then remove it
                if (dotPos > 0)
                {
                    realTypeName = realTypeName.Substring(0, dotPos);
                }
                ImageSource icon = _glyphService.GetGlyph(typeInfo.getGlyphGroup(), typeInfo.getGlyphItem());
                if (!compList.Add(new XSCompletion(realTypeName, realTypeName, typeInfo.Prototype, icon, null, Kind.Class, "")))
                {
                    break;
                }
            }
        }
예제 #12
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            WriteOutputMessage("-->> AugmentCompletionSessions");
            try
            {
                if (XSettings.DisableCodeCompletion)
                {
                    return;
                }
                XSharpModel.ModelWalker.Suspend();
                if (_disposed)
                {
                    throw new ObjectDisposedException("XSharpCompletionSource");
                }
                _showTabs      = XSettings.EditorCompletionListTabs;
                _keywordsInAll = XSettings.EditorKeywordsInAll;

                // Where does the StartSession has been triggered ?
                ITextSnapshot snapshot     = _buffer.CurrentSnapshot;
                var           triggerPoint = (SnapshotPoint)session.GetTriggerPoint(snapshot);
                if (triggerPoint == null)
                {
                    return;
                }
                // What is the character were it starts ?
                var line = triggerPoint.GetContainingLine();
                //var triggerposinline = triggerPoint.Position - 2 - line.Start;
                //var afterChar = line.GetText()[triggerposinline];
                //if (afterChar == ' ' || afterChar == '\t')
                //    return;

                // The "parameters" coming from CommandFilter
                uint cmd       = 0;
                char typedChar = '\0';
                bool autoType  = false;
                session.Properties.TryGetProperty(XsCompletionProperties.Command, out cmd);
                VSConstants.VSStd2KCmdID nCmdId = (VSConstants.VSStd2KCmdID)cmd;
                session.Properties.TryGetProperty(XsCompletionProperties.Char, out typedChar);
                session.Properties.TryGetProperty(XsCompletionProperties.AutoType, out autoType);
                bool showInstanceMembers = (typedChar == ':') || ((typedChar == '.') && _file.Project.ParseOptions.AllowDotForInstanceMembers);

                ////////////////////////////////////////////
                //
                SnapshotSpan  lineSpan      = new SnapshotSpan(line.Start, line.Length);
                SnapshotPoint caret         = triggerPoint;
                var           tagAggregator = aggregator.CreateTagAggregator <IClassificationTag>(_buffer);
                var           tags          = tagAggregator.GetTags(lineSpan);
                IMappingTagSpan <IClassificationTag> lastTag = null;
                foreach (var tag in tags)
                {
                    //tagList.Add(tag);
                    SnapshotPoint ptStart = tag.Span.Start.GetPoint(_buffer, PositionAffinity.Successor).Value;
                    SnapshotPoint ptEnd   = tag.Span.End.GetPoint(_buffer, PositionAffinity.Successor).Value;
                    if ((ptStart != null) && (ptEnd != null))
                    {
                        if (caret.Position >= ptEnd)
                        {
                            lastTag = tag;
                        }
                    }
                }
                if (lastTag != null)
                {
                    var name = lastTag.Tag.ClassificationType.Classification.ToLower();
                    // No Intellisense in Comment
                    if (name == "comment" || name == "xsharp.text")
                    {
                        return;
                    }
                }
                ////////////////////////////////////////////
                SnapshotPoint start        = triggerPoint;
                var           applicableTo = snapshot.CreateTrackingSpan(new SnapshotSpan(start, triggerPoint), SpanTrackingMode.EdgeInclusive);
                //
                if (_file == null)
                {
                    // Uhh !??, Something went wrong
                    return;
                }
                // The Completion list we are building
                XCompletionList compList = new XCompletionList(_file);
                XCompletionList kwdList  = new XCompletionList(_file);
                IXTypeSymbol    type     = null;
                if (session.Properties.ContainsProperty(XsCompletionProperties.Type))
                {
                    type = (IXTypeSymbol)session.Properties[XsCompletionProperties.Type];
                }
                // Start of Process
                string filterText = "";
                // Check if we can get the member where we are
                // Standard TokenList Creation (based on colon Selector )
                bool includeKeywords;
                session.Properties.TryGetProperty(XsCompletionProperties.IncludeKeywords, out includeKeywords);
                CompletionState state;
                var             member   = session.TextView.FindMember(triggerPoint);
                var             location = session.TextView.TextBuffer.FindLocation(triggerPoint);
                if (location == null)
                {
                    return;
                }
                var tokenList = XSharpTokenTools.GetTokenList(location, out state, includeKeywords);


                // We might be here due to a COMPLETEWORD command, so we have no typedChar
                // but we "may" have a incomplete word like System.String.To
                // Try to Guess what TypedChar could be
                if (typedChar == '\0' && autoType)
                {
                    if (tokenList.Count > 0)
                    {
                        string extract = tokenList[tokenList.Count - 1].Text;
                        typedChar = extract[extract.Length - 1];
                        if ((typedChar != '.') && (typedChar != ':'))
                        {
                            if (tokenList.Count == 1)
                            {
                                //
                                filterText = tokenList[0].Text;
                                int dotPos = extract.LastIndexOf(".");
                                if (dotPos > -1)
                                {
                                    string startToken = extract.Substring(0, dotPos);
                                    filterText        = extract.Substring(dotPos + 1);
                                    typedChar         = '.';
                                    tokenList[0].Text = startToken + ".";
                                }
                            }
                            else
                            {
                                // So, we get the last Token as a Filter
                                filterText = tokenList[tokenList.Count - 1].Text;
                            }
                            // Include the filter as the text to replace
                            start       -= filterText.Length;
                            applicableTo = snapshot.CreateTrackingSpan(new SnapshotSpan(start, triggerPoint), SpanTrackingMode.EdgeInclusive);
                        }
                    }
                }
                bool dotSelector = (typedChar == '.');

                // TODO: Based on the Project.Settings, we should add the Vulcan.VO namespace
                int tokenType = XSharpLexer.UNRECOGNIZED;

                var symbol     = XSharpLookup.RetrieveElement(location, tokenList, CompletionState.General, out var notProcessed).FirstOrDefault();
                var memberName = "";
                // Check for members, locals etc and convert the type of these to IXTypeSymbol
                if (symbol != null)
                {
                    if (symbol is IXTypeSymbol xtype)
                    {
                        type = xtype;
                    }
                    else if (symbol is IXMemberSymbol xmember)
                    {
                        var typeName = xmember.TypeName;
                        if (xmember is XSourceMemberSymbol sourcemem)
                        {
                            type = sourcemem.File.FindType(typeName);
                        }
                        else
                        {
                            type = location.FindType(typeName);
                        }
                        memberName = xmember.Name;
                    }
                    else if (symbol is IXVariableSymbol xvar)
                    {
                        var typeName = "";
                        if (xvar is XSourceUndeclaredVariableSymbol)
                        {
                            type       = null;
                            state      = CompletionState.General;
                            filterText = xvar.Name;
                        }
                        else if (xvar is XSourceVariableSymbol sourcevar)
                        {
                            typeName = sourcevar.TypeName;
                            if (sourcevar.ResolvedType != null)
                            {
                                type     = sourcevar.ResolvedType;
                                typeName = type.FullName;
                            }
                            else
                            {
                                type = sourcevar.File.FindType(typeName);
                            }
                        }
                        else if (xvar is XPEParameterSymbol par)
                        {
                            typeName = par.TypeName;
                            type     = location.FindType(typeName);
                        }
                        memberName = xvar.Name;
                    }
                    else if (symbol.Kind == Kind.Keyword)
                    {
                        filterText = symbol.Name;
                    }
                    else if (symbol.Kind == Kind.Namespace)
                    {
                        filterText = symbol.Name + ".";
                    }
                    if (type != null)
                    {
                        switch (type.FullName)
                        {
                        case XSharpTypeNames.XSharpUsual:
                        case XSharpTypeNames.VulcanUsual:
                            type = null;
                            break;
                        }
                    }
                    session.Properties[XsCompletionProperties.Type] = type;
                }
                if (type == null)
                {
                    showInstanceMembers = false;
                }
                if ((dotSelector || state != CompletionState.None))
                {
                    if (string.IsNullOrEmpty(filterText) && type == null)
                    {
                        filterText = helpers.TokenListAsString(tokenList);
                        if (filterText.Length > 0 && !filterText.EndsWith(".") && state != CompletionState.General)
                        {
                            filterText += ".";
                        }
                    }
                    if (type == null && state.HasFlag(CompletionState.Namespaces))
                    {
                        helpers.AddNamespaces(compList, location, filterText);
                    }
                    if (type == null && state.HasFlag(CompletionState.Interfaces))
                    {
                        helpers.AddTypeNames(compList, location, filterText, afterDot: true, onlyInterfaces: true);
                        helpers.AddXSharpKeywordTypeNames(kwdList, filterText);
                    }
                    if (type == null && state.HasFlag(CompletionState.Types))
                    {
                        helpers.AddTypeNames(compList, location, filterText, afterDot: true, onlyInterfaces: false);
                        helpers.AddXSharpKeywordTypeNames(kwdList, filterText);
                    }
                    if (state.HasFlag(CompletionState.StaticMembers))
                    {
                        if (type != null && symbol is IXTypeSymbol)
                        {
                            // First we need to keep only the text AFTER the last dot
                            int dotPos = filterText.LastIndexOf('.');
                            filterText = filterText.Substring(dotPos + 1, filterText.Length - dotPos - 1);
                            helpers.BuildCompletionListMembers(location, compList, type, Modifiers.Public, true, filterText);
                        }
                    }
                    if (type.IsVoStruct() && typedChar == '.')
                    {
                        // vostruct or union in other assembly
                        showInstanceMembers = true;
                        filterText          = "";
                    }
                    if (state.HasFlag(CompletionState.InstanceMembers))
                    {
                        showInstanceMembers = true;
                        filterText          = "";
                    }
                }
                if (showInstanceMembers)
                {
                    // Member call
                    if (type != null)
                    {
                        Modifiers visibleAs = Modifiers.Public;
                        if (type is XSourceTypeSymbol sourceType && sourceType.File.Project == member.File.Project)
                        {
                            visibleAs = Modifiers.Internal;
                            switch (memberName.ToLower())
                            {
                            case "self":
                            case "this":
                                visibleAs = Modifiers.Private;
                                break;

                            case "super":
                                visibleAs = Modifiers.Protected;
                                break;

                            default:
                                if (member.ParentName == type.FullName)
                                {
                                    visibleAs = Modifiers.Private;
                                }
                                break;
                            }
                        }
                        // Now, Fill the CompletionList with the available members, from there
                        helpers.BuildCompletionListMembers(location, compList, type, visibleAs, false, filterText);
                    }
                }
                //
                if (!dotSelector && !showInstanceMembers)
                {
                    switch (tokenType)
                    {
                    case XSharpLexer.USING:
                        // It can be a namespace
                        helpers.AddNamespaces(compList, location, filterText);
                        break;

                    case XSharpLexer.AS:
                    case XSharpLexer.IS:
                    case XSharpLexer.REF:
                    case XSharpLexer.INHERIT:
                        // It can be a namespace
                        helpers.AddNamespaces(compList, location, filterText);
                        // It can be Type, FullyQualified
                        // we should also walk all the USINGs, and the current Namespace if any, to search Types
                        helpers.AddTypeNames(compList, location, filterText, onlyInterfaces: false, afterDot: false);
                        //
                        helpers.AddXSharpKeywordTypeNames(kwdList, filterText);
                        break;

                    case XSharpLexer.IMPLEMENTS:
                        // It can be a namespace
                        helpers.AddNamespaces(compList, location, filterText);
                        helpers.AddTypeNames(compList, location, filterText, onlyInterfaces: true, afterDot: false);
                        break;

                    default:
                        //if (state.HasFlag(CompletionState.General))
                        //{
                        //    filterText = notProcessed;
                        //    helpers.AddGenericCompletion(compList, location, filterText);
                        //}
                        break;
                    }
                }

                if ((kwdList.Count > 0) && _keywordsInAll /*&& XSettings.CompleteKeywords*/)
                {
                    foreach (var item in kwdList.Values)
                    {
                        compList.Add(item);
                    }
                }
                // Sort in alphabetical order
                // and put in the SelectionList
                var values = compList.Values;
                // Create the All Tab
                completionSets.Add(new CompletionSet("All", "All", applicableTo, values, Enumerable.Empty <Completion>()));
                if (_showTabs)
                {
                    helpers.BuildTabs(compList, completionSets, applicableTo);
                }
                // Keywords are ALWAYS in a separate Tab anyway
                if (kwdList.Count > 0)
                {
                    completionSets.Add(new CompletionSet("Keywords", "Keywords", applicableTo, kwdList.Values, Enumerable.Empty <Completion>()));
                }
            }
            catch (Exception ex)
            {
                XSettings.LogException(ex, "AugmentCompletionSessions failed");
            }
            finally
            {
                XSharpModel.ModelWalker.Resume();
            }
            WriteOutputMessage("<<-- AugmentCompletionSessions");
        }
예제 #13
0
 /// <summary>
 /// Add Members for our Types to the completionlist
 /// </summary>
 /// <param name="compList"></param>
 /// <param name="xType"></param>
 /// <param name="minVisibility"></param>
 internal void FillMembers(XSharpSearchLocation location, XCompletionList compList, IXTypeSymbol xType, Modifiers minVisibility, bool staticOnly, string startWith)
 {
     FillMembers(location, compList, xType, xType.GetMembers(startWith), minVisibility, staticOnly);
 }
예제 #14
0
        /// <summary>
        /// Add members to the completionlist
        /// </summary>
        /// <param name="compList"></param>
        /// <param name="members"></param>
        /// <param name="minVisibility"></param>
        /// <param name="staticOnly"></param>
        internal void FillMembers(XSharpSearchLocation location, XCompletionList compList, IXTypeSymbol type, IEnumerable <IXMemberSymbol> members, Modifiers minVisibility, bool staticOnly)
        {
            if (members.Count() == 0)
            {
                return;
            }
            WriteOutputMessage($"FillMembers {type?.FullName}: {members.Count()} members");
            foreach (var elt in members)
            {
                bool add = true;
                if (IsHiddenMemberName(elt.Name))
                {
                    continue;
                }
                switch (elt.Kind)
                {
                case Kind.EnumMember:
                    add = true;
                    break;

                case Kind.Constructor:
                case Kind.Destructor:
                case Kind.Operator:
                    add = false;
                    break;

                default:
                    if (!elt.Kind.IsGlobalTypeMember() && elt.IsStatic != staticOnly)
                    {
                        add = false;
                    }
                    if (add)
                    {
                        add = elt.IsVisible(minVisibility);
                    }
                    if (staticOnly && elt.IsStatic && type != null)
                    {
                        if (elt.Parent.FullName == "System.Object" && type.FullName != "System.Object")
                        {
                            add = false;
                        }
                    }
                    break;
                }
                if (type != null && type.Kind == Kind.Enum && elt.DeclaringType != null && elt.DeclaringType != type.FullName && elt.Name != "HasFlag")
                {
                    add = false;
                }
                if (!add)
                {
                    continue;
                }
                //
                ImageSource icon  = _glyphService.GetGlyph(elt.getGlyphGroup(), elt.getGlyphItem());
                string      toAdd = "";
                if (elt.Kind.HasParameters() && elt.Kind != Kind.Constructor && !elt.Kind.IsProperty() && elt.Kind != Kind.Event)
                {
                    toAdd = "(";
                }
                if (!compList.Add(new XSCompletion(elt.Name, elt.Name + toAdd, elt.Prototype, icon, null, elt.Kind, elt.Value)))
                {
                    break;
                }
            }
        }
예제 #15
0
 internal void BuildCompletionListMembers(XSharpSearchLocation location, XCompletionList compList, IXTypeSymbol type, Modifiers minVisibility, bool staticOnly, string startWith)
 {
     if (type == null)
     {
         return;
     }
     //
     FillMembers(location, compList, type, minVisibility, staticOnly, startWith);
     if (type is XSourceTypeSymbol sourceType)
     {
         sourceType.ForceComplete();
         var baseType = sourceType.BaseTypeName;
         if (string.IsNullOrWhiteSpace(baseType))
         {
             if (type.Kind == Kind.Enum)
             {
                 baseType = "System.Enum";
             }
             else if (type.Kind == Kind.Delegate)
             {
                 baseType = "System.Delegate";
             }
             else
             {
                 baseType = "System.Object";
             }
         }
         var parentType = sourceType.File.FindType(baseType, sourceType.Namespace);
         if (parentType != null && parentType.FullName == sourceType.FullName)
         {
             ; // recursion !
             WriteOutputMessage("*** Recursion detected *** " + sourceType.FullName + " inherits from " + parentType.FullName);
         }
         else if (baseType == "System.Enum" && staticOnly)
         {
             ; // do nothing
         }
         else
         {
             BuildCompletionListMembers(location, compList, parentType, Modifiers.Protected, staticOnly, startWith);
         }
         foreach (var ifname in sourceType.Interfaces)
         {
             var iftype = sourceType.File.FindType(ifname, sourceType.Namespace);
             if (iftype != null)
             {
                 BuildCompletionListMembers(location, compList, iftype, Modifiers.Public, staticOnly, startWith);
             }
         }
     }
     if (type is XPETypeSymbol && type.Children.Count > 0)
     {
         AddTypeNames(compList, location, type.FullName, false);
     }
     if (type is XSourceTypeSymbol)
     {
         var usings = location.Usings.ToList();
         usings.Add(type.FullName);
         AddXSharpTypeNames(compList, location, type.FullName, usings, type.FullName);
     }
     if (!staticOnly)
     {
         FillExtensions(location, compList, type, startWith);
     }
 }
예제 #16
0
        //internal void AddGenericCompletion(XCompletionList compList, XSharpSearchLocation location, string startWith )
        //{
        //    if (XSettings.CompleteLocals && compList.Count < XSettings.MaxCompletionEntries)
        //    {
        //        AddGenericLocals(compList, location, startWith);
        //    }
        //    if (XSettings.CompleteSelf && compList.Count < XSettings.MaxCompletionEntries)
        //    {
        //        AddGenericSelfMembers(compList, location, startWith);
        //    }
        //    if (XSettings.CompleteParent && compList.Count < XSettings.MaxCompletionEntries)
        //    {
        //        AddGenericInheritedMembers(compList, location, startWith);
        //    }
        //    if (XSettings.CompleteNamespaces && compList.Count < XSettings.MaxCompletionEntries)
        //    {
        //        AddNamespaces(compList, location, startWith);
        //    }
        //    if (XSettings.CompleteTypes && compList.Count < XSettings.MaxCompletionEntries)
        //    {
        //         AddTypeNames(compList, location, startWith);
        //    }
        //    if (XSettings.CompleteFunctions && compList.Count < XSettings.MaxCompletionEntries)
        //    {
        //        AddGenericFunctions(compList, location, startWith, true);
        //    }
        //    if (XSettings.CompleteFunctionsP && compList.Count < XSettings.MaxCompletionEntries)
        //    {
        //        AddGenericFunctions(compList, location, startWith, false);
        //    }
        //    if (XSettings.CompleteFunctionsA && compList.Count < XSettings.MaxCompletionEntries)
        //    {
        //        AddGenericFunctionsAssemblies(compList, location, startWith, false);
        //    }
        //    if (XSettings.CompleteGlobals && compList.Count < XSettings.MaxCompletionEntries)
        //    {
        //        AddGenericGlobals(compList, location, startWith, true);
        //    }
        //    if (XSettings.CompleteGlobalsP && compList.Count < XSettings.MaxCompletionEntries)
        //    {
        //        AddGenericGlobals(compList, location, startWith, false);
        //    }
        //    if (XSettings.CompleteGlobalsA && compList.Count < XSettings.MaxCompletionEntries)
        //    {
        //        AddGenericGlobalsAssemblies(compList, location, startWith, false);

        //    }
        //    if (XSettings.CompleteSnippets)
        //    {
        //        // todo: Add Snippets
        //    }
        //    if (XSettings.CompleteKeywords)
        //    {
        //        AddXSharpKeywords(compList, startWith);
        //    }
        //}

        internal void AddGenericGlobals(XCompletionList compList, XSharpSearchLocation location, string startWith, bool onlyProject)
        {
            var found = location.Project.FindGlobalMembersLike(startWith, onlyProject);

            FillMembers(location, compList, null, found, Modifiers.Public, false);
        }
예제 #17
0
        internal void AddNamespaces(XCompletionList compList, XSharpSearchLocation location, string startWith)
        {
            // We are looking for NameSpaces, in References
            if (startWith == null)
            {
                return;
            }
            var namespaces = location.Project.AllNamespaces;
            // Calculate the length we must remove
            int startLen = 0;
            int dotPos   = startWith.LastIndexOf('.');

            if (dotPos != -1)
            {
                startLen = dotPos + 1;
            }
            ImageSource icon      = _glyphService.GetGlyph(StandardGlyphGroup.GlyphGroupNamespace, StandardGlyphItem.GlyphItemPublic);
            ImageSource iconClass = _glyphService.GetGlyph(StandardGlyphGroup.GlyphGroupClass, StandardGlyphItem.GlyphItemPublic);

            foreach (string nameSpace in namespaces.Where(ns => nameStartsWith(ns, startWith)))
            {
                string displayName = nameSpace;
                // remove the start
                if (startLen > 0)
                {
                    displayName = displayName.Substring(startLen);
                }
                // Do we have another part
                dotPos = displayName.IndexOf('.');
                // Then remove it
                if (dotPos > 0)
                {
                    displayName = displayName.Substring(0, dotPos);
                }
                //
                XSCompletion item;
                if (!compList.ContainsKey(displayName))
                {
                    if (displayName.IndexOf("<") > 0)
                    {
                        item = new XSCompletion(displayName, displayName, nameSpace, iconClass, null, Kind.Class, "");
                    }
                    else
                    {
                        item = new XSCompletion(displayName, displayName, "Namespace " + nameSpace, icon, null, Kind.Namespace, "");
                    }
                    if (!compList.Add(item))
                    {
                        break;
                    }
                }
            }
            //
            // And our own Namespaces
            AddXSharpNamespaces(compList, location, startWith, icon);
            // We should also add the external NameSpaces
            var prjs = location.Project.ReferencedProjects;

            foreach (var prj in prjs)
            {
                AddXSharpNamespaces(compList, location, startWith, icon);
            }
        }
예제 #18
0
        internal void AddGenericFunctionsAssemblies(XCompletionList compList, XSharpSearchLocation location, string startWith, bool onlyProject)
        {
            var found = location.Project.FindFunctionsInAssemblyReferences(startWith);

            FillMembers(location, compList, null, found, Modifiers.Public, false);
        }