Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
completion.py88 linesDownload Raw Back to sqlautocomplete
1"""2Using Completion class from3    https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/src/prompt_toolkit/completion/base.py4"""5 6__all__ = (7    'Completion'8)9 10 11class Completion:12    """13    :param text: The new string that will be inserted into the document.14    :param start_position: Position relative to the cursor_position where the15        new text will start. The text will be inserted between the16        start_position and the original cursor position.17    :param display: (optional string) If the completion has to be displayed18        differently in the completion menu.19    :param display_meta: (Optional string) Meta information about the20        completion, e.g. the path or source where it's coming from.21    :param get_display_meta: Lazy `display_meta`. Retrieve meta information22        only when meta is displayed.23    """24 25    def __init__(self, text, start_position=0, display=None, display_meta=None,26                 get_display_meta=None):27        self.text = text28        self.start_position = start_position29        self._display_meta = display_meta30        self._get_display_meta = get_display_meta31 32        if display is None:33            self.display = text34        else:35            self.display = display36 37        assert self.start_position <= 038 39    def __repr__(self) -> str:40        if isinstance(self.display, str) and self.display == self.text:41            return "{}(text={!r}, start_position={!r})".format(42                self.__class__.__name__,43                self.text,44                self.start_position,45            )46        else:47            return "{}(text={!r}, start_position={!r}, display={!r})".format(48                self.__class__.__name__,49                self.text,50                self.start_position,51                self.display,52            )53 54    def __eq__(self, other: object) -> bool:55        if not isinstance(other, Completion):56            return False57        return (58            self.text == other.text and59            self.start_position == other.start_position and60            self.display == other.display and61            self._display_meta == other._display_meta62        )63 64    def __hash__(self) -> int:65        return hash((self.text, self.start_position, self.display,66                     self._display_meta))67 68    @property69    def display_meta(self):70        # Return meta-text. (This is lazy when using "get_display_meta".)71        if self._display_meta is not None:72            return self._display_meta73 74    def new_completion_from_position(self, position: int) -> "Completion":75        """76        (Only for internal use!)77        Get a new completion by splitting this one. Used by `Application` when78        it needs to have a list of new completions after inserting the common79        prefix.80        """81        assert position - self.start_position >= 082 83        return Completion(84            text=self.text[position - self.start_position:],85            display=self.display,86            display_meta=self._display_meta,87        )88 
codekingpro/portable-devtools · Team Ai