Giter Site home page Giter Site logo

Comments (3)

nakst avatar nakst commented on July 18, 2024

This is currently not possible to do; the watch window API needs to be expanded first. Do you have any suggestions on what it should look like?

from gf.

typon avatar typon commented on July 18, 2024

It took me a while to wrap my head around what the current API is attempting to do...my suggestion would be to make it a lot more explicit.

What about something like this:

from typing import Callable
from abc import ABC, abstractmethod

class WatchHook(ABC):
    @abstractmethod
    def get_short_name(self, expression_value: gdb.Value):
        raise NotImplementedError("must override!")

    @abstractmethod
    def get_row_names(self, expression_value: gdb.Value):
        raise NotImplementedError("must override!")

    @abstractmethod
    def get_row_values(self, expression_value: gdb.Value):
        raise NotImplementedError("must override!")

# Sample array hook
class ArrayHook(WatchHook):
    def get_short_name(self, array_value: gdb.Value):
        # TODO: Extract size of array here
        return f"Array of {array_size} items"

    def get_row_names(self, array_value: gdb.Value):
        """
        This method is called `get_row_names` and not `get_field_names` because
        the user can use these for any purpose, for example indices of an array
        """
        # TODO: Extract size of array here
        self.array_size = array_size
        return [str(index) for index in range(0, array_size)]

    def get_row_values(self, value_stringify_callback: Callable, array_value: gdb.Value):
        result = []
        for index in range(self.array_size):
            value: gdb.Value = array_value[index]
            # This callback will recursively call other registered hooks or the default hook
            # to get the string to be displayed
            # In the case where array items are structs or other nested objects,
            # the callback will insert the short_name here and mark this row as expandable
            value_str: str = value_stringify_callback(value)
            result.append(value_str)
        return result

I don't understand the rest of the gf code enough to actually implement this myself, unfortunately :( I am willing to help though.

from gf.

nakst avatar nakst commented on July 18, 2024

I've added this in 982176e and documented it in c3aa0fb.
However I have not had a chance to test it much yet, so I'll keep this issue open for now in case there are bugs.

from gf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.