Exemplo n.º 1
0
        public static XSourceEntity FindElementInFile(XFile file, XPETypeSymbol petype, XSymbol element)
        {
            var walker = new SourceWalker(file, false);

            walker.Parse(false);
            var           entities = walker.EntityList;
            XSourceEntity result   = null;

            if (petype.IsFunctionsClass)
            {
                foreach (var entity in entities)
                {
                    if (entity.Prototype == element.Prototype)
                    {
                        result = entity;
                        break;
                    }
                }
            }
            else
            {
                foreach (var entity in entities)
                {
                    if (entity.FullName == element.FullName)
                    {
                        result = entity;
                        break;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 2
0
 internal XDropDownMember(string label, TextSpan span, int glyph, DROPDOWNFONTATTR fontAttribute, XSourceEntity element)
 {
     Label    = label;
     Span     = span;
     Glyph    = glyph;
     FontAttr = fontAttribute;
     Entity   = element;
 }
Exemplo n.º 3
0
        private void SelectContainingMember(int newLine)
        {
            if (_file == null)
            {
                return;
            }
            XSourceEntity selectedElement = _file.FindMemberAtRow(newLine);

            if (selectedElement == _lastSelected && !SettingsChanged)
            {
                return;
            }
            XSourceTypeSymbol parentType = null;

            if (selectedElement is XSourceMemberSymbol)
            {
                parentType = (XSourceTypeSymbol)selectedElement.Parent;
            }
            else if (selectedElement is XSourceTypeSymbol)
            {
                parentType = selectedElement as XSourceTypeSymbol;
            }
            else
            {
                parentType = _file.GlobalType;
            }
            bool newType = true;

            if (parentType != null && _lastType != null && parentType.FullName == _lastType.FullName)
            {
                newType = false;
            }
            var nothingChanged = _file.ContentHashCode == this._lastHashCode && !SettingsChanged && !relatedFilesChanged;

            if (nothingChanged)
            {
                if (newType && XSettings.EditorNavigationMembersOfCurrentTypeOnly)
                {
                    _selectedTypeIndex = findSelectedType(parentType);
                    loadMemberCombos(_selectedTypeIndex, newLine);
                    _lastHashCode = _file.ContentHashCode;
                    _lastType     = parentType;
                    _saveSettings();
                    return;
                }
                // when not on a new type or when the member combo is already complete then we
                // can select the entry in the existing members combobox
                _selectedMemberIndex = findSelectedMember(selectedElement);
                _selectedTypeIndex   = findSelectedType(parentType);
                _lastSelected        = selectedElement;
                _lastType            = parentType;
            }
            else
            {
                reloadCombos(newLine);
            }
            return;
        }
Exemplo n.º 4
0
        public int OnItemChosen(int combo, int index)
        {
            XSourceEntity entity = null;

            if (index < 0)
            {
                index = 0;
            }
            switch (combo)
            {
            case 0:
                if (index < _types.Count)
                {
                    entity = _types[index].Entity;
                }
                break;

            case 1:
                if (index < _members.Count)
                {
                    entity = _members[index].Entity;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            if (entity != null)
            {
                bool open = false;
                if (entity.File.FullPath == this._file.FullPath)
                {
                    IVsTextView textView = ThreadHelper.JoinableTaskFactory.Run(GetActiveTextViewAsync);
                    if (textView != null)
                    {
                        textView.SetCaretPos(entity.Range.StartLine, 0);
                        if (entity.Range.StartLine > 5)
                        {
                            textView.SetTopLine(entity.Range.StartLine - 5);
                        }
                        else
                        {
                            textView.SetTopLine(0);
                        }
                        textView.SendExplicitFocus();
                        open = true;
                    }
                }
                if (!open)
                {
                    entity.OpenEditor();
                }
            }
            return(VSConstants.S_OK);
        }
Exemplo n.º 5
0
 private int findSelectedMember(XSourceEntity member)
 {
     if (member != null)
     {
         for (int i = 0; i < _members.Count; i++)
         {
             if (String.Compare(_members[i].Entity.FullName, member.FullName, true) == 0)
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
Exemplo n.º 6
0
        private void loadTypeCombos(int nLine)
        {
            _types.Clear();
            var                      sortItems = XSettings.EditorNavigationSorted;
            XDropDownMember          elt;
            int                      nSelect = 0;
            DROPDOWNFONTATTR         ft;
            List <XSourceTypeSymbol> xList = _file.TypeList.Values.ToList <XSourceTypeSymbol>();

            if (sortItems)
            {
                xList.Sort(delegate(XSourceTypeSymbol elt1, XSourceTypeSymbol elt2)
                {
                    return(elt1.FullName.CompareTo(elt2.FullName));
                });
            }
            if (xList.Count == 0)
            {
                xList.Add(_file.GlobalType);
            }
            foreach (XSourceTypeSymbol eltType in xList)
            {
                if (eltType.Kind == Kind.Namespace)
                {
                    continue;
                }
                //
                TextSpan sp = this.TextRangeToTextSpan(eltType.Range);
                ft = DROPDOWNFONTATTR.FONTATTR_PLAIN;
                string name = eltType.FullName;
                if (string.IsNullOrEmpty(name))
                {
                    name = "?";
                }
                elt     = new XDropDownMember(name, sp, eltType.Glyph, ft, eltType);
                nSelect = _types.Count;
                _types.Add(elt);
                if (eltType.Range.StartLine <= nLine && eltType.Range.EndLine >= nLine)
                {
                    _selectedTypeIndex = nSelect;
                    _lastType          = eltType;
                }
            }
            return;
        }
Exemplo n.º 7
0
        private void InitText(XSourceEntity member)
        {
            string descText = this.Name;

            //
            if (member != null)
            {
                if (member.Parent is XSourceTypeSymbol symbol)
                {
                    nameSpace = symbol.Namespace;
                    className = symbol.Name;
                }
                //
                descText = member.Name;
                if (member is XSourceMemberSymbol)
                {
                    var tm = member as XSourceMemberSymbol;
                    descText = tm.Kind == Kind.Constructor ? CONSTRUCTOR : member.Name;
                    if (tm.Kind.HasParameters())
                    {
                        descText += tm.Kind == Kind.Constructor ? "{" : "( ";
                        if (tm.HasParameters)
                        {
                            //
                            descText += tm.ParameterList;
                        }
                        descText += tm.Kind == Kind.Constructor ? "}" : ") ";
                    }
                }
                else if (member is XSourceTypeSymbol)
                {
                    var tm = member as XSourceTypeSymbol;
                    if ((tm.Kind == Kind.Namespace) && (String.IsNullOrEmpty(descText)))
                    {
                        descText = DEFAULTNAMESPACE;
                    }
                }
            }
            nodeText = descText;
        }
Exemplo n.º 8
0
 internal XSharpLibraryNode(XSourceEntity entity, string namePrefix, IVsHierarchy hierarchy, uint itemId)
     : base(String.IsNullOrEmpty(entity.FullName) ? namePrefix : entity.FullName)
 {
     kind       = entity.Kind;
     attributes = entity.Attributes;
     if (kind == Kind.Namespace)
     {
         this.NodeType = LibraryNodeType.Namespaces;
     }
     else if (kind.IsType())
     {
         this.NodeType = LibraryNodeType.Classes;
     }
     else
     {
         this.NodeType = LibraryNodeType.Members;
     }
     //
     this.filesId = new List <uint>();
     //
     this.ownerHierarchy = hierarchy;
     this.Depends(itemId);
     //this.member = scope;
     // Can we Goto ?
     if ((ownerHierarchy != null) && (VSConstants.VSITEMID_NIL != itemId))
     {
         this.CanGoToSource = true;
         this.editorInfo    = new SourcePosition()
         {
             FileName = entity.File.FullPath,
             Line     = entity.Range.StartLine + 1,
             Column   = entity.Range.StartColumn,
         };
     }
     //
     this.BuildImageData(entity.Kind, entity.Visibility);
     this.InitText(entity);
     this.InitDescription(entity);
 }
Exemplo n.º 9
0
        private void InitDescription(XSourceEntity member) //, _VSOBJDESCOPTIONS flags, IVsObjectBrowserDescription3 description)
        {
            description = new List <Tuple <string, VSOBDESCRIPTIONSECTION> >();
            string descText;

            if (member != null)
            {
                string modifier = "";
                string access   = "";
                if ((member is XSourceTypeSymbol) && (member.Kind != Kind.Namespace))
                {
                    modifier = member.Modifiers.ToDisplayString();
                    access   = member.Visibility.ToDisplayString();
                }
                else if ((member is XSourceMemberSymbol) && ((member.Kind != Kind.Function) && (member.Kind != Kind.Procedure)))
                {
                    modifier = member.Modifiers.ToDisplayString();
                    access   = member.Visibility.ToDisplayString();
                }
                //
                if (!string.IsNullOrEmpty(modifier))
                {
                    description.Add(Item(modifier + " ", VSOBDESCRIPTIONSECTION.OBDS_ATTRIBUTE));
                }
                //
                if (!string.IsNullOrEmpty(access))
                {
                    description.Add(Item(access + " ", VSOBDESCRIPTIONSECTION.OBDS_ATTRIBUTE));
                }
                //
                if (member.Kind != Kind.Field)
                {
                    VSOBDESCRIPTIONSECTION descName = VSOBDESCRIPTIONSECTION.OBDS_MISC;
                    descText = XSettings.FormatKeyword(member.Kind.DisplayName()) + " ";
                    if (member.Kind == Kind.Constructor)
                    {
                        descName = VSOBDESCRIPTIONSECTION.OBDS_NAME;
                    }
                    description.Add(Item(descText, descName));
                }
                if (member.Kind != Kind.Constructor)
                {
                    descText = member.Name;
                    description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_NAME));
                }
                // Parameters ?
                if (member.Kind.HasParameters())
                {
                    descText = "(";
                    description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC));
                    XSourceMemberSymbol realmember;
                    XSourceTypeSymbol   type = member as XSourceTypeSymbol;
                    if (member.Kind == Kind.Delegate && type?.XMembers.Count > 0)
                    {
                        realmember = type.XMembers[0];
                    }
                    else
                    {
                        realmember = member as XSourceMemberSymbol;
                    }

                    if (realmember != null && realmember.HasParameters)
                    {
                        //
                        int paramNum = 1;
                        foreach (IXParameterSymbol param in realmember.Parameters)
                        {
                            descText = param.Name;
                            description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_PARAM));
                            descText = param.ParamTypeDesc;
                            description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC));
                            descText = param.TypeName;
                            //
                            description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_TYPE));
                            // Need a comma ?
                            if (paramNum < realmember.ParameterCount)
                            {
                                paramNum++;
                                descText = ",";
                                description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_COMMA));
                            }
                        }
                    }
                    descText = ")";
                    description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC));
                }
                if (member.Kind.HasReturnType())
                {
                    descText = XLiterals.AsKeyWord;
                    description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_MISC));
                    descText = member.TypeName;
                    description.Add(Item(descText, VSOBDESCRIPTIONSECTION.OBDS_TYPE));
                }

                description.Add(Item(null, VSOBDESCRIPTIONSECTION.OBDS_ENDDECL));
            }
            //
            if (member.File?.Project != null)
            {
                string        summary = null, returns = null, remarks = null;
                List <string> pNames        = new List <string>();
                List <string> pDescriptions = new List <string>();
                if (member is XSourceMemberSymbol symbol1)
                {
                    summary = XSharpXMLDocMember.GetMemberSummary(symbol1, member.File?.Project, out returns, out remarks);
                    XSharpXMLDocMember.GetMemberParameters(symbol1, member.File?.Project, pNames, pDescriptions);
                }
                else if (member is XSourceTypeSymbol symbol)
                {
                    summary = XSharpXMLDocMember.GetTypeSummary(symbol, member.File?.Project, out returns, out remarks);
                }
                if (!string.IsNullOrEmpty(summary))
                {
                    description.Add(Item(NEWLINE, VSOBDESCRIPTIONSECTION.OBDS_MISC));
                    description.Add(Item(SUMMARY, VSOBDESCRIPTIONSECTION.OBDS_NAME));
                    description.Add(Item(summary, VSOBDESCRIPTIONSECTION.OBDS_MISC));
                }
                if (pNames.Count > 0)
                {
                    description.Add(Item(NEWLINE, VSOBDESCRIPTIONSECTION.OBDS_MISC));
                    description.Add(Item(PARAMETERS, VSOBDESCRIPTIONSECTION.OBDS_NAME));
                    for (int i = 0; i < pNames.Count; i++)
                    {
                        description.Add(Item(NEWLINE + pNames[i], VSOBDESCRIPTIONSECTION.OBDS_PARAM));
                        description.Add(Item(" : ", VSOBDESCRIPTIONSECTION.OBDS_MISC));
                        description.Add(Item(pDescriptions[i], VSOBDESCRIPTIONSECTION.OBDS_MISC));
                    }
                }
                if (!string.IsNullOrEmpty(returns))
                {
                    description.Add(Item(NEWLINE, VSOBDESCRIPTIONSECTION.OBDS_MISC));
                    description.Add(Item(RETURNS, VSOBDESCRIPTIONSECTION.OBDS_NAME));
                    description.Add(Item(returns, VSOBDESCRIPTIONSECTION.OBDS_MISC));
                }
                if (!string.IsNullOrEmpty(remarks))
                {
                    description.Add(Item(NEWLINE, VSOBDESCRIPTIONSECTION.OBDS_MISC));
                    description.Add(Item(REMARKS, VSOBDESCRIPTIONSECTION.OBDS_NAME));
                    description.Add(Item(remarks, VSOBDESCRIPTIONSECTION.OBDS_MISC));
                }
            }
        }
Exemplo n.º 10
0
        private void loadMemberCombos(int selectedType, int nLine)
        {
            var sortItems       = XSettings.EditorNavigationSorted;
            var includeFields   = XSettings.EditorNavigationIncludeFields;
            var currentTypeOnly = XSettings.EditorNavigationMembersOfCurrentTypeOnly;

            if (selectedType >= _types.Count)
            {
                return;
            }
            var currentType = (XSourceTypeSymbol)(selectedType > -1 ? _types[selectedType].Entity : _types[0].Entity);
            var globalType  = _file.GlobalType;
            DROPDOWNFONTATTR ft;
            bool             hasPartial = !currentType.IsGlobal && currentType.IsPartial;

            _members.Clear();
            _relatedFiles.Clear();
            AddSourceFile(_file.SourcePath);
            var members = new List <XSourceEntity>();

            if (currentTypeOnly)
            {
                members.AddRange(GetTypeMembers(currentType));
            }
            else
            {
                // get members of types in this file and members of partial types in other files.
                members.AddRange(GetAllMembers());
            }
            if (sortItems)
            {
                members = members.OrderBy(x => x.FullName).ToList();
            }
            // now either load all members or just the members of the current type
            // Add member for class declaration. This also makes sure that there at least one
            // element in the members list, which is convenient.
            TextSpan spM = this.TextRangeToTextSpan(currentType.Range);

            ft = DROPDOWNFONTATTR.FONTATTR_PLAIN;
            XDropDownMember elt;

            if (currentTypeOnly)
            {
                // Add a 'root' element for the type.
                if (currentType != globalType)
                {
                    if (currentType.Kind != Kind.Delegate)
                    {
                        elt = new XDropDownMember("(" + currentType.Name + ")", spM, currentType.Glyph, ft, currentType);
                        _members.Add(elt);
                    }
                }
                else
                {
                    elt = new XDropDownMember(currentType.Name, spM, currentType.Glyph, ft, currentType);
                    _members.Add(elt);
                }
            }
            foreach (XSourceEntity member in members)
            {
                bool otherFile;
                if (includeFields || (member.Kind != Kind.Field && member.Kind != Kind.VODefine))
                {
                    spM       = this.TextRangeToTextSpan(member.Range);
                    otherFile = false;
                    ft        = DROPDOWNFONTATTR.FONTATTR_PLAIN;
                    if (member.Parent is XSourceTypeSymbol typedef && typedef.IsPartial)
                    {
                        otherFile = string.Compare(member.File.FullPath, _file.FullPath, true) != 0;
                    }

                    string prototype = member.ComboPrototype;
                    bool   addPrefix = false;
                    if (currentTypeOnly)
                    {
                        addPrefix = false;
                    }
                    else
                    {
                        if (member.Parent is XSourceEntity && member.Parent.Name != XLiterals.GlobalName && member.Kind.IsClassMember(_file.Project.Dialect))
                        {
                            addPrefix = true;
                        }
                    }
                    if (addPrefix)
                    {
                        var parent = member.Parent as XSourceEntity;
                        if (member.Modifiers.HasFlag(Modifiers.Static) || member is XSourceTypeSymbol)
                        {
                            prototype = parent.ComboPrototype + "." + prototype;
                        }
                        else
                        {
                            prototype = parent.ComboPrototype + ":" + prototype;
                        }
                    }
                    if (member.Kind.IsLocal())
                    {
                        prototype = member.Parent.Name + "." + prototype;
                    }
                    if (otherFile)
                    {
                        AddSourceFile(member.File.SourcePath);
                        ft         = DROPDOWNFONTATTR.FONTATTR_GRAY;
                        prototype += " (" + System.IO.Path.GetFileName(member.File.SourcePath) + ")";
                    }
                    elt = new XDropDownMember(prototype, spM, member.Glyph, ft, member);
                    var nSelect = _members.Count;
                    _members.Add(elt);
                    if (member.Range.ContainsInclusive(nLine, 0))
                    {
                        _selectedMemberIndex = nSelect;
                        _lastSelected        = member;
                    }
                }
            }
        }