Commit graph

1383 commits

Author SHA1 Message Date
Paul Gauthier
c46e8daa32 use networkx exclusively to maintain the graph structure 2023-05-31 16:53:42 -07:00
Paul Gauthier
b88dc7828c noop 2023-05-31 16:43:52 -07:00
Paul Gauthier
82f77615bc Merge branch 'main' into call-graph 2023-05-31 16:31:10 -07:00
Paul Gauthier
3b2c8c81ca copy 2023-05-31 16:29:53 -07:00
Paul Gauthier
3e384dd35b copy 2023-05-31 16:26:51 -07:00
Paul Gauthier
25ba428324 Merge branch 'main' into call-graph 2023-05-31 15:34:47 -07:00
Paul Gauthier
755cabe54f Merge remote-tracking branch 'origin/main' 2023-05-31 15:34:29 -07:00
Paul Gauthier
a553d71ca2 noop 2023-05-31 15:34:17 -07:00
paul-gauthier
d07d72c2d6
Update README.md 2023-05-31 09:33:59 -07:00
paul-gauthier
1031320836
Merge pull request #9 from jevon/patch-1
Update README.md
2023-05-31 08:25:21 -07:00
Jevon MacDonald
e1df502f34
Update README.md
Disambiguating the format to include OpenAI API token in ~/.aider.config.yml
2023-05-31 11:46:25 -03:00
Paul Gauthier
c635217d6a wip 2023-05-31 05:58:56 -07:00
Paul Gauthier
a216754c9f noqa 2023-05-30 17:07:12 -07:00
Paul Gauthier
4297e75b9b fixed up shelve 2023-05-30 17:06:02 -07:00
Paul Gauthier
a9b53569ac aider: Switched both caches to use shelve instead of json.
# Context:
USER: switch both caches to use shelve instead of json
ASSISTANT: To switch both caches to use `shelve` instead of `json`, we need to modify the `aider/repomap.py` file. We will update the `load_tags_cache`, `save_tags_cache`, `load_ident_cache`, and `save_ident_cache` methods.

Here are the changes:

```python
aider/repomap.py
<<<<<<< ORIGINAL
import json
=======
import shelve
>>>>>>> UPDATED
```

```python
aider/repomap.py
<<<<<<< ORIGINAL
    IDENT_CACHE_FILE = ".aider.ident.cache.json"
    TAGS_CACHE_FILE = ".aider.tags.cache.json"

    def load_tags_cache(self):
        if os.path.exists(self.TAGS_CACHE_FILE):
            with open(self.TAGS_CACHE_FILE, "r") as f:
                self.TAGS_CACHE = json.load(f)
        else:
            self.TAGS_CACHE = dict()

    def save_tags_cache(self):
        with open(self.TAGS_CACHE_FILE, "w") as f:
            json.dump(self.TAGS_CACHE, f)
=======
    IDENT_CACHE_FILE = ".aider.ident.cache"
    TAGS_CACHE_FILE = ".aider.tags.cache"

    def load_tags_cache(self):
        if os.path.exists(self.TAGS_CACHE_FILE):
            with shelve.open(self.TAGS_CACHE_FILE) as db:
                self.TAGS_CACHE = dict(db)
        else:
            self.TAGS_CACHE = dict()

    def save_tags_cache(self):
        with shelve.open(self.TAGS_CACHE_FILE) as db:
            db.update(self.TAGS_CACHE)
>>>>>>> UPDATED
```

```python
aider/repomap.py
<<<<<<< ORIGINAL
    def load_ident_cache(self):
        if os.path.exists(self.IDENT_CACHE_FILE):
            with open(self.IDENT_CACHE_FILE, "r") as f:
                self.IDENT_CACHE = json.load(f)
        else:
            self.IDENT_CACHE = dict()

    def save_ident_cache(self):
        with open(self.IDENT_CACHE_FILE, "w") as f:
            json.dump(self.IDENT_CACHE, f)
=======
    def load_ident_cache(self):
        if os.path.exists(self.IDENT_CACHE_FILE):
            with shelve.open(self.IDENT_CACHE_FILE) as db:
                self.IDENT_CACHE = dict(db)
        else:
            self.IDENT_CACHE = dict()

    def save_ident_cache(self):
        with shelve.open(self.IDENT_CACHE_FILE) as db:
            db.update(self.IDENT_CACHE)
>>>>>>> UPDATED
```

These changes will replace the usage of `json` with `shelve` for both caches.
2023-05-30 17:03:31 -07:00
Paul Gauthier
bd57c71898 fix up json cache 2023-05-30 17:01:30 -07:00
Paul Gauthier
d1bbb85437 aider: Added methods to load and save tags cache to .aider.tags.cache file.
# Context:
USER: persist the tags cache to .aider.tags.cache
ASSISTANT: To persist the tags cache to `.aider.tags.cache`, you need to modify the `aider/repomap.py` file. Add two new methods `load_tags_cache` and `save_tags_cache` to the `RepoMap` class, and call them in the `__init__` method and `run_ctags` method, respectively.

Here are the changes you need to make:

```python
aider/repomap.py
<<<<<<< ORIGINAL
    TAGS_CACHE_FILE = ".aider.tags.cache"
=======
    TAGS_CACHE_FILE = ".aider.tags.cache"

    def load_tags_cache(self):
        if os.path.exists(self.TAGS_CACHE_FILE):
            with open(self.TAGS_CACHE_FILE, "r") as f:
                self.TAGS_CACHE = json.load(f)
        else:
            self.TAGS_CACHE = dict()

    def save_tags_cache(self):
        with open(self.TAGS_CACHE_FILE, "w") as f:
            json.dump(self.TAGS_CACHE, f)
>>>>>>> UPDATED
```

```python
aider/repomap.py
<<<<<<< ORIGINAL
    def __init__(self, use_ctags=None, root=None, main_model="gpt-4"):
=======
    def __init__(self, use_ctags=None, root=None, main_model="gpt-4"):
        self.load_tags_cache()
>>>>>>> UPDATED
```

```python
aider/repomap.py
<<<<<<< ORIGINAL
    def run_ctags(self, filename):
        # Check if the file is in the cache and if the modification time has not changed
        file_mtime = os.path.getmtime(filename)
        cache_key = filename
        if cache_key in self.TAGS_CACHE and self.TAGS_CACHE[cache_key]["mtime"] == file_mtime:
            return self.TAGS_CACHE[cache_key]["data"]

        cmd = self.ctags_cmd + [filename]
        output = subprocess.check_output(cmd).decode("utf-8")
        output = output.splitlines()

        data = [json.loads(line) for line in output]

        # Update the cache
        self.TAGS_CACHE[cache_key] = {"mtime": file_mtime, "data": data}
=======
    def run_ctags(self, filename):
        # Check if the file is in the cache and if the modification time has not changed
        file_mtime = os.path.getmtime(filename)
        cache_key = filename
        if cache_key in self.TAGS_CACHE and self.TAGS_CACHE[cache_key]["mtime"] == file_mtime:
            return self.TAGS_CACHE[cache_key]["data"]

        cmd = self.ctags_cmd + [filename]
        output = subprocess.check_output(cmd).decode("utf-8")
        output = output.splitlines()

        data = [json.loads(line) for line in output]

        # Update the cache
        self.TAGS_CACHE[cache_key] = {"mtime": file_mtime, "data": data}
        self.save_tags_cache()
>>>>>>> UPDATED
```

These changes will load the tags cache from the `.aider.tags.cache` file when initializing the `RepoMap` class and save the updated cache to the file after running ctags.
2023-05-30 16:54:36 -07:00
Paul Gauthier
29ca124f5f Fixed persisting ident cache 2023-05-30 16:52:28 -07:00
Paul Gauthier
311fc1d6e1 aider: Persist the IDENT_CACHE to .aider.ident.cache whenever it is updated.
# Context:
USER: persist the `IDENT_CACHE` to .aider.ident.cache whenever it is updated
ASSISTANT: To persist the `IDENT_CACHE` to `.aider.ident.cache` whenever it is updated, we need to modify the `get_name_identifiers` method in the `RepoMap` class. Here are the changes:

```python
aider/repomap.py
<<<<<<< ORIGINAL
    def get_name_identifiers(self, fname, uniq=True):
        file_mtime = os.path.getmtime(fname)
        cache_key = fname
        if cache_key in self.IDENT_CACHE and self.IDENT_CACHE[cache_key]["mtime"] == file_mtime:
            idents = self.IDENT_CACHE[cache_key]["data"]
        else:
            idents = self.get_name_identifiers_uncached(fname)
            self.IDENT_CACHE[cache_key] = {"mtime": file_mtime, "data": idents}
=======
import json

class RepoMap:
    # ...
    IDENT_CACHE_FILE = ".aider.ident.cache"

    def __init__(self, use_ctags=None, root=None, main_model="gpt-4"):
        # ...
        self.load_ident_cache()

    def load_ident_cache(self):
        if os.path.exists(self.IDENT_CACHE_FILE):
            with open(self.IDENT_CACHE_FILE, "r") as f:
                self.IDENT_CACHE = json.load(f)
        else:
            self.IDENT_CACHE = dict()

    def save_ident_cache(self):
        with open(self.IDENT_CACHE_FILE, "w") as f:
            json.dump(self.IDENT_CACHE, f)

    def get_name_identifiers(self, fname, uniq=True):
        file_mtime = os.path.getmtime(fname)
        cache_key = fname
        if cache_key in self.IDENT_CACHE and self.IDENT_CACHE[cache_key]["mtime"] == file_mtime:
            idents = self.IDENT_CACHE[cache_key]["data"]
        else:
            idents = self.get_name_identifiers_uncached(fname)
            self.IDENT_CACHE[cache_key] = {"mtime": file_mtime, "data": idents}
            self.save_ident_cache()
>>>>>>> UPDATED
```

This will load the `IDENT_CACHE` from the `.aider.ident.cache` file when the `RepoMap` class is initialized and save the cache to the file whenever it is updated.
2023-05-30 16:50:56 -07:00
Paul Gauthier
49374d04b5 aider: Made IDENT_CACHE use mtime like TAGS_CACHE.
# Context:
USER: make `IDENT_CACHE` use mtime like `TAGS_CACHE`
ASSISTANT: To make `IDENT_CACHE` use mtime like `TAGS_CACHE`, we need to modify the `get_name_identifiers` and `get_name_identifiers_uncached` methods in the `RepoMap` class. Here are the changes:

```python
aider/repomap.py
<<<<<<< ORIGINAL
    def get_name_identifiers(self, fname, uniq=True):
        idents = self.IDENT_CACHE.get(fname)
        if idents is None:
            idents = self.get_name_identifiers_uncached(fname)
            self.IDENT_CACHE[fname] = idents
=======
    def get_name_identifiers(self, fname, uniq=True):
        file_mtime = os.path.getmtime(fname)
        cache_key = fname
        if cache_key in self.IDENT_CACHE and self.IDENT_CACHE[cache_key]["mtime"] == file_mtime:
            idents = self.IDENT_CACHE[cache_key]["data"]
        else:
            idents = self.get_name_identifiers_uncached(fname)
            self.IDENT_CACHE[cache_key] = {"mtime": file_mtime, "data": idents}
>>>>>>> UPDATED

```
2023-05-30 16:49:12 -07:00
Paul Gauthier
a7ca584859 refac 2023-05-30 16:47:50 -07:00
Paul Gauthier
4a1e252bfc noop 2023-05-30 14:25:55 -07:00
Paul Gauthier
313968415a wip 2023-05-30 14:15:29 -07:00
Paul Gauthier
2353e54628 moved get_name_identifiers 2023-05-30 14:07:05 -07:00
Paul Gauthier
497b04acd3 Merge branch 'main' into call-graph 2023-05-30 13:57:16 -07:00
Paul Gauthier
5d4fd15a21 do isort first 2023-05-30 13:55:28 -07:00
Paul Gauthier
77d20b6819 Fixed TAGS_CACHE 2023-05-30 13:54:56 -07:00
Paul Gauthier
5801bd9ca4 aider: Moved TAGS_CACHE into the RepoMap class.
# Context:
USER: move `TAGS_CACHE` into the class
ASSISTANT: To move the `TAGS_CACHE` into the `RepoMap` class, I will make the following changes:

```python
aider/repomap.py
<<<<<<< ORIGINAL
# Global cache for tags
TAGS_CACHE = {}
=======
>>>>>>> UPDATED
```

```python
aider/repomap.py
<<<<<<< ORIGINAL
class RepoMap:
    ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"]

    def __init__(self, use_ctags=None, root=None, main_model="gpt-4"):
=======
    class RepoMap:
        ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"]
        TAGS_CACHE = {}

        def __init__(self, use_ctags=None, root=None, main_model="gpt-4"):
>>>>>>> UPDATED
```

Now, the `TAGS_CACHE` is a class attribute of the `RepoMap` class.
2023-05-30 13:53:31 -07:00
Paul Gauthier
6b4c54d117 Merge branch 'main' into call-graph 2023-05-30 11:45:39 -07:00
Paul Gauthier
ca74eee2f9 Allow GPT to omit the filename from edit blocks, if an earlier block provided it 2023-05-30 11:45:21 -07:00
Paul Gauthier
ef22abd8be copy 2023-05-30 08:01:49 -07:00
Paul Gauthier
9cb793c82d reverted c9ebbdf0 2023-05-30 07:58:54 -07:00
Paul Gauthier
b359134f86 reverted a4e57e17b5 2023-05-30 07:58:31 -07:00
Paul Gauthier
0d568e2b59 screencast.svg 2023-05-30 06:42:05 -07:00
Paul Gauthier
6b4ce832b3 screencast.svg 2023-05-30 06:39:19 -07:00
Paul Gauthier
eb6aba8726 screencast.svg 2023-05-30 06:25:52 -07:00
Paul Gauthier
a4e57e17b5 aider: Added completions_height parameter to InputOutput class and passed it from aider/main.py.
# Context:
USER: pass it to `InputOutput` and store as a self. var
ASSISTANT: I will modify the `InputOutput` class in `aider/io.py` to accept the `completions_height` parameter and store it as an instance variable.

Here's the change to add the `completions_height` parameter to the `InputOutput` class:

```python
aider/io.py

^C KeyboardInterrupt
USER: `aider/io.py`
ASSISTANT: I will modify the `InputOutput` class in `aider/io.py` to accept the `completions_height` parameter and store it as an instance variable.

Here's the change to add the `completions_height` parameter to the `InputOutput` class:

```python
aider/io.py
<<<<<<< ORIGINAL
    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
    ):
=======
    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
        completions_height=10,
    ):
        self.completions_height = completions_height
>>>>>>> UPDATED
```

Now, you need to pass the `completions_height` value from `aider/main.py` to the `InputOutput` class when creating an instance:

```python
aider/main.py
<<<<<<< ORIGINAL
    io = InputOutput(
        args.pretty,
        args.yes,
        args.input_history_file,
        args.chat_history_file,
        input=input,
        output=output,
        user_input_color=args.user_input_color,
        tool_output_color=args.tool_output_color,
        tool_error_color=args.tool_error_color,
    )
=======
    io = InputOutput(
        args.pretty,
        args.yes,
        args.input_history_file,
        args.chat_history_file,
        input=input,
        output=output,
        user_input_color=args.user_input_color,
        tool_output_color=args.tool_output_color,
        tool_error_color=args.tool_error_color,
        completions_height=args.completions_height,
    )
>>>>>>> UPDATED
```

Now, the `completions_height` value is passed to the `InputOutput` class and stored as an instance variable.
2023-05-29 17:33:39 -07:00
Paul Gauthier
c9ebbdf0c0 aider: Added a --completions-height command line parameter to aider/main.py.
# Context:
USER: add a --completions-height cmd line param to `aider/main.py`
ASSISTANT: I will add a `--completions-height` command line parameter to `aider/main.py`. This parameter will allow users to set the height of the completions displayed in the terminal.

Here's the change to add the `--completions-height` parameter:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable dirty commit of changes",
    )
=======
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable dirty commit of changes",
    )
    parser.add_argument(
        "--completions-height",
        type=int,
        default=10,
        metavar="COMPLETIONS_HEIGHT",
        help="Set the height of the completions displayed in the terminal (default: 10)",
    )
>>>>>>> UPDATED
```

This will add a new command line argument `--completions-height` with a default value of 10. Users can now set the height of the completions displayed in the terminal by providing a value for this argument.
2023-05-29 17:32:02 -07:00
Paul Gauthier
a7ab3d5d78 screencast.svg 2023-05-29 17:08:06 -07:00
Paul Gauthier
e25cf11aff stronger prompt against editing r/o files 2023-05-29 15:02:51 -07:00
Paul Gauthier
728d3f76a8 new gif 2023-05-29 14:55:04 -07:00
Paul Gauthier
765e0886f9 new gif 2023-05-29 12:21:43 -07:00
Paul Gauthier
2ff24a51dd bold italic 2023-05-29 12:13:28 -07:00
Paul Gauthier
fbb14b2823 aider: Changed pygments.literal.string to appear in inverse colors.
# Context:
USER: no. let's make pygments.literal.string be in inverse colors
ASSISTANT: To make `pygments.literal.string` appear in inverse colors, we need to modify the `aider/io.py` file. Update the `style` dictionary in the `get_input` method:

```python
aider/io.py
<<<<<<< ORIGINAL
        if self.user_input_color:
            style = Style.from_dict({"": self.user_input_color, "pygments.literal.string": f"underline {self.user_input_color}"})
=======
        if self.user_input_color:
            style = Style.from_dict({"": self.user_input_color, "pygments.literal.string": f"reverse {self.user_input_color}"})
>>>>>>> UPDATED
```

This change will apply the inverse color style to ticked words in the `PromptSession`.
2023-05-29 11:49:50 -07:00
Paul Gauthier
8f40f08636 aider: Updated the style dictionary in get_input method to apply underline style and self.user_input_color to ticked words.
# Context:
USER: underlined and self.user_input_color
ASSISTANT: To underline ticked words and apply the `self.user_input_color`, we need to modify the `aider/io.py` file. Update the `style` dictionary in the `get_input` method:

```python
aider/io.py
<<<<<<< ORIGINAL
        if self.user_input_color:
            style = Style.from_dict({"": self.user_input_color, "pygments.literal.string": "underline"})
=======
        if self.user_input_color:
            style = Style.from_dict({"": self.user_input_color, "pygments.literal.string": f"underline {self.user_input_color}"})
>>>>>>> UPDATED
```

This change will apply the underline style and the `self.user_input_color` to ticked words in the `PromptSession`.
2023-05-29 11:48:22 -07:00
Paul Gauthier
507442da3f aider: Added underline style to ticked words in PromptSession.
# Context:
USER: can we override the style for `ticked` words to just underline them, not change the color?
ASSISTANT: Yes, we can override the style for ticked words to underline them without changing the color. We need to modify the `aider/io.py` file. Update the `style` dictionary in the `InputOutput` class's `__init__` method:

```python
aider/io.py
<<<<<<< ORIGINAL
        if self.user_input_color:
            style = Style.from_dict
^C KeyboardInterrupt
USER: no, just for the markdown highlighting in the `PromptSession`
ASSISTANT: I apologize for the misunderstanding. To override the style for ticked words in the `PromptSession`, we need to modify the `aider/io.py` file. Update the `style` dictionary in the `get_input` method:

```python
aider/io.py
<<<<<<< ORIGINAL
        if self.user_input_color:
            style = Style.from_dict({"": self.user_input_color})
=======
        if self.user_input_color:
            style = Style.from_dict({"": self.user_input_color, "pygments.literal.string": "underline"})
>>>>>>> UPDATED
```

This change will apply the underline style to ticked words in the `PromptSession` without changing their color.
2023-05-29 11:46:57 -07:00
Paul Gauthier
4a4d0efe89 aider: Replaced MarkdownLexer with PygmentsLexer to correctly highlight user input with markdown syntax.
# Context:
USER: AttributeError: 'MarkdownLexer' object has no attribute 'lex_document'
ASSISTANT: I apologize for the confusion. It seems I misunderstood the usage of `MarkdownLexer` with `prompt_toolkit`. Instead, we should use `PygmentsLexer` from `prompt_toolkit.lexers` to wrap the `MarkdownLexer`. Here's the updated change:

First, import `PygmentsLexer` from `prompt_toolkit.lexers`:

```python
aider/io.py
<<<<<<< ORIGINAL
from prompt_toolkit.completion import Completer, Completion
=======
from prompt_toolkit.completion import Completer, Completion
from prompt_toolkit.lexers import PygmentsLexer
>>>>>>> UPDATED
```

Then, update the `PromptSession` instantiation in the `get_input` method:

```python
aider/io.py
<<<<<<< ORIGINAL
            session_kwargs = {
                "message": show,
                "completer": completer_instance,
                "reserve_space_for_menu": 4,
                "complete_style": CompleteStyle.MULTI_COLUMN,
                "input": self.input,
                "output": self.output,
                "lexer": MarkdownLexer(),
            }
=======
            session_kwargs = {
                "message": show,
                "completer": completer_instance,
                "reserve_space_for_menu": 4,
                "complete_style": CompleteStyle.MULTI_COLUMN,
                "input": self.input,
                "output": self.output,
                "lexer": PygmentsLexer(MarkdownLexer),
            }
>>>>>>> UPDATED
```

These changes will correctly use the `MarkdownLexer` with `prompt_toolkit` to highlight the user input with markdown syntax.
2023-05-29 11:43:50 -07:00
Paul Gauthier
2a0761b0ce aider: Added MarkdownLexer to highlight user input with markdown syntax.
# Context:
USER: have `prompt_toolkit` highlight the user input with a markdown lexer
ASSISTANT: To highlight the user input with a markdown lexer, we need to modify the `aider/io.py` file. We will import the `MarkdownLexer` from `pygments.lexers.markup` and use it as the lexer for the `PromptSession`.

Here's the change you need to make:

```python
aider/io.py
<<<<<<< ORIGINAL
from pygments.lexers import guess_lexer_for_filename
=======
from pygments.lexers import guess_lexer_for_filename, MarkdownLexer
>>>>>>> UPDATED
```

And update the `PromptSession` instantiation in the `get_input` method:

```python
aider/io.py
<<<<<<< ORIGINAL
            session_kwargs = {
                "message": show,
                "completer": completer_instance,
                "reserve_space_for_menu": 4,
                "complete_style": CompleteStyle.MULTI_COLUMN,
                "input": self.input,
                "output": self.output,
            }
=======
            session_kwargs = {
                "message": show,
                "completer": completer_instance,
                "reserve_space_for_menu": 4,
                "complete_style": CompleteStyle.MULTI_COLUMN,
                "input": self.input,
                "output": self.output,
                "lexer": MarkdownLexer(),
            }
>>>>>>> UPDATED
```

These changes will import the `MarkdownLexer` and use it for the `PromptSession`, which will highlight the user input with markdown syntax.
2023-05-29 11:42:19 -07:00
Paul Gauthier
e4805490f5 quote autocompletions 2023-05-29 11:32:50 -07:00
Paul Gauthier
d28cb2beea noop 2023-05-29 11:27:19 -07:00