public EngineController(DynamoModel dynamoModel, string geometryFactoryFileName) { this.dynamoModel = dynamoModel; // Create a core which is used for parsing code and loading libraries libraryCore = new ProtoCore.Core(new Options() { RootCustomPropertyFilterPathName = string.Empty }); libraryCore.Executives.Add(Language.kAssociative, new ProtoAssociative.Executive(libraryCore)); libraryCore.Executives.Add(Language.kImperative, new ProtoImperative.Executive(libraryCore)); libraryCore.ParsingMode = ParseMode.AllowNonAssignment; libraryServices = new LibraryServices(libraryCore); libraryServices.LibraryLoading += this.LibraryLoading; libraryServices.LibraryLoadFailed += this.LibraryLoadFailed; libraryServices.LibraryLoaded += this.LibraryLoaded; liveRunnerServices = new LiveRunnerServices(dynamoModel, this, geometryFactoryFileName); liveRunnerServices.ReloadAllLibraries(libraryServices.ImportedLibraries); codeCompletionServices = new CodeCompletionServices(LiveRunnerCore); astBuilder = new AstBuilder(dynamoModel, this); syncDataManager = new SyncDataManager(); dynamoModel.NodeDeleted += NodeDeleted; }
public void Dispose() { libraryServices.LibraryLoaded -= LibraryLoaded; liveRunnerServices.Dispose(); codeCompletionServices = null; }
/// <summary> /// LibraryLoaded event handler. /// </summary> private void LibraryLoaded(object sender, LibraryServices.LibraryLoadedEventArgs e) { liveRunnerServices.ReloadAllLibraries(libraryServices.ImportedLibraries); // The LiveRunner core is newly instantiated whenever a new library is imported // due to which a new instance of CodeCompletionServices needs to be created with the new Core codeCompletionServices = new CodeCompletionServices(LiveRunnerCore); }
/// <summary> /// Disposes EngineController. /// </summary> public void Dispose() { // This flag must be set immediately IsDisposed = true; libraryServices.LibraryLoaded -= LibraryLoaded; liveRunnerServices.Dispose(); codeCompletionServices = null; }
private void OnLibraryLoaded() { liveRunnerServices.ReloadAllLibraries(libraryServices.ImportedLibraries); VMLibrariesReset?.Invoke(); // The LiveRunner core is newly instantiated whenever a new library is imported // due to which a new instance of CodeCompletionServices needs to be created with the new Core codeCompletionServices = new CodeCompletionServices(LiveRunnerCore); libraryServices.SetLiveCore(LiveRunnerCore); }
public void TestMethodKeywordCompletionWhenTyping() { var codeCompletionServices = new CodeCompletionServices(libraryServicesCore); string code = "im"; var completions = codeCompletionServices.SearchCompletions(code, System.Guid.Empty); // Expected 5 completion items Assert.AreEqual(5, completions.Count()); string[] expected = { "Decimal", "Imperative", "ImportFromCSV", "Minimal", "MinimalTracedClass" }; var actual = completions.Select(x => x.Text).OrderBy(x => x); Assert.AreEqual(expected, actual); }
public EngineController(LibraryServices libraryServices, string geometryFactoryFileName, bool verboseLogging) { this.libraryServices = libraryServices; libraryServices.LibraryLoaded += LibraryLoaded; liveRunnerServices = new LiveRunnerServices(this, geometryFactoryFileName); liveRunnerServices.ReloadAllLibraries(libraryServices.ImportedLibraries); codeCompletionServices = new CodeCompletionServices(LiveRunnerCore); astBuilder = new AstBuilder(this); syncDataManager = new SyncDataManager(); VerboseLogging = verboseLogging; }
public void TestCompletionWhenTyping() { var codeCompletionServices = new CodeCompletionServices(libraryServicesCore); string code = "Poi"; var completions = codeCompletionServices.SearchCompletions(code, System.Guid.Empty); // Expected 4 completion items Assert.AreEqual(4, completions.Count()); string[] expected = { "DummyPoint", "FFITarget.DesignScript.Point", "FFITarget.Dynamo.Point", "UnknownPoint" }; var actual = completions.Select(x => x.Text).OrderBy(x => x); Assert.AreEqual(expected, actual); }
public void TestBuiltInMethodSignatureCompletion() { var codeCompletionServices = new CodeCompletionServices(libraryServicesCore); string functionPrefix = ""; string functionName = "Count"; string code = ""; var overloads = codeCompletionServices.GetFunctionSignatures(code, functionName, functionPrefix); // Expected 1 "AddWithValueContainer" method overloads Assert.AreEqual(1, overloads.Count()); foreach (var overload in overloads) { Assert.AreEqual(functionName, overload.Text); } Assert.AreEqual("Count : int (array : [])", overloads.ElementAt(0).Stub); }
public void TestStaticMethodSignatureCompletion() { var codeCompletionServices = new CodeCompletionServices(libraryServicesCore); string ffiTargetClass = "CodeCompletionClass"; string functionName = "StaticFunction"; string code = ""; var overloads = codeCompletionServices.GetFunctionSignatures(code, functionName, ffiTargetClass); // Expected 1 "StaticFunction" method overload Assert.AreEqual(1, overloads.Count()); foreach (var overload in overloads) { Assert.AreEqual(functionName, overload.Text); } Assert.AreEqual("StaticFunction : int ()", overloads.ElementAt(0).Stub); }
public void TestCtorSignatureCompletion() { string ffiTargetClass = "CodeCompletionClass"; string functionName = "CodeCompletionClass"; var codeCompletionServices = new CodeCompletionServices(libraryServicesCore); string code = ""; var overloads = codeCompletionServices.GetFunctionSignatures(code, functionName, ffiTargetClass); // Expected 3 "CodeCompletionClass" ctor overloads Assert.AreEqual(3, overloads.Count()); foreach (var overload in overloads) { Assert.AreEqual(functionName, overload.Text); } Assert.AreEqual("CodeCompletionClass (i1 : int, i2 : int, i3 : int)", overloads.ElementAt(2).Stub); }
public void TestMethodSignatureCompletion() { var codeCompletionServices = new CodeCompletionServices(libraryServicesCore); string functionPrefix = "a"; string ffiTargetClass = "CodeCompletionClass"; string functionName = "OverloadedAdd"; string code = string.Format("{0} : {1};", functionPrefix, ffiTargetClass); var overloads = codeCompletionServices.GetFunctionSignatures(code, functionName, functionPrefix); // Expected 2 "OverloadedAdd" method overloads Assert.AreEqual(2, overloads.Count()); foreach (var overload in overloads) { Assert.AreEqual(functionName, overload.Text); } Assert.AreEqual("OverloadedAdd : int (cf : ClassFunctionality)", overloads.ElementAt(0).Stub); }
/// <summary> /// LibraryLoaded event handler. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LibraryLoaded(object sender, LibraryServices.LibraryLoadedEventArgs e) { string newLibrary = e.LibraryPath; // Load all functions defined in that library. dynamoModel.SearchModel.Add(libraryServices.GetFunctionGroups(newLibrary)); // Reset the VM liveRunnerServices.ReloadAllLibraries(libraryServices.ImportedLibraries); // The LiveRunner core is newly instantiated whenever a new library is imported // due to which a new instance of CodeCompletionServices needs to be created with the new Core codeCompletionServices = new CodeCompletionServices(LiveRunnerCore); // Mark all nodes as dirty so that AST for the whole graph will be // regenerated. foreach (var node in dynamoModel.HomeSpace.Nodes) { node.RequiresRecalc = true; } }
public void CodeCompletionServicesGetCompletionsOnTypeTest() { //Arrange string ffiTargetClass = "CodeCompletionClass"; var codeCompletionServices = new CodeCompletionServices(libraryServicesCore); //We pass a ElementResolver parameter in the third parameter so will execute a specific section of the code var completions = codeCompletionServices.GetCompletionsOnType("", "CodeCompletionClass", new ElementResolver()); var completionData = completions.First(); completionData.Description = "Test"; //Assert //Due that we are passing null in the parameter mirror will raise a ArgumentException Assert.Throws <ArgumentException>(() => CompletionData.ConvertMirrorToCompletionData(null)); //Act CompletionData.ConvertMirrorToCompletionData(new ClassMirror(ffiTargetClass, libraryServicesCore), true, new ElementResolver()); //Assert Assert.AreEqual(8, completions.Count()); }
public void TestMethodSignatureReturnTypeCompletion() { var codeCompletionServices = new CodeCompletionServices(libraryServicesCore); string functionPrefix = "a"; string ffiTargetClass = "CodeCompletionClass"; string functionName = "AddWithValueContainer"; string code = string.Format("{0} : {1};", functionPrefix, ffiTargetClass); var overloads = codeCompletionServices.GetFunctionSignatures(code, functionName, functionPrefix); // Expected 1 "AddWithValueContainer" method overloads Assert.AreEqual(1, overloads.Count()); foreach (var overload in overloads) { Assert.AreEqual(functionName, overload.Text); } var expected = "AddWithValueContainer : ValueContainer[] (valueContainer : ValueContainer)"; Assert.AreEqual(expected, overloads.ElementAt(0).Stub); }
public void Dispose() { dynamoModel.NodeDeleted -= NodeDeleted; liveRunnerServices.Dispose(); libraryServices.LibraryLoading -= this.LibraryLoading; libraryServices.LibraryLoadFailed -= this.LibraryLoadFailed; libraryServices.LibraryLoaded -= this.LibraryLoaded; // TODO: Find a better way to save loaded libraries. if (!DynamoModel.IsTestMode) { foreach (var library in libraryServices.ImportedLibraries) { DynamoPathManager.Instance.AddPreloadLibrary(library); } } libraryServices.Dispose(); codeCompletionServices = null; libraryCore.Cleanup(); }
public void CodeCompletionServicesGetFunctionSignatures() { //Arrange string ffiTargetClass = "CodeCompletionClass"; string functionName = "foo"; string code = @"x[y[z.foo()].goo("; var codeCompletionServices = new CodeCompletionServices(libraryServicesCore); //Act //We pass an empty string in the third parameter (functionPrefix) so will execute a specific section of the code var overloads = codeCompletionServices.GetFunctionSignatures(code, functionName, ""); //Assert Assert.IsNotNull(overloads); //Act //We pass a ElementResolver parameter in the fourth parameter so will execute a specific section of the code overloads = codeCompletionServices.GetFunctionSignatures(code, functionName, ffiTargetClass, new ElementResolver()); //Assert Assert.IsNotNull(overloads); Assert.AreEqual(overloads.Count(), 0); }