示例#1
0
        /// <summary>
        /// Retrieves the refactoring target based on the file.
        /// </summary>
        public static ASResult GetRefactorTargetFromFile(string path, DocumentHelper associatedDocumentHelper)
        {
            String           fileName = Path.GetFileNameWithoutExtension(path);
            Int32            line     = 0;
            var              doc      = associatedDocumentHelper.LoadDocument(path);
            ScintillaControl sci      = doc != null ? doc.SciControl : null;

            if (sci == null)
            {
                return(null);             // Should not happen...
            }
            List <ClassModel> classes = ASContext.Context.CurrentModel.Classes;

            if (classes.Count > 0)
            {
                foreach (ClassModel classModel in classes)
                {
                    if (classModel.Name.Equals(fileName))
                    {
                        // Optimization, we don't need to make a full lookup in this case
                        return(new ASResult
                        {
                            IsStatic = true,
                            Type = classModel
                        });
                    }
                }
            }
            else
            {
                foreach (MemberModel member in ASContext.Context.CurrentModel.Members)
                {
                    if (member.Name.Equals(fileName))
                    {
                        line = member.LineFrom;
                        break;
                    }
                }
            }
            if (line > 0)
            {
                sci.SelectText(fileName, sci.PositionFromLine(line));
                return(GetDefaultRefactorTarget());
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// Checks if a given search match actually points to the given target source
        /// </summary>
        /// <returns>True if the SearchMatch does point to the target source.</returns>
        public static ASResult DeclarationLookupResult(ScintillaControl Sci, int position, DocumentHelper associatedDocumentHelper)
        {
            if (!ASContext.Context.IsFileValid || (Sci == null))
            {
                return(null);
            }
            // get type at cursor position
            ASResult result = ASComplete.GetExpressionType(Sci, position);

            if (result.IsPackage)
            {
                return(result);
            }
            // open source and show declaration
            if (!result.IsNull())
            {
                if (result.Member != null && (result.Member.Flags & FlagType.AutomaticVar) > 0)
                {
                    return(null);
                }
                FileModel model = result.InFile ?? result.Member?.InFile ?? result.Type?.InFile;
                if (model == null || model.FileName == "")
                {
                    return(null);
                }
                ClassModel inClass = result.InClass ?? result.Type;
                // for Back command
                int lookupLine = Sci.CurrentLine;
                int lookupCol  = Sci.CurrentPos - Sci.PositionFromLine(lookupLine);
                ASContext.Panel.SetLastLookupPosition(ASContext.Context.CurrentFile, lookupLine, lookupCol);
                // open the file
                if (model != ASContext.Context.CurrentModel)
                {
                    if (model.FileName.Length > 0 && File.Exists(model.FileName))
                    {
                        if (!associatedDocumentHelper.ContainsOpenedDocument(model.FileName))
                        {
                            associatedDocumentHelper.LoadDocument(model.FileName);
                        }
                        Sci = associatedDocumentHelper.GetOpenedDocument(model.FileName).SciControl;
                    }
                    else
                    {
                        ASComplete.OpenVirtualFile(model);
                        result.InFile = ASContext.Context.CurrentModel;
                        if (result.InFile == null)
                        {
                            return(null);
                        }
                        if (inClass != null)
                        {
                            inClass = result.InFile.GetClassByName(inClass.Name);
                            if (result.Member != null)
                            {
                                result.Member = inClass.Members.Search(result.Member.Name, 0, 0);
                            }
                        }
                        else if (result.Member != null)
                        {
                            result.Member = result.InFile.Members.Search(result.Member.Name, 0, 0);
                        }
                        Sci = ASContext.CurSciControl;
                    }
                }
                if (Sci == null)
                {
                    return(null);
                }
                if ((inClass == null || inClass.IsVoid()) && result.Member == null)
                {
                    return(null);
                }
                int    line    = 0;
                string name    = null;
                bool   isClass = false;
                // member
                if (result.Member != null && result.Member.LineFrom > 0)
                {
                    line = result.Member.LineFrom;
                    name = result.Member.Name;
                }
                // class declaration
                else if (inClass.LineFrom > 0)
                {
                    line    = inClass.LineFrom;
                    name    = inClass.Name;
                    isClass = true;
                    // constructor
                    foreach (MemberModel member in inClass.Members)
                    {
                        if ((member.Flags & FlagType.Constructor) > 0)
                        {
                            line    = member.LineFrom;
                            name    = member.Name;
                            isClass = false;
                            break;
                        }
                    }
                }
                if (line > 0) // select
                {
                    if (isClass)
                    {
                        ASComplete.LocateMember(Sci, "(class|interface)", name, line);
                    }
                    else
                    {
                        ASComplete.LocateMember(Sci, "(function|var|const|get|set|property|[,(])", name, line);
                    }
                }
                return(result);
            }
            return(null);
        }
        /// <summary>
        /// Retrieves the refactoring target based on the file.
        /// </summary>
        public static ASResult GetRefactorTargetFromFile(string path, DocumentHelper associatedDocumentHelper)
        {
            String fileName = Path.GetFileNameWithoutExtension(path);
            Int32 line = 0;
            var doc = associatedDocumentHelper.LoadDocument(path);
            ScintillaControl sci = doc != null ? doc.SciControl : null;
            if (sci == null) return null; // Should not happen...
            List<ClassModel> classes = ASContext.Context.CurrentModel.Classes;
            if (classes.Count > 0)
            {
                foreach (ClassModel classModel in classes)
                {
                    if (classModel.Name.Equals(fileName))
                    {
                        // Optimization, we don't need to make a full lookup in this case
                        return new ASResult
                        {
                            IsStatic = true,
                            Type = classModel
                        };
                    }
                }
            }
            else
            {
                foreach (MemberModel member in ASContext.Context.CurrentModel.Members)
                {
                    if (member.Name.Equals(fileName))
                    {
                        line = member.LineFrom;
                        break;
                    }
                }
            }
            if (line > 0)
            {
                sci.SelectText(fileName, sci.PositionFromLine(line));
                return GetDefaultRefactorTarget();
            }

            return null;
        }