oleg-shilo / cs-script.npp

CS-Script (C# Intellisense) plugin for Notepad++ (x86/x64)
MIT License
246 stars 52 forks source link

Support for debugging lambda expressions #26

Closed androidsystest001 closed 7 months ago

androidsystest001 commented 6 years ago

Please support for debugging lambda expressions, eg:

            List<entity> lst = new List<entity>();

            for (int i = 0; i < 10; i++)
            {
                lst.Add(new entity
                {
                    a = i,
                    b = i*10,
                    c = i*100,
                });      
            }
            IEnumerable<entity> a = lst.Where(x => x.a > 5);

Current result for value of "a" is : " System.Linq.Enumerable+WhereListIterator`1[ConsoleApplication1.entity]} "

oleg-shilo commented 6 years ago

The problem is in the fact that you are trying to get the value of the expression before it has been evaluated. You need to trigger the evaluation and the easiest way to do that is just to call ToArray:

IEnumerable<entity> a = lst.Where(x => x.a > 5).ToArray();

It will work: image

However there is a problem with the current implementation as the subitems in the watch view are no reevaluated on the debug step. Thus you will need to delete and reinsert the expression (e.g. 'a') you want to reevaluate.

That's why I marked it as a defect and started working on it.

androidsystest001 commented 6 years ago

The problem is in the fact that you are trying to get the value of the expression before it has been evaluated. You need to trigger the evaluation and the easiest way to do that is just to call ToArray

Thanks for reply. I understand about "ToArray" But i have another question, if you head about it, please write a something... "How evaluated the lambda expressions in this case without change source code? - like debugger of Visual Studio" (Using mdbg_v4...)

Thanks for support...

oleg-shilo commented 6 years ago

Evaluating lambda at runtime is possible even though not trivial. A descent CLR debugger allows you to do that (e.g. VS). However, with this pp plugin I had to integrate a long abandoned MS debugger mdbg, which is incomplete and was a nightmare to integrate. It just does not expose this functionality at all. It's even worse than that. It's interface had no functionality for evaluating any anything except the fields. I am not kidding, it does not support evaluating object properties. I had to reverse engineer it and implement properties support but to do anything trickier (like lambdas) in the product that is abandoned by the vendor and has no grip with the open source community... I don't think it is feasible.

That's why I have also ported this plugin to VSCode that has a descent debugger for free. And that debugger can only improve with time.

in addition to that I have placed the "Open in Visual Studio" button in the plugin window toolbar so one can open the script in the VS and use its debugger when the built-in debugger is insufficient.