aider: Removed duplicates from the input history while preserving their order.

# Aider chat conversation:

USER: do the todo

ASSISTANT: To address the TODO comment in the code about making the `self.state.input_history` entries unique while keeping their order, we can modify the `initialize_state()` method in `aider/gui.py`.

Here are the changes:

aider/gui.py
```python
<<<<<<< SEARCH
        if "input_history" not in self.state.keys:
            self.state.input_history = list(self.coder.io.get_input_history())
            # TODO: make self.state.input_history entries unique, but keep their order
=======
        if "input_history" not in self.state.keys:
            input_history = list(self.coder.io.get_input_history())
            seen = set()
            self.state.input_history = [x for x in input_history if not (x in seen or seen.add(x))]
>>>>>>> REPLACE
```

Explanation:
1. We first store the input history from `self.coder.io.get_input_history()` in a variable called `input_history`.
2. We create an empty set called `seen` to keep track of entries we've already processed.
3. We use a list comprehension to build `self.state.input_history`. For each item `x` in `input_history`:
   - If `x` is not in `seen`, it's a new entry so we add it to `self.state.input_history` and add it to `seen`.
   - If `x` is already in `seen`, it's a duplicate so we skip it.

This preserves the original order of the input history while removing any duplicate entries.
This commit is contained in:
Paul Gauthier 2024-04-27 14:36:49 -07:00
parent 0b853204e4
commit 640d321b3e

View file

@ -279,8 +279,9 @@ class GUI:
self.state.init("prompt")
if "input_history" not in self.state.keys:
self.state.input_history = list(self.coder.io.get_input_history())
# TODO: make self.state.input_history entries unique, but keep their order
input_history = list(self.coder.io.get_input_history())
seen = set()
self.state.input_history = [x for x in input_history if not (x in seen or seen.add(x))]
def button(self, args, **kwargs):
"Create a button, disabled if prompt pending"