示例#1
0
        public override bool OnCompletionInsert(ScintillaNet.ScintillaControl sci, int position, string text, char trigger)
        {
            if (text == "Vector")
            {
                string insert = null;
                string line   = sci.GetLine(sci.LineFromPosition(position));
                Match  m      = Regex.Match(line, @"\svar\s+(?<varname>.+)\s*:\s*Vector\.<(?<indextype>.+)(?=(>\s*=))");
                if (m.Success)
                {
                    insert = String.Format(".<{0}>", m.Groups["indextype"].Value);
                }
                else
                {
                    m = Regex.Match(line, @"\s*=\s*new");
                    if (m.Success)
                    {
                        ASResult result = ASComplete.GetExpressionType(sci, sci.PositionFromLine(sci.LineFromPosition(position)) + m.Index);
                        if (result != null && !result.IsNull() && result.Member != null && result.Member.Type != null)
                        {
                            m = Regex.Match(result.Member.Type, @"(?<=<).+(?=>)");
                            if (m.Success)
                            {
                                insert = String.Format(".<{0}>", m.Value);
                            }
                        }
                    }
                    if (insert == null)
                    {
                        if (trigger == '.' || trigger == '(')
                        {
                            return(true);
                        }
                        insert = ".<>";
                        sci.InsertText(position + text.Length, insert);
                        sci.CurrentPos = position + text.Length + 2;
                        sci.SetSel(sci.CurrentPos, sci.CurrentPos);
                        ASComplete.HandleAllClassesCompletion(sci, "", false, true);
                        return(true);
                    }
                }
                if (insert == null)
                {
                    return(false);
                }
                if (trigger == '.')
                {
                    sci.InsertText(position + text.Length, insert.Substring(1));
                    sci.CurrentPos = position + text.Length;
                }
                else
                {
                    sci.InsertText(position + text.Length, insert);
                    sci.CurrentPos = position + text.Length + insert.Length;
                }
                sci.SetSel(sci.CurrentPos, sci.CurrentPos);
                return(true);
            }

            return(false);
        }
示例#2
0
        private void ProcessMouseMove(Point point)
        {
            int position = sciControl.PositionFromPointClose(point.X, point.Y);

            if (position < 0)
            {
                SetCurrentWord(null);
                return;
            }

            if (ASContext.Context.IsFileValid)
            {
                Word word = new Word();
                word.StartPos = sciControl.WordStartPosition(position, true);
                word.EndPos   = sciControl.WordEndPosition(position, true);

                ASResult result = ASComplete.GetExpressionType(sciControl, word.EndPos);
                if (!result.IsNull())
                {
                    SetCurrentWord(word);
                }
                else
                {
                    SetCurrentWord(null);
                }
            }
        }
示例#3
0
        public virtual ASResult GetCollectionOfForeachStatement(ScintillaControl sci, int startPosition)
        {
            var result      = new ASResult();
            var parCount    = 0;
            var endPosition = sci.TextLength;
            var pos         = startPosition;

            while (pos < endPosition)
            {
                if (!sci.PositionIsOnComment(pos))
                {
                    var c = (char)sci.CharAt(pos);
                    if (c > ' ')
                    {
                        if (c == '(')
                        {
                            parCount++;
                        }
                        else if (c == ')')
                        {
                            parCount--;
                            if (parCount == 0)
                            {
                                result = ASComplete.GetExpressionType(sci, pos);
                                break;
                            }
                        }
                    }
                }
                pos++;
            }
            return(result);
        }
示例#4
0
        private void OnMouseHover(ScintillaNet.ScintillaControl sci, int position)
        {
            if (!ASContext.Context.IsFileValid)
            {
                return;
            }

            lastHoverPosition = position;

            // get word at mouse position
            int style = sci.BaseStyleAt(position);

            if (!ASComplete.IsTextStyle(style))
            {
                return;
            }
            position = sci.WordEndPosition(position, true);
            ASResult result = ASComplete.GetExpressionType(sci, position);

            // set tooltip
            if (!result.IsNull())
            {
                string text = ASComplete.GetToolTipText(result);
                if (text == null)
                {
                    return;
                }
                // show tooltip
                UITools.Tip.ShowAtMouseLocation(text);
            }
        }
示例#5
0
        private void OnMouseHover(ScintillaNet.ScintillaControl sci, int position)
        {
            if (ASContext.Locked || !ASContext.Context.IsFileValid())
            {
                return;
            }

            // get word at mouse position
            int style = sci.BaseStyleAt(position);

            DebugConsole.Trace("Style=" + style);
            if (!ASComplete.IsTextStyle(style))
            {
                return;
            }
            position = sci.WordEndPosition(position, true);
            ASResult result = ASComplete.GetExpressionType(sci, position);

            // set tooltip
            if (!result.IsNull())
            {
                string text = ASComplete.GetToolTipText(result);
                DebugConsole.Trace("SHOW " + text);
                if (text == null)
                {
                    return;
                }
                // show tooltip
                InfoTip.ShowAtMouseLocation(text);
            }
        }
        void ProcessMouseMove(Point point)
        {
            int position = sci.PositionFromPointClose(point.X, point.Y);

            if (position < 0)
            {
                SetCurrentWord(null);
            }
            else if (ASContext.Context.IsFileValid)
            {
                Word word = new Word
                {
                    StartPos = sci.WordStartPosition(position, true),
                    EndPos   = sci.WordEndPosition(position, true)
                };
                ASResult expr = ASComplete.GetExpressionType(sci, word.EndPos);
                if (expr.IsNull())
                {
                    string overrideKey = ASContext.Context.Features.overrideKey;
                    if (expr.Context == null || !expr.Context.BeforeBody || string.IsNullOrEmpty(overrideKey) || sci.GetWordFromPosition(position) != overrideKey)
                    {
                        word = null;
                    }
                }
                SetCurrentWord(word);
            }
        }
        public new ASResult GetVarOfForeachStatement(ScintillaControl sci, int startPosition)
        {
            var result         = new ASResult();
            var parCount       = 0;
            var characterClass = ScintillaControl.Configuration.GetLanguage(sci.ConfigurationLanguage).characterclass.Characters;
            var endPosition    = sci.TextLength;
            var pos            = startPosition;

            while (pos < endPosition)
            {
                if (!sci.PositionIsOnComment(pos))
                {
                    var c = (char)sci.CharAt(pos);
                    if (c > ' ')
                    {
                        if (parCount == 0 && c == '(')
                        {
                            parCount++;
                        }
                        else if (parCount == 1 && characterClass.IndexOf(c) != -1)
                        {
                            pos    = sci.WordEndPosition(pos, true);
                            result = ASComplete.GetExpressionType(sci, pos);
                            break;
                        }
                    }
                }
                pos++;
            }
            return(result);
        }
示例#8
0
            public void SimpleTest()
            {
                //TODO: Improve this test with more checks!
                var pluginMain   = Substitute.For <PluginMain>();
                var pluginUiMock = new PluginUIMock(pluginMain);

                pluginMain.MenuItems.Returns(new List <System.Windows.Forms.ToolStripItem>());
                pluginMain.Settings.Returns(new GeneralSettings());
                pluginMain.Panel.Returns(pluginUiMock);
                ASContext.GlobalInit(pluginMain);
                ASContext.Context             = Substitute.For <IASContext>();
                ASContext.Context.CurrentLine = 9;
                var asContext = new AS3Context.Context(new AS3Settings());

                ASContext.Context.Features.Returns(asContext.Features);
                ASContext.Context.GetCodeModel(null).ReturnsForAnyArgs(x => asContext.GetCodeModel(x.ArgAt <string>(0)));

                // Maybe we want to get the filemodel from ASFileParser even if we won't get a controlled environment?
                var member = new MemberModel("test1", "void", FlagType.Function, Visibility.Public)
                {
                    LineFrom   = 4,
                    LineTo     = 10,
                    Parameters = new List <MemberModel>
                    {
                        new MemberModel("arg1", "String", FlagType.ParameterVar, Visibility.Default),
                        new MemberModel("arg2", "Boolean", FlagType.ParameterVar, Visibility.Default)
                        {
                            Value = "false"
                        }
                    }
                };

                var classModel = new ClassModel();

                classModel.Name = "ASCompleteTest";
                classModel.Members.Add(member);

                var fileModel = new FileModel();

                fileModel.Classes.Add(classModel);

                classModel.InFile = fileModel;

                ASContext.Context.CurrentModel.Returns(fileModel);
                ASContext.Context.CurrentClass.Returns(classModel);
                ASContext.Context.CurrentMember.Returns(member);

                var sci = GetBaseScintillaControl();

                sci.Text = TestFile.ReadAllText("ASCompletion.Test_Files.completion.as3.SimpleTest.as");
                sci.ConfigurationLanguage = "as3";
                sci.Colourise(0, -1);

                var result = ASComplete.GetExpressionType(sci, 185);

                Assert.True(result.Context != null && result.Context.LocalVars != null);
                Assert.AreEqual(4, result.Context.LocalVars.Count);
            }
示例#9
0
        /// <summary>
        /// Retrieves the refactoring target based on the current location.
        /// Note that this will look up to the declaration source.
        /// This allows users to execute the rename from a reference to the source rather than having to navigate to the source first.
        /// </summary>
        public static ASResult GetDefaultRefactorTarget()
        {
            ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl;

            if (!ASContext.Context.IsFileValid || (sci == null))
            {
                return(null);
            }
            int position = sci.WordEndPosition(sci.CurrentPos, true);

            return(ASComplete.GetExpressionType(sci, position));
        }
示例#10
0
        /// <summary>
        /// Gets the result for menu updating from current position.
        /// </summary>
        private ASResult GetResultFromCurrentPosition()
        {
            ITabbedDocument document = PluginBase.MainForm.CurrentDocument;

            if (document == null || document.SciControl == null || !ASContext.Context.IsFileValid)
            {
                return(null);
            }
            Int32    position = document.SciControl.WordEndPosition(document.SciControl.CurrentPos, true);
            ASResult result   = ASComplete.GetExpressionType(document.SciControl, position);

            return(result == null && result.IsNull() ? null : result);
        }
示例#11
0
        private void OnMouseHover(ScintillaControl sci, int position)
        {
            if (!ASContext.Context.IsFileValid)
            {
                return;
            }

            lastHoverPosition = position;

            // get word at mouse position
            int style = sci.BaseStyleAt(position);

            if (!ASComplete.IsTextStyle(style))
            {
                return;
            }
            position = sci.WordEndPosition(position, true);
            ASResult result = ASComplete.GetExpressionType(sci, position);

            // set tooltip
            if (!result.IsNull())
            {
                if (Control.ModifierKeys == Keys.Control)
                {
                    var code = ASComplete.GetCodeTipCode(result);
                    if (code == null)
                    {
                        return;
                    }
                    UITools.CodeTip.Show(sci, position - result.Path.Length, code);
                }
                else
                {
                    string text = ASComplete.GetToolTipText(result);
                    if (text == null)
                    {
                        return;
                    }
                    // show tooltip
                    UITools.Tip.ShowAtMouseLocation(text);
                }
            }
        }
示例#12
0
        public bool IsImported(string sourceText)
        {
            MemberModel member;

            if (sourceText != null)
            {
                SetSrc(sci, sourceText);
                var expr = ASComplete.GetExpressionType(sci, ASComplete.ExpressionEndPosition(sci, sci.CurrentPos), false, true);
                if (expr.Type != null)
                {
                    member = expr.Type;
                }
                else
                {
                    var type = sci.GetWordFromPosition(sci.CurrentPos);
                    member = new MemberModel(type, type, FlagType.Class, Visibility.Public);
                }
            }
            else
            {
                member = ClassModel.VoidClass;
            }
            return(ASContext.Context.IsImported(member, sci.CurrentLine));
        }
示例#13
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)
        {
            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 != null && result.Member.InFile != null) ? result.Member.InFile : null) ?? ((result.Type != null) ? result.Type.InFile : null);
                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))
                    {
                        ASContext.MainForm.OpenEditableDocument(model.FileName, false);
                    }
                    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);
                        }
                    }
                }
                if ((inClass == null || inClass.IsVoid()) && result.Member == null)
                {
                    return(null);
                }
                Sci = ASContext.CurSciControl;
                if (Sci == 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("(class|interface)", name, line);
                    }
                    else
                    {
                        ASComplete.LocateMember("(function|var|const|get|set|property|[,(])", name, line);
                    }
                }
                return(result);
            }
            return(null);
        }
示例#14
0
 /// <summary>
 /// Renames the given the set of matched references
 /// </summary>
 private void OnFindAllReferencesCompleted(object sender, RefactorCompleteEventArgs<IDictionary<string, List<SearchMatch>>> eventArgs)
 {
     UserInterfaceManager.ProgressDialog.Show();
     UserInterfaceManager.ProgressDialog.SetTitle(TextHelper.GetString("Info.UpdatingReferences"));
     MessageBar.Locked = true;
     var isParameterVar = (Target.Member?.Flags & FlagType.ParameterVar) > 0;
     foreach (var entry in eventArgs.Results)
     {
         UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.Updating") + " \"" + entry.Key + "\"");
         // re-open the document and replace all the text
         var doc = AssociatedDocumentHelper.LoadDocument(entry.Key);
         var sci = doc.SciControl;
         var targetMatches = entry.Value;
         if (isParameterVar)
         {
             var lineFrom = Target.Context.ContextFunction.LineFrom;
             var lineTo = Target.Context.ContextFunction.LineTo;
             var search = new FRSearch(NewName) {WholeWord = true, NoCase = false, SingleLine = true};
             var matches = search.Matches(sci.Text, sci.PositionFromLine(lineFrom), lineFrom);
             matches.RemoveAll(it => it.Line < lineFrom || it.Line > lineTo);
             if (matches.Count != 0)
             {
                 sci.BeginUndoAction();
                 try
                 {
                     for (var i = 0; i < matches.Count; i++)
                     {
                         var match = matches[i];
                         var expr = ASComplete.GetExpressionType(sci, sci.MBSafePosition(match.Index) + sci.MBSafeTextLength(match.Value));
                         if (expr.IsNull() || expr.Context.Value != NewName) continue;
                         string replacement;
                         var flags = expr.Member.Flags;
                         if ((flags & FlagType.Static) > 0) replacement = ASContext.Context.CurrentClass.Name + "." + NewName;
                         else if((flags & FlagType.LocalVar) == 0) replacement = "this." + NewName;
                         else continue;
                         RefactoringHelper.SelectMatch(sci, match);
                         sci.EnsureVisible(sci.LineFromPosition(sci.MBSafePosition(match.Index)));
                         sci.ReplaceSel(replacement);
                         for (var j = 0; j < targetMatches.Count; j++)
                         {
                             var targetMatch = targetMatches[j];
                             if (targetMatch.Line <= match.Line) continue;
                             FRSearch.PadIndexes(targetMatches, j, match.Value, replacement);
                             if (targetMatch.Line == match.Line + 1)
                             {
                                 targetMatch.LineText = sci.GetLine(match.Line);
                                 targetMatch.Column += replacement.Length - match.Value.Length;
                             }
                             break;
                         }
                         FRSearch.PadIndexes(matches, i + 1, match.Value, replacement);
                     }
                 }
                 finally
                 {
                     sci.EndUndoAction();
                 }
             }
         }
         // replace matches in the current file with the new name
         RefactoringHelper.ReplaceMatches(targetMatches, sci, NewName);
         //Uncomment if we want to keep modified files
         //if (sci.IsModify) AssociatedDocumentHelper.MarkDocumentToKeep(entry.Key);
         doc.Save();
     }
     if (newFileName != null) RenameFile(eventArgs.Results);
     Results = eventArgs.Results;
     AssociatedDocumentHelper.CloseTemporarilyOpenedDocuments();
     if (OutputResults) ReportResults();
     UserInterfaceManager.ProgressDialog.Hide();
     MessageBar.Locked = false;
     FireOnRefactorComplete();
 }