Exemplo n.º 1
0
        public void SignatureHelpStarArgs()
        {
            SignatureAnalysis sigResult = null;

            using (var view = new PythonEditor(@"def f(a, *b, c=None): pass
f(1, 2, 3, 4,")) {
                for (int retries = 3; retries >= 0; --retries)
                {
                    TestSignature(view, -1, "f", 4, out sigResult);
                    if (retries == 0)
                    {
                        Assert.IsTrue(sigResult.Signatures.Count >= 1, "No signature analysis results");
                    }
                    else if (sigResult.Signatures.Count >= 1)
                    {
                        break;
                    }
                    Console.WriteLine("Retry {0}", retries);
                    view.Text = view.Text;
                }
                Assert.AreEqual("*b", sigResult.Signatures[0].CurrentParameter.Name);
            }
        }
Exemplo n.º 2
0
        public void SignatureHelp()
        {
            var prefixes = new[] { "", "(", "a = ", "f(", "l[", "{", "if " };
            var sigs     = new[] {
                new { Expr = "f(", Param = 0, Function = "f" },
                new { Expr = "f(1,", Param = 1, Function = "f" },
                new { Expr = "f(1, 2,", Param = 2, Function = "f" },
                new { Expr = "f(1, (1, 2),", Param = 2, Function = "f" },
                new { Expr = "f(1, a + b,", Param = 2, Function = "f" },
                new { Expr = "f(1, a or b,", Param = 2, Function = "f" },
                new { Expr = "f(1, a if True else b,", Param = 2, Function = "f" },
                new { Expr = "a.f(1, a if True else b,", Param = 2, Function = "a.f" },
                new { Expr = "a().f(1, a if True else b,", Param = 2, Function = "a().f" },
                new { Expr = "a(2, 3, 4).f(1, a if True else b,", Param = 2, Function = "a(2, 3, 4).f" },
                new { Expr = "a(2, (3, 4), 4).f(1, a if True else b,", Param = 2, Function = "a(2, (3, 4), 4).f" },
                new { Expr = "f(lambda a, b, c: 42", Param = 0, Function = "f" },
                new { Expr = "f(lambda a, b, c", Param = 0, Function = "f" },
                new { Expr = "f(lambda a: lambda b, c: 42", Param = 0, Function = "f" },
                new { Expr = "f(z, lambda a, b, c: 42", Param = 1, Function = "f" },
                new { Expr = "f(z, lambda a, b, c", Param = 1, Function = "f" },
                new { Expr = "f(z, lambda a: lambda b, c: 42", Param = 1, Function = "f" },
                new { Expr = "f([a for b in c", Param = 0, Function = "f" },
                // No function for f(( because ReverseExpressionParser will stop at the unmatched (
                new { Expr = "f((a for b in c", Param = 0, Function = "" },
                new { Expr = "f({a for b in c", Param = 0, Function = "f" },
                new { Expr = "f([a for b in c],", Param = 1, Function = "f" },
                new { Expr = "f((a for b in c),", Param = 1, Function = "f" },
                new { Expr = "f({a for b in c},", Param = 1, Function = "f" },
                new { Expr = "f(0, [a for b in c],", Param = 2, Function = "f" },
                new { Expr = "f(0, (a for b in c),", Param = 2, Function = "f" },
                new { Expr = "f(0, {a for b in c},", Param = 2, Function = "f" },
                new { Expr = "f([1,2", Param = 0, Function = "f" },
                new { Expr = "f([1,2,", Param = 0, Function = "f" },
                new { Expr = "f({1:2,", Param = 0, Function = "f" },
                new { Expr = "f({1,", Param = 0, Function = "f" },
                new { Expr = "f({1:2", Param = 0, Function = "f" },
            };

            using (var view = new PythonEditor()) {
                foreach (var prefix in prefixes)
                {
                    foreach (var sig in sigs)
                    {
                        var test = prefix + sig.Expr;
                        Console.WriteLine("   -- {0}", test);
                        view.Text = test;
                        var snapshot = view.CurrentSnapshot;

                        SignatureAnalysis res = null;
                        view.VS.InvokeSync(() => {
                            res = view.VS.GetPyService().GetSignatures(
                                view.View.TextView,
                                snapshot,
                                snapshot.CreateTrackingSpan(snapshot.Length, 0, SpanTrackingMode.EdgeInclusive)
                                );
                        });

                        Assert.IsNotNull(res);
                        Assert.AreEqual(sig.Function, res.Text, test);
                        Assert.AreEqual(sig.Param, res.ParameterIndex, test);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private static void TestSignature(PythonEditor view, int location, string expectedExpression, int paramIndex, out SignatureAnalysis sigs)
        {
            if (location < 0)
            {
                location = view.CurrentSnapshot.Length + location;
            }

            sigs = GetSignatureAnalysis(view, location);
            Assert.AreEqual(expectedExpression, sigs.Text, view.Text);
            Assert.AreEqual(paramIndex, sigs.ParameterIndex, view.Text);
        }
Exemplo n.º 4
0
        private static void TestSignature(MockVs vs, int location, string sourceCode, string expectedExpression, int paramIndex, PythonLanguageVersion version, bool analyze, out SignatureAnalysis sigs)
        {
            if (location < 0)
            {
                location = sourceCode.Length + location;
            }

            sigs = GetSignatureAnalysis(vs, location, sourceCode, version);
            Assert.AreEqual(expectedExpression, sigs.Text, sourceCode);
            Assert.AreEqual(paramIndex, sigs.ParameterIndex, sourceCode);
        }