theHamsta / nvim-dap-virtual-text

GNU General Public License v3.0
869 stars 25 forks source link

Does not show the correct current value #36

Closed balazser closed 2 years ago

balazser commented 2 years ago

Actual Shows a wrong value for the arr: list[tuple[int,int]] variable. Expected Show the right value [(1, 2), (0, 3), (2, 4)]

You can see on the attached screenshot [nvim-dap-virtual-text](https://github.com/theHamsta/nvim-dap-virtual-text) shows [3, 2, 4] while at the bottom dap repr shows [(1, 2), (0, 3), (2, 4)] image

Code that I used.

from operator import itemgetter

class Solution:
    def twoSum(self, nums: list[int], target: int) -> list[int]:
        if len(nums) < 2:
            return nums

        arr = list(sorted(enumerate(nums), key=itemgetter(1)))
        i = 0
        j = len(nums) - 1

        while i < j:
            arri = arr[i]
            arrj = arr[j]
            sum_ = arri[1] + arrj[1]
            if sum_ == target:
                return [arri[0], arrj[0]]
            elif sum_ > target:
                j -= 1
            else:
                i += 1
        return []

arr = [2, 7, 11, 15]
target = 9

Solution().twoSum(arr, target) == [0, 1]
theHamsta commented 2 years ago

There is a difference on how the value is determined between the virtual text and the evaluation in the REPL. The REPL does an "eval" request of an arbitrary expressions while this plugin just uses the value of the variable environment (with preference for locals, it's a list of key/value pairs provided by the debug adapter) provided by the debug adapter. I'll check whether VSCode or the dap-ui plugin behave differently. Most likely a value that doesn't get updated is due to the debug adapter. But maybe there is also a bug in this plugin. Will check later.

theHamsta commented 2 years ago

I found the issue

grafik

It seems that python-debug-adapter does set the "local" attribute to the local scope and then my plugin just uses any of the scopes (globals in this example). I can re-add the heuristic that we had here earlier that would match the string value "locals" as preferred scope.