Beispiel #1
0
        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;
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        /// <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;
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);

        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        public void TestCompletionForPrimitiveTypes()
        {
            // Unit test for CodeCommpletionServices.SearchTypes() which should
            // include primitive types as well.
            var codeCompletionServices = new CodeCompletionServices(libraryServicesCore);

            string code = "boo";
            var completions = codeCompletionServices.SearchTypes(code);
            Assert.AreEqual(1, completions.Count());

            string[] expected = { "bool" };
            var actual = completions.Select(x => x.Text).OrderBy(x => x);
            Assert.AreEqual(expected, actual);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        public void TestHiddenConflictingClassCompletionWhenTyping()
        {
            var codeCompletionServices = new CodeCompletionServices(libraryServicesCore);

            // "SecondNamespace.AnotherClassWithNameConflict" is defined in FFITarget library with "IsVisibleInDynamoLibrary" 
            // attribute set to false. We verify that this class does not appear in code completion results
            // and that only "FirstNamespace.AnotherClassWithNameConflict" appears in code completion results with
            // fully qualified name so that it can be resolved against "SecondNamespace.AnotherClassWithNameConflict" 
            string code = "ano";
            var completions = codeCompletionServices.SearchCompletions(code, Guid.Empty);

            // Expected 1 completion items
            Assert.AreEqual(1, completions.Count());

            string[] expected = { "AnotherClassWithNameConflict" };
            var actual = completions.Select(x => x.Text).OrderBy(x => x);

            Assert.AreEqual(expected, actual);

            // Assert that the class name is indeed a class
            ClassMirror type = null;
            Assert.DoesNotThrow(() => type = new ClassMirror("FirstNamespace.AnotherClassWithNameConflict", libraryServicesCore));

            var members = type.GetMembers();

            expected = new[] { "AnotherClassWithNameConflict", "PropertyA", "PropertyB", "PropertyC" };
            AssertCompletions(members, expected);
        }
Beispiel #13
0
        public void TestHiddenClassCompletionWhenTyping()
        {
            var codeCompletionServices = new CodeCompletionServices(libraryServicesCore);

            // "SampleClassB" defined in FFITarget library with "IsVisibleInDynamoLibrary" attribute
            // is set to false. We verify that this class does not appear in code completion results
            string code = "sam";
            var completions = codeCompletionServices.SearchCompletions(code, Guid.Empty);

            // Expected 2 completion items
            Assert.AreEqual(2, completions.Count());

            string[] expected = { "SampleClassA", "SampleClassC" };
            var actual = completions.Select(x => x.Text).OrderBy(x => x);

            Assert.AreEqual(expected, actual);
        }
Beispiel #14
0
        public EngineController(LibraryServices libraryServices, string geometryFactoryFileName, bool verboseLogging)
        {
            this.libraryServices = libraryServices;
            libraryServices.LibraryLoaded += LibraryLoaded;
            CompilationServices = new CompilationServices(libraryServices.LibraryManagementCore);

            liveRunnerServices = new LiveRunnerServices(this, geometryFactoryFileName);

            liveRunnerServices.ReloadAllLibraries(libraryServices.ImportedLibraries);
            libraryServices.SetLiveCore(LiveRunnerCore);

            codeCompletionServices = new CodeCompletionServices(LiveRunnerCore);

            astBuilder = new AstBuilder(this);
            syncDataManager = new SyncDataManager();

            VerboseLogging = verboseLogging;
        }
Beispiel #15
0
        /// <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);
            libraryServices.SetLiveCore(LiveRunnerCore);
        }
Beispiel #16
0
        public void Dispose()
        {
            // This flag must be set immediately
            IsDisposed = true;

            libraryServices.LibraryLoaded -= LibraryLoaded;

            liveRunnerServices.Dispose();
            codeCompletionServices = null;
        }