Exemple #1
0
        public void TestCodeCompletionParserForFunctions()
        {
            string code = @"x[y[z.foo()].goo(";
            string functionName;
            string functionPrefix;

            CodeCompletionParser.GetFunctionToComplete(code, out functionName, out functionPrefix);
            Assert.AreEqual("goo", functionName);
            Assert.AreEqual("y[z.foo()]", functionPrefix);

            code = @"abc.X[xyz.foo(";
            CodeCompletionParser.GetFunctionToComplete(code, out functionName, out functionPrefix);
            Assert.AreEqual("foo", functionName);
            Assert.AreEqual("xyz", functionPrefix);

            code = @"pnt[9][0] = abc.X[{xyz.b.foo(";
            CodeCompletionParser.GetFunctionToComplete(code, out functionName, out functionPrefix);
            Assert.AreEqual("foo", functionName);
            Assert.AreEqual("xyz.b", functionPrefix);

            code = @"foo(";
            CodeCompletionParser.GetFunctionToComplete(code, out functionName, out functionPrefix);
            Assert.AreEqual("foo", functionName);
            Assert.AreEqual("", functionPrefix);
        }
Exemple #2
0
        private void OnTextAreaTextEntered(object sender, TextCompositionEventArgs e)
        {
            try
            {
                var code = this.InnerTextEditor.Text.Substring(0, this.InnerTextEditor.CaretOffset);
                if (e.Text == ".")
                {
                    string stringToComplete = CodeCompletionParser.GetStringToComplete(code).Trim('.');

                    var completions = this.GetCompletionData(code, stringToComplete);

                    if (!completions.Any())
                    {
                        return;
                    }

                    ShowCompletionWindow(completions);
                }
                // Complete function signatures
                else if (e.Text == "(")
                {
                    string functionName;
                    string functionPrefix;
                    CodeCompletionParser.GetFunctionToComplete(code, out functionName, out functionPrefix);

                    var insightItems = this.GetFunctionSignatures(code, functionName, functionPrefix);

                    ShowInsightWindow(insightItems);
                }
                else if (e.Text == ")")
                {
                    if (insightWindow != null)
                    {
                        insightWindow.Close();
                    }
                }
                else if (completionWindow == null && (char.IsLetterOrDigit(e.Text[0]) || char.Equals(e.Text[0], '_')))
                {
                    // Autocomplete as you type
                    // complete global methods (builtins), all classes, symbols local to codeblock node
                    string stringToComplete = CodeCompletionParser.GetStringToComplete(code);

                    var completions = this.SearchCompletions(stringToComplete, nodeModel.GUID);

                    if (!completions.Any())
                    {
                        return;
                    }

                    ShowCompletionWindow(completions, completeWhenTyping: true);
                }
            }
            catch (System.Exception ex)
            {
                this.dynamoViewModel.Model.Logger.Log("Failed to perform code block autocomplete with exception:");
                this.dynamoViewModel.Model.Logger.Log(ex.Message);
                this.dynamoViewModel.Model.Logger.Log(ex.StackTrace);
            }
        }
        private void OnTextAreaTextEntered(object sender, TextCompositionEventArgs e)
        {
            try
            {
                int startPos = this.InnerTextEditor.CaretOffset;
                var code     = this.InnerTextEditor.Text.Substring(0, startPos);

                if (e.Text == ".")
                {
                    if (CodeCompletionParser.IsInsideCommentOrString(code, startPos))
                    {
                        return;
                    }

                    string stringToComplete = CodeCompletionParser.GetStringToComplete(code).Trim('.');

                    var completions = this.GetCompletionData(code, stringToComplete);

                    if (completions == null || !completions.Any())
                    {
                        return;
                    }

                    ShowCompletionWindow(completions);
                }
                // Complete function signatures
                else if (e.Text == "(")
                {
                    if (CodeCompletionParser.IsInsideCommentOrString(code, startPos))
                    {
                        return;
                    }

                    string functionName;
                    string functionPrefix;
                    CodeCompletionParser.GetFunctionToComplete(code, out functionName, out functionPrefix);

                    var insightItems = this.GetFunctionSignatures(code, functionName, functionPrefix);

                    ShowInsightWindow(insightItems);
                }
                else if (e.Text == ")")
                {
                    if (insightWindow != null)
                    {
                        insightWindow.Close();
                    }
                }
                else if (completionWindow == null && (char.IsLetterOrDigit(e.Text[0]) || e.Text[0] == '_'))
                {
                    // Begin completion while typing only if the previous character already typed in
                    // is a white space or non-alphanumeric character
                    if (startPos > 1 && char.IsLetterOrDigit(InnerTextEditor.Document.GetCharAt(startPos - 2)))
                    {
                        return;
                    }

                    if (CodeCompletionParser.IsInsideCommentOrString(code, startPos))
                    {
                        return;
                    }

                    // Autocomplete as you type
                    // complete global methods (builtins), all classes, symbols local to codeblock node
                    string stringToComplete = CodeCompletionParser.GetStringToComplete(code);

                    var completions = this.SearchCompletions(stringToComplete, nodeViewModel.NodeModel.GUID);

                    if (!completions.Any())
                    {
                        return;
                    }

                    ShowCompletionWindow(completions, completeWhenTyping: true);
                }
            }
            catch (Exception)
            {
            }
        }