public void TestFunctionInsideClass() { string code = @" class A { x : var; constructor A() { x = 10; } def foo : int(a : int, b : int) { return = a + b; } def bar : int(a : int, b : int) { } }"; AutoCompletionHelper.Reset(); AutoCompletionHelper.Compile(code, null); List <AutoCompletionHelper.MethodSignature> sigs = AutoCompletionHelper.GetMethodParameterList(17, 10, "foo", null); List <AutoCompletionHelper.MethodSignature> sigs2 = AutoCompletionHelper.GetMethodParameterList(17, 10, "this.foo", null); Assert.IsTrue(sigs.Count == 1); Assert.IsTrue(sigs[0].MethodName == "A.foo"); Assert.IsTrue(sigs2.Count == 1); Assert.IsTrue(sigs2[0].MethodName == "A.foo"); }
public void TestInsideGlobalScope() { string code = @" class Point { x : var; y : var; z : var; constructor Point() { x = 1; y = 2; z = 3; } def foo : sum() { return = x + y + z; } } p = Point.Point(); // This is line 20 // This is line 21 "; List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list1 = AutoCompletionHelper.GetList(22, 1, code, "p", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list2 = AutoCompletionHelper.GetList(22, 1, code, "Point", null); Assert.AreEqual(4, list1.Count); // x, y, z, sum Assert.AreEqual(1, list2.Count); // Point Assert.IsTrue((list2[0].Key & AutoCompletionHelper.MemberType.Constructor) != 0); }
public void TestDoubleDotCrash002() { string code = @"a = 2.."; List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list1 = AutoCompletionHelper.GetList(1, 6, code, ".", null); Assert.IsTrue(list1.Count == 0); }
private void HideFunctionSignaturePopup() { AutoCompletionHelper.Reset(); if (null != functionSignaturePopup) { functionSignatureControl.ResetContent(); functionSignaturePopup.IsOpen = false; } }
internal bool UpdateForFunctionArgument(int line, int column, string function, int argument) { if (string.IsNullOrEmpty(function)) { return(false); } IScriptObject activeScript = Solution.Current.ActiveScript; string filePath = activeScript.GetParsedScript().GetScriptPath(); if (string.IsNullOrEmpty(filePath)) { filePath = null; } bool updateVisual = false; if (currentFunctionName != function) { AutoCompletionHelper.SetSearchPaths(ExtensionFactory.GetSearchPaths()); signatures = AutoCompletionHelper.GetMethodParameterList( line, column, function, filePath); currentFunctionName = function; updateVisual = true; } if (null == signatures || (signatures.Count == 0)) { return(false); // Could not retrieve any function information. } // Update visual if there's change in argument index. updateVisual = (updateVisual || (this.currentArgumentIndex != argument)); this.currentArgumentIndex = argument; if (false == updateVisual) { return(true); // Visual remains the same. } if (0 == CurrentOverload || (CurrentOverload > TotalOverloads)) { CurrentOverload = 1; } NotifyPropertyChanged("CurrentOverload"); NotifyPropertyChanged("TotalOverloads"); NotifyPropertyChanged("IsOverloaded"); UpdateFormattedOutput(); Logger.LogInfo("AutoComplete-UpdateToolTip", GetLoggingInfo()); return(true); }
public void TestNameLoopupInLanguageBlock() { string code = @" class Point { private x : var; protected static w : var; y : var; z : var; constructor Point() { x = 1; y = 2; z = 3; } def foo : sum() { p = Point.Point(); // This is line 18 return = x + y + z; } } p = Point.Point(); [Imperative] { // This is line 27 } def foo : int() { p1 = Point.Point(); [Imperative] { // This is line 35 } return = 10; } "; List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list1 = AutoCompletionHelper.GetList(18, 1, code, "p", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list2 = AutoCompletionHelper.GetList(27, 1, code, "p", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list3 = AutoCompletionHelper.GetList(35, 1, code, "p1", null); Assert.AreEqual(4, list1.Count); // x, y, z, sum Assert.AreEqual(3, list2.Count); // y, z, sum Assert.AreEqual(3, list3.Count); // y, z, sum }
public void TestBasicIdentifierList() { string code = @" class A { public x : var; public static y : var; private z : var; protected static w : var; public constructor A() { } public def foo : int() { return = 10; } } class B { public a : A; public static b : A; constructor B() { } } b = B.B(); "; List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list1 = AutoCompletionHelper.GetList(25, 10, code, "this.a", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list2 = AutoCompletionHelper.GetList(25, 10, code, "B.b", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list3 = AutoCompletionHelper.GetList(29, 10, code, "b.a", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list4 = AutoCompletionHelper.GetList(29, 10, code, "B.b", null); Assert.IsTrue(list1.Count == 2); // Only public 'x' and 'foo'. Assert.IsTrue(list2.Count == 2); // Only public 'x' and 'foo'. Assert.IsTrue(list3.Count == 2); // Only public 'x' and 'foo'. Assert.IsTrue(list4.Count == 2); // Only public 'x' and 'foo'. }
public void TestBasicIdentifierList() { string code = @" class A { public x : var; public static y : var; private z : var; protected static w : var; public constructor A() { } public def foo : int() { return = 10; } } class B { public a : A; public static b : A; constructor B() { } } b = B.B(); "; AutoCompletionHelper.Reset(); AutoCompletionHelper.Compile(code, null); List <AutoCompletionHelper.MethodSignature> sigs = AutoCompletionHelper.GetMethodParameterList(30, 10, "b.a.foo", null); List <AutoCompletionHelper.MethodSignature> sigs2 = AutoCompletionHelper.GetMethodParameterList(30, 10, "B.b.foo", null); Assert.IsTrue(sigs.Count == 1); Assert.IsTrue(sigs[0].MethodName == "A.foo"); Assert.IsTrue(sigs2.Count == 1); Assert.IsTrue(sigs2[0].MethodName == "A.foo"); }
public void TestDoubleDotCrash001() { string code = @" class Sample { x : var; constructor Sample() { x = 10; } } // S = Sample.. "; List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list1 = AutoCompletionHelper.GetList(11, 5, code, "Sample", null); Assert.IsTrue(list1.Count == 1 && list1[0].Value == "Sample"); }
public void TestRankedAndMixedTypeArray01() { string code = @" class A { constructor A(i){ } def foo() { } } class B { constructor B() { } def faa() { } def foo() { } static def bar() { } } arr = { A.A(), 1, { 2, B.B() }, 5 };//line 26 "; List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list1 = AutoCompletionHelper.GetList(28, 1, code, "arr", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list2 = AutoCompletionHelper.GetList(28, 1, code, "arr[0]", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list3 = AutoCompletionHelper.GetList(28, 1, code, "arr[2][1]", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list4 = AutoCompletionHelper.GetList(28, 1, code, "B", null); Assert.AreEqual(1, list1.Count); // foo Assert.AreEqual(1, list2.Count); // foo Assert.AreEqual(2, list3.Count); // faa,foo Assert.AreEqual(2, list4.Count); // B,bar }
public void TestInnerBlockCrash() { string code = "[Imperative]\n" + "{\n" + " if (0 < 10)\n" + " {\n" + " a = foo\n" + " }\n" + "\n" + " return = 0;\n" + "}\n"; AutoCompletionHelper.Reset(); AutoCompletionHelper.Compile(code, null); List <AutoCompletionHelper.MethodSignature> signatures = null; signatures = AutoCompletionHelper.GetMethodParameterList(4, 15, "foo", null); Assert.AreNotEqual(null, signatures); Assert.AreEqual(0, signatures.Count); // "foo" is undefined! }
public void TestRangeExpression() { string code = @" class Range { constructor Expression(a : int, b : int) { return = a + b; } def DoNothing() { } } a = Range.Expression(1..5..1, 2..5..1); b = Range.Expression(1..5..1, 2..5); // Line #20"; List <KeyValuePair <AutoCompletionHelper.MemberType, string> > completionList = null; completionList = AutoCompletionHelper.GetList(20, 1, code, "a", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(1, completionList.Count); Assert.AreEqual("DoNothing", completionList[0].Value); completionList = AutoCompletionHelper.GetList(20, 1, code, "b", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(1, completionList.Count); Assert.AreEqual("DoNothing", completionList[0].Value); }
/// <summary> /// This method is called just once at the beginning when function /// tool-tip is about to be displayed. It generates the necessary data /// ready for queries by the function tool-tip control. This data stays /// for as long as the tool-tip stays visible, user can go from one /// function to the next with arrow keys, the function signature tool- /// tip will highlight the corresponding argument, or be refreshed with /// information of a new function (e.g. when user moves the cursor from /// one function to the next in a nested function call). Due to this /// reason, this method is not function-specific, it compiles the entire /// source code. /// </summary> private bool GenerateCompletionDataForCallContext() { if (AutoCompletionHelper.IsHelperReset == false) { return(true); // There's no need to recompute. } int[] linesToExclude = new int[] { textCore.CursorPosition.Y }; ITextBuffer textBuffer = textCore.CurrentTextBuffer; string partialContent = textBuffer.GetPartialContent(linesToExclude, " \n"); if (null == AutoCompletionHelper.MessageHandler) { AutoCompletionHelper.MessageHandler = new AutoCompleteMessageHandler(textEditorControl); } // Clear output stream messages before attempting another compilation. AutoCompleteMessageHandler messageHandler = null; messageHandler = AutoCompletionHelper.MessageHandler as AutoCompleteMessageHandler; messageHandler.ClearMessages(); IScriptObject activeScript = Solution.Current.ActiveScript; string filePath = activeScript.GetParsedScript().GetScriptPath(); if (string.IsNullOrEmpty(filePath)) { filePath = null; } if (AutoCompletionHelper.Compile(partialContent, filePath) == false) { return(false); } messageHandler.DisplayPossibleErrors(); return(true); }
public void TestInsideClassMemberFunctionScopeAndThisKeyword() { string code = @" class Point { private x : var; protected static w : var; y : var; z : var; constructor Point() { x = 1; y = 2; z = 3; } def foo : sum() { p = Point.Point(); // This is line 18 return = x + y + z; } } p = Point.Point(); "; List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list1 = AutoCompletionHelper.GetList(18, 1, code, "Point", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list2 = AutoCompletionHelper.GetList(18, 1, code, "p", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list3 = AutoCompletionHelper.GetList(18, 1, code, "this", null); Assert.AreEqual(2, list1.Count); // w, Point Assert.AreEqual(4, list2.Count); // x, y, z, foo Assert.AreEqual(4, list3.Count); // x, y, z, foo }
public void TestAutoCompleteInternalMethods() { string code = @" class A { constructor A(i) { } def foo() { } } p = A.A({ 1, 2, 3 }); q = A.A(); "; List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list1 = AutoCompletionHelper.GetList(14, 1, code, "p", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list2 = AutoCompletionHelper.GetList(15, 1, code, "q", null); Assert.AreEqual(1, list1.Count); // foo Assert.AreEqual(1, list2.Count); // foo }
/// <summary> /// Method to retrieve AutoComplete list and bind it to visual element /// </summary> private void DoAutoComplete(string variable) { Logger.LogInfo("DoAutoComplete", variable); EnsureAutoCompleteListCreated(); IScriptObject activeScript = Solution.Current.ActiveScript; string filePath = activeScript.GetParsedScript().GetScriptPath(); if (filePath == string.Empty) { filePath = null; } int[] linesToExclude = new int[] { textCore.CursorPosition.Y }; ITextBuffer textBuffer = textCore.CurrentTextBuffer; string partialContent = textBuffer.GetPartialContent(linesToExclude, " \n"); if (null == AutoCompletionHelper.MessageHandler) { AutoCompletionHelper.MessageHandler = new AutoCompleteMessageHandler(textEditorControl); } // Clear output stream messages before attempting another compilation. AutoCompleteMessageHandler messageHandler = null; messageHandler = AutoCompletionHelper.MessageHandler as AutoCompleteMessageHandler; messageHandler.ClearMessages(); AutoCompletionHelper.SetSearchPaths(ExtensionFactory.GetSearchPaths()); // Method to contact IDECodeGen.dll to retrieve the list for AutoComplete items List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list = AutoCompletionHelper.GetList(textCore.CursorPosition.Y, textCore.CursorPosition.X, partialContent, variable, filePath); messageHandler.DisplayPossibleErrors(); if (list.Count == 0) { return; } CharPosition position = activeScript.CreateCharPosition(); position.SetCharacterPosition(textCore.CursorPosition.X, textCore.CursorPosition.Y); // Add each AutoComplete Item one at a time Keyboard.Focus(textEditorCanvas); autoCompleteList.ClearList(); autoCompleteList.AddItemsToList(list); autoCompletePopup.Placement = PlacementMode.Custom; autoCompletePopup.PlacementTarget = textEditorCanvas; autoCompletePopup.CursorPosition = textCore.CursorPosition; autoCompletePopup.IsOpen = true; // The focus shift is important as the AutoCompleteList will // be re-routing events back to the main control now. autoCompleteList.DoFocusOnFirstItem(); autoCompletePopup.Width = autoCompleteList.Width; autoCompletePopup.Height = autoCompleteList.Height; }
public void TestRankedAndMixedTypeArray03() { string code = @" class Aaah { constructor Oooh() { } def Yeeeah : int() { return = 23; } } class Beee { constructor Booo() { a = { 1.0, Aaah.Oooh() }; // Line #20 } } c = { 1.0, Aaah.Oooh() }; // Line #26 "; List <KeyValuePair <AutoCompletionHelper.MemberType, string> > completionList = null; completionList = AutoCompletionHelper.GetList(20, 1, code, "a", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(0, completionList.Count); completionList = AutoCompletionHelper.GetList(20, 1, code, "a[0]", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(0, completionList.Count); completionList = AutoCompletionHelper.GetList(20, 1, code, "a[1]", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(1, completionList.Count); Assert.AreEqual("Yeeeah", completionList[0].Value); completionList = AutoCompletionHelper.GetList(20, 1, code, "a[2]", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(0, completionList.Count); completionList = AutoCompletionHelper.GetList(26, 1, code, "c", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(0, completionList.Count); completionList = AutoCompletionHelper.GetList(26, 1, code, "c[0]", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(0, completionList.Count); completionList = AutoCompletionHelper.GetList(26, 1, code, "c[1]", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(1, completionList.Count); Assert.AreEqual("Yeeeah", completionList[0].Value); completionList = AutoCompletionHelper.GetList(26, 1, code, "c[2]", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(0, completionList.Count); }
public void TestClassInheritance() { string code = @" class Base { public x : var; protected y : var; private z : var; public def foo1 : int() { return = 10; } protected def foo2 : int() { return = 10; } private def foo3 : int() { return = 10; } public static def foo4 : int() { return = 10; } protected static def foo5 : int() { return = 10; } private static def foo6 : int() { return = 11; } public constructor Base() { // This is line 39 } } class Derived extends Base { public w : var; public constructor Derived() { // This is line 49 } public def bar1 : int() { return = 101; } protected def bar2 : int() { return = 102; } private def bar3 : int() { return = 103; } public static def bar4 : int() { return = 104; } protected static def bar5 : int() { return = 105; } private static def bar6 : int() { return = 106; } } "; List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list1 = AutoCompletionHelper.GetList(39, 1, code, "this", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list2 = AutoCompletionHelper.GetList(39, 1, code, "Base", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list3 = AutoCompletionHelper.GetList(49, 1, code, "this", null); List <KeyValuePair <AutoCompletionHelper.MemberType, string> > list4 = AutoCompletionHelper.GetList(49, 1, code, "Derived", null); Assert.AreEqual(6, list1.Count); // x, y, z, foo1, foo2, foo3 Assert.AreEqual(4, list2.Count); // foo4, foo5, foo6, Base Assert.AreEqual(8, list3.Count); // x, y, w, foo1, foo2, bar1, bar2, bar3 Assert.AreEqual(6, list4.Count); // foo4, foo5, bar4, bar5, bar6, Derived }
public void TestRankedAndMixedTypeArray02() { string code = @" class ClassOne { constructor ByValues(values : int[]) { } def DoubleTheValue : double(value : double) { return = value * 2.0; } } class ClassTwo { luckValue : int; constructor ByLuck(values : int[]) { luckValue = values[0]; } def GetLuckLevel : int() { return = luckValue; } } first = ClassOne.ByValues({ 1, 2 }); // Line #28 second = ClassTwo.ByLuck({ 1, 2 }); // Line #29 abracadabra = 3; third = { first, second, { second, first } }; // Line #33 "; List <KeyValuePair <AutoCompletionHelper.MemberType, string> > completionList = null; completionList = AutoCompletionHelper.GetList(30, 1, code, "first", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(1, completionList.Count); Assert.AreEqual("DoubleTheValue", completionList[0].Value); completionList = AutoCompletionHelper.GetList(30, 1, code, "second", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(2, completionList.Count); Assert.AreEqual("luckValue", completionList[0].Value); Assert.AreEqual("GetLuckLevel", completionList[1].Value); completionList = AutoCompletionHelper.GetList(35, 1, code, "third", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(1, completionList.Count); // Type defaulted to "first" ("ClassOne"). Assert.AreEqual("DoubleTheValue", completionList[0].Value); completionList = AutoCompletionHelper.GetList(35, 1, code, "third[0]", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(1, completionList.Count); // Type defaulted to "first" ("ClassOne"). Assert.AreEqual("DoubleTheValue", completionList[0].Value); completionList = AutoCompletionHelper.GetList(35, 1, code, "third[1]", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(2, completionList.Count); Assert.AreEqual("luckValue", completionList[0].Value); Assert.AreEqual("GetLuckLevel", completionList[1].Value); completionList = AutoCompletionHelper.GetList(35, 1, code, "third[100]", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(1, completionList.Count); // Out-of-bound defaulted to "first" ("ClassOne"). Assert.AreEqual("DoubleTheValue", completionList[0].Value); completionList = AutoCompletionHelper.GetList(35, 1, code, "third[2][0]", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(2, completionList.Count); // Nested "ClassTwo" type. Assert.AreEqual("luckValue", completionList[0].Value); Assert.AreEqual("GetLuckLevel", completionList[1].Value); completionList = AutoCompletionHelper.GetList(35, 1, code, "third[2][1]", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(1, completionList.Count); // Nested "ClassOne" type. Assert.AreEqual("DoubleTheValue", completionList[0].Value); completionList = AutoCompletionHelper.GetList(35, 1, code, "third[2][100]", null); Assert.AreNotEqual(null, completionList); Assert.AreEqual(1, completionList.Count); // Nested out-of-bound defaulted to "ClassOne" type. Assert.AreEqual("DoubleTheValue", completionList[0].Value); }