Beispiel #1
0
        /// <summary>
        /// Rescans all members.
        /// </summary>
        private void ApplyMembers()
        {
            var flags = ProcessorFlags.IncludeFileCodeModel;

            if (_optionsService.GetBoolOption(this.Feature, "XmlDoc"))
            {
                flags = flags | ProcessorFlags.IncludeMemberXmlDoc;
            }

            var members = _fileProcessor.GetMembers(flags, this.Filter);

            _sourceMembers.Clear();
            _sourceMembers.AddRange(members);             // causes filter to be evaluated
        }
Beispiel #2
0
        /// <summary>
        /// Rescans all members.
        /// </summary>
        private void ApplyMembers()
        {
            var flags = ProcessorFlags.IncludeFileCodeModel;

            if (_optionsService.GetBoolOption(this.Feature, "XmlDoc"))
            {
                flags = flags | ProcessorFlags.IncludeMemberXmlDoc;
            }

            var model    = _fileProcessor.GetMembers(flags, this.Filter);
            var members  = model.Members;
            var fileName = model.FileName;

            this.SameType = model.Members.Count(
                m => (m.ElementKind == Kind.Class) || (m.ElementKind == Kind.Interface) || (m.ElementKind == Kind.Struct) || (m.ElementKind == Kind.Enum)) <= 1;

            // Reset search on new file
            if (!string.IsNullOrEmpty(this.FileName) && !string.IsNullOrEmpty(fileName) && !fileName.Equals(this.FileName, StringComparison.OrdinalIgnoreCase))
            {
                _search = string.Empty;
            }
            this.FileName = fileName;

            string filter = null;

            if (this.Filter == CodeModelFilterFlags.All)
            {
                filter = string.Empty;
            }
            else if (this.Filter.HasFlag(CodeModelFilterFlags.ClassesInterfaces))
            {
                filter = "classes and interfaces";
            }
            else if (this.Filter.HasFlag(CodeModelFilterFlags.Methods))
            {
                filter = "methods";
            }
            else if (this.Filter.HasFlag(CodeModelFilterFlags.Properties))
            {
                filter = "properties";
            }
            this.Title = $"USysWare Code Browser {(string.IsNullOrEmpty(filter) ? string.Empty : $"- {filter} ")}- {Path.GetFileName(this.FileName)}";
Beispiel #3
0
        /// <summary>
        /// Rescans all members.
        /// </summary>
        private void ApplyMembers()
        {
            var flags = ProcessorFlags.IncludeFileCodeModel;

            if (_optionsService.GetBoolOption(this.Feature, "XmlDoc"))
            {
                flags = flags | ProcessorFlags.IncludeMemberXmlDoc;
            }

            var model    = _fileProcessor.GetMembers(flags, this.Filter);
            var members  = model.Members;
            var fileName = model.FileName;

            // Reset search on new file
            if (!string.IsNullOrEmpty(this.FileName) && !string.IsNullOrEmpty(fileName) && !fileName.Equals(this.FileName, StringComparison.OrdinalIgnoreCase))
            {
                _search = string.Empty;
            }
            this.FileName = fileName;

            _sourceMembers.Clear();
            _sourceMembers.AddRange(members);             // causes filter to be evaluated
        }
Beispiel #4
0
        /// <summary>
        /// Walks qualified project items and processes all of their qualified items.
        /// </summary>
        private void ProcessProjectItems(List <FileModel> model, ProcessorFlags flags, CodeModelFilterFlags filter, LanguageSettings languageSet,
                                         ProjectItems projectItems, bool isWebProject, ref bool isRoot, ProjectItem parentItem, string parentName)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // Parent item is applicable or meant to be used for actual files only, i.e. file combos like .cs and .designer.cs, etc.
            if (parentItem != null)
            {
                var parentItemKind = parentItem.Kind;

                if ((string.Compare(parentItemKind, Constants.vsProjectItemKindPhysicalFile, StringComparison.OrdinalIgnoreCase) != 0) &&
                    (string.Compare(parentItemKind, Constants.vsProjectItemKindSolutionItems, StringComparison.OrdinalIgnoreCase) != 0))
                {
                    parentItem = null;
                }
            }
            var parentSubType    = FileSubType.None;
            var parentSubTypeSet = false;

            if (!string.IsNullOrEmpty(parentName) && !parentName.EndsWith("\\", StringComparison.OrdinalIgnoreCase))
            {
                parentName = parentName + "\\";
            }

            // Save the current language and determine the new current language
            if (isWebProject)
            {
                var webLanguageSet = GetWebFolderLanguage(isRoot, projectItems);

                // Fallback scenario - use default project language so that non-code files can be resolved
                if (webLanguageSet?.Type != LanguageType.Unknown)
                {
                    languageSet = webLanguageSet;                     // language should be restored for other items once we walk up the stack
                }
            }

            // Root processing is finished after language is checked for the root project items
            isRoot = false;
            var projectName = string.Empty;

            foreach (ProjectItem projectItem in projectItems)
            {
                // Skip project references as they can't contribute any files
                var isReferences = projectItem.Object is VSLangProj.References;
                var isReference  = projectItem.Object is VSLangProj.Reference;
                if (isReferences || isReference)
                {
                    continue;
                }

                var projectItemKind = projectItem.Kind;

                // LightSwitch type projects with virtual references node workaround
                if (!string.IsNullOrEmpty(projectItem.Name) &&
                    projectItem.Name.Equals(REFERENCES_NODE, StringComparison.OrdinalIgnoreCase) &&
                    (string.Compare(projectItemKind, Constants.vsProjectItemKindVirtualFolder, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    continue;
                }

                if ((string.Compare(projectItemKind, Constants.vsProjectItemKindPhysicalFile, StringComparison.OrdinalIgnoreCase) == 0) ||
                    (string.Compare(projectItemKind, Constants.vsProjectItemKindSolutionItems, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    if (!parentSubTypeSet)
                    {
                        parentSubTypeSet = true;

                        if (parentItem != null)
                        {
                            parentSubType = _fileTypeResolver.GetSubType(parentItem, languageSet, isWebProject);
                        }
                    }

                    var itemSubType = _fileTypeResolver.GetSubType(projectItem, languageSet, isWebProject);

                    // Check if this is a code file
                    var add = !flags.HasFlag(ProcessorFlags.IncludeCodeFilesOnly) || _fileTypeResolver.IsCodeSubType(itemSubType);

                    // Check for .Designer file
                    if (add &&
                        !flags.HasFlag(ProcessorFlags.IncludeDesignerFiles) &&
                        _fileTypeResolver.IsDesignerItem(projectItem, itemSubType, languageSet, isWebProject))
                    {
                        add = false;
                    }

                    // Used to collect skipped files here as well... something to keep an eye out out for
                    if (add)
                    {
                        var fileName = projectItem.get_FileNames(1);
                        if (string.IsNullOrEmpty(fileName))
                        {
                            add = false;
                        }

                        if (add)
                        {
                            // Try getting a misc/simple subtype for unknown and solution projects
                            if ((languageSet?.Type == LanguageType.Unknown) && (itemSubType == FileSubType.None))
                            {
                                itemSubType = _fileTypeResolver.GetExtensionSubType(projectItem, languageSet, isWebProject);
                            }

                            if (string.IsNullOrEmpty(projectName))
                            {
                                projectName = projectItem.ContainingProject?.Name;
                            }

                            var itemModel = new FileModel
                            {
                                ProjectItem       = projectItem,
                                FileName          = projectItem.Name,
                                ParentProjectItem = parentItem,
                                ParentName        = parentName,
                                ParentSubType     = parentSubType,
                                ItemSubType       = itemSubType,
                                FileNameWithPath  = fileName,
                                ProjectName       = projectName
                            };

                            if (flags.HasFlag(ProcessorFlags.IncludeFileCodeModel))
                            {
                                var codeMembers = _fileProcessor.GetMembers(projectItem, flags, filter);
                                if ((codeMembers != null) && (codeMembers.Members != null))
                                {
                                    itemModel.Members.AddRange(codeMembers.Members);
                                }
                            }

                            model.Add(itemModel);
                        }
                    }

                    ProjectItems currentProjectItems = projectItem.ProjectItems;
                    if ((currentProjectItems != null) && (currentProjectItems.Count > 0))
                    {
                        ProcessProjectItems(
                            model, flags, filter, languageSet,
                            currentProjectItems, false, ref isRoot, projectItem, parentName);
                    }
                }
                else                 // projectItemKind
                {
                    if ((string.Compare(projectItemKind, Constants.vsProjectItemKindPhysicalFolder, StringComparison.OrdinalIgnoreCase) == 0) ||
                        (string.Compare(projectItemKind, Constants.vsProjectItemKindVirtualFolder, StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        ProjectItems currentProjectItems = projectItem.ProjectItems;
                        if ((currentProjectItems != null) && (currentProjectItems.Count > 0))
                        {
                            ProcessProjectItems(
                                model, flags, filter, languageSet,
                                currentProjectItems, isWebProject, ref isRoot, projectItem, parentName + projectItem.Name);
                        }
                    }
                }
            }             // foreach (projectItem)
        }