Commit graph

210 commits

Author SHA1 Message Date
Paul Gauthier
dea93bbfd9 mentioned_idents 2024-05-14 12:18:48 -07:00
Paul Gauthier
e5616c0247 mentioned_fnames 2024-05-14 11:52:32 -07:00
Paul Gauthier
73e6949287 refac 2024-05-14 11:12:36 -07:00
Paul Gauthier
851e98a398 added tree cache 2024-05-14 10:32:16 -07:00
Paul Gauthier
3251380364 refac 2024-05-14 10:23:53 -07:00
Paul Gauthier
370f668955 remove useless noqa 2024-05-14 06:02:40 -07:00
Paul Gauthier
e96420f999 fix to ignore long (!) lines in repomap 2024-05-14 06:01:24 -07:00
Paul Gauthier
292250db4f prompt and token adjustments when no files in chat with repo 2024-05-13 12:30:42 -07:00
Paul Gauthier
1d55f749fb cleanup 2024-05-08 13:56:40 -07:00
Paul Gauthier
9e7f2ec790 cleanup 2024-05-08 13:41:24 -07:00
Paul Gauthier
f256b43043 wip 2024-05-08 13:35:34 -07:00
Paul Gauthier
f0f0c330d7 cleanup 2024-04-19 12:14:58 -07:00
Paul Gauthier
547ae142ba refactor tokenizer 2024-04-19 12:08:35 -07:00
Paul Gauthier
3449f7da42 quiet tree-sitter warnings 2024-04-18 16:36:56 -07:00
Paul Gauthier
65400981c5 aider: Replace deprecated pkg_resources.resource_filename with importlib.resources.files for accessing package resources in Python 3.9+.
# Aider chat conversation:

USER: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html

ASSISTANT: To address the `DeprecationWarning` regarding `pkg_resources`, we will replace its usage with the recommended `importlib.resources` or `importlib.metadata` from the Python standard library. The specific replacement depends on the original use case of `pkg_resources`. In the provided code, `pkg_resources` is used to access package data, so we will use `importlib.resources`.

Here are the diffs for the necessary changes:

```diff
--- aider/repomap.py
+++ aider/repomap.py
@@ ... @@
 import networkx as nx
-import pkg_resources
+import importlib.resources as pkg_resources
 from diskcache import Cache
 from grep_ast import TreeContext, filename_to_lang
 from pygments.lexers import guess_lexer_for_filename
 from pygments.token import Token
 from pygments.util import ClassNotFound
@@ ... @@
         # Load the tags queries
         try:
-            scm_fname = pkg_resources.resource_filename(
-                __name__, os.path.join("queries", f"tree-sitter-{lang}-tags.scm")
-            )
+            scm_fname = pkg_resources.files(__package__).joinpath(
+                "queries", f"tree-sitter-{lang}-tags.scm"
+            )
         except KeyError:
             return
-        query_scm = Path(scm_fname)
+        query_scm = scm_fname
         if not query_scm.exists():
             return
         query_scm = query_scm.read_text()
```

These changes replace the deprecated `pkg_resources.resource_filename` with `importlib.resources.files`, which is the recommended way to access package resources in Python 3.9 and later. The `files()` function returns a `Path`-like object that can be used to read the contents of the resource.
2024-04-18 16:30:10 -07:00
Paul Gauthier
c9bb22d6d5 roughed in tokenizer, dropped openai, openrouter 2024-04-17 15:22:35 -07:00
Paul Gauthier
8f98f3b430 Handle languages without tags.scm files #514 2024-03-22 10:14:22 -07:00
Paul Gauthier
f37488447f handle RecursionError 2024-01-02 10:12:44 -08:00
Paul Gauthier
d54f883698 do not include added files in the repo map #315 2023-11-15 13:06:22 -08:00
Paul Gauthier
f0c575e413 use io.read_text to avoid unicode errors in repomap #305 2023-11-02 09:30:59 -07:00
Paul Gauthier
5edf20915f updated sample map 2023-10-22 15:06:35 -07:00
Paul Gauthier
93fd53263e handle encoding 2023-10-19 13:16:53 -07:00
Paul Gauthier
a941c5cb82 cache tags 2023-10-19 13:13:48 -07:00
Paul Gauthier
5b99281d86 refac 2023-10-19 13:10:29 -07:00
Paul Gauthier
ce3099fa8b Fall back to the pygments lexer for refs if tree-sitter only provides defs 2023-10-19 12:54:27 -07:00
Paul Gauthier
551dddd746 handle languages where tree-sitter only has definition tags 2023-10-19 12:25:01 -07:00
Paul Gauthier
cb8d9d6a64 Merge branch 'main' into sitter-map 2023-10-19 10:09:22 -07:00
Paul Gauthier
cd30e531be better warnings on files that are missing or not normal 2023-10-19 10:09:16 -07:00
Paul Gauthier
cba883d4cd fix sorting and whitespace in map 2023-10-19 08:15:28 -07:00
Paul Gauthier
0291a99257 use rel_fname 2023-10-19 08:10:45 -07:00
Paul Gauthier
cff5534fab show_top_of_file_parent_scope 2023-10-19 08:07:59 -07:00
Paul Gauthier
9750fcd04a copy 2023-10-18 16:28:20 -07:00
Paul Gauthier
4c2125d289 cleanup 2023-10-18 16:18:59 -07:00
Paul Gauthier
2a1255ed07 cleanup 2023-10-18 16:12:07 -07:00
Paul Gauthier
40d702abd1 cleanup 2023-10-18 16:06:12 -07:00
Paul Gauthier
c0375d3328 fix tests; fix off-by-one bug in output of repomap 2023-10-18 15:42:38 -07:00
Paul Gauthier
10b856e0af cleanup 2023-10-18 15:18:12 -07:00
Paul Gauthier
2c98ea4448 Merge branch 'main' into sitter-map 2023-10-18 15:04:55 -07:00
Paul Gauthier
bf154b548e Only warn once about non-files being excluded from the repo map #281 2023-10-18 10:15:07 -07:00
Paul Gauthier
4347823c36 improved debug main() func 2023-09-08 08:26:06 -07:00
Paul Gauthier
427c9129a4 ssh 2023-09-01 15:52:27 -07:00
Paul Gauthier
6c5208246c aider: Fixed the queries directory not being included in the package by moving it inside the aider package and adjusting the package_data argument in the setup.py file.
# Aider chat conversation:

ASSISTANT: The `queries` directory might not be included in the package because it's not specified correctly in the `setup.py` file.

In the `setup.py` file, you have specified `package_data={'': ['queries/*']}`. This means that setuptools will include all files in the `queries` directory that are inside any package. However, if the `queries` directory is not inside a Python package (i.e., a directory containing an `__init__.py` file), it will not be included.

To fix this, you need to move the `queries` directory inside the `aider` package and adjust the `package_data` argument in the `setup.py` file. Here's how you can do it:

```python
setup.py
<<<<<<< HEAD
    package_data={
        '': ['queries/*'],
    },
=======
    package_data={
        'aider': ['queries/*'],
    },
>>>>>>> updated
```

This code changes the `package_data` argument to include all files in the `queries` directory that is inside the `aider` package.

After making this change, you need to move the `queries` directory inside the `aider` package. If the `queries` directory is currently in the same directory as the `setup.py` file, you can do this by running `mv queries aider/` in the terminal.

Finally, you need to adjust the `scm_fname` assignment in the `repomap.py` file to reflect the new location of the `queries` directory:

```python
aider/repomap.py
<<<<<<< HEAD
        scm_fname = pkg_resources.resource_filename(
            __name__, os.path.join("..", "queries", f"tree-sitter-{lang}-tags.scm")
        )
=======
        scm_fname = pkg_resources.resource_filename(
            __name__, os.path.join("queries", f"tree-sitter-{lang}-tags.scm")
        )
>>>>>>> updated
```

This code changes the path in the `resource_filename` call to look for the `queries` directory inside the `aider` package.
2023-09-01 14:14:05 -07:00
Paul Gauthier
7b95aef9d6 Add a debug statement to dump the scm filename. 2023-09-01 14:14:03 -07:00
Paul Gauthier
72d6afc470 aider: Imported pkg_resources module in repomap.py.
# Aider chat conversation:

USER:   File "/Users/gauthier/tmp/queries/.venv/lib/python3.11/site-packages/aider/repomap.py", line 180, in get_tags
    scm_fname = pkg_resources.resource_filename(
                ^^^^^^^^^^^^^
NameError: name 'pkg_resources' is not defined

ASSISTANT: The error message indicates that the `pkg_resources` module is not imported in the `repomap.py` file. This module is part of setuptools and is used to access files included in the package.

To fix this, you need to import the `pkg_resources` module at the beginning of the `repomap.py` file. Here's how you can do it:

```python
aider/repomap.py
<<<<<<< HEAD
import colorsys
import os
import random
import sys
from collections import Counter, defaultdict, namedtuple
from pathlib import Path
=======
import colorsys
import os
import pkg_resources
import random
import sys
from collections import Counter, defaultdict, namedtuple
from pathlib import Path
>>>>>>> updated
```

This code adds the `import pkg_resources` line right after the `import os` line.
2023-09-01 14:11:19 -07:00
Paul Gauthier
9d9ea5c4a8 aider: Refactor the scm_fname assignment in repomap.py to use os.path.join for Windows safety.
# Aider chat conversation:

USER: that's not windows safe is it?

ASSISTANT: You're correct. The use of `..` to refer to the parent directory is not Windows safe. On Windows, the path separator is `\` instead of `/`. However, Python's `os` and `os.path` modules provide functions that handle paths in a way that is safe for both Unix and Windows.

You can use `os.path.join` to construct the path to the scm file. This function takes care of using the correct path separator for the current operating system.

Here's how you can modify the `scm_fname` assignment in `repomap.py`:

```python
aider/repomap.py
<<<<<<< HEAD
        scm_fname = pkg_resources.resource_filename(
            __name__, f"../queries/tree-sitter-{lang}-tags.scm"
        )
=======
        scm_fname = pkg_resources.resource_filename(
            __name__, os.path.join("..", "queries", f"tree-sitter-{lang}-tags.scm")
        )
>>>>>>> updated
```

This code will work correctly on both Unix and Windows.
2023-09-01 14:08:59 -07:00
Paul Gauthier
b587685dc6 aider: Adjusted path in repomap.py to correctly locate the queries directory in the parent directory.
# Aider chat conversation:

USER: the queries directory is currently in the parent dir of repomap.py. what should i do?

ASSISTANT: If the `queries` directory is in the parent directory of `repomap.py`, you need to adjust the path in the `resource_filename` call accordingly.

You can use `..` to refer to the parent directory. Here's how you can modify the `scm_fname` assignment in `repomap.py`:

```python
aider/repomap.py
<<<<<<< HEAD
        scm_fname = pkg_resources.resource_filename(
            __name__, f"queries/tree-sitter-{lang}-tags.scm"
        )
=======
        scm_fname = pkg_resources.resource_filename(
            __name__, f"../queries/tree-sitter-{lang}-tags.scm"
        )
>>>>>>> updated
```

Please note that this assumes that the `queries` directory is directly in the parent directory of `repomap.py`. If it's in a different location, you'll need to adjust the path accordingly.
2023-09-01 14:08:35 -07:00
Paul Gauthier
7b77dbb88d aider: Updated package data to include the queries directory and modified repomap.py to use pkg_resources to access the scm files at runtime.
# Aider chat conversation:

USER: the `scm_fname` is using a path in my local filesystem. how do i package up the queries directory for pip install in a way that the script can find those scm files at runtime

ASSISTANT: To package the queries directory for pip install, you need to include it in your package data in the `setup.py` file. This will ensure that the directory is included when your package is installed.

Then, you can use the `pkg_resources` module to access the files at runtime. This module is part of `setuptools`, so it's already installed if you're using pip.

Here are the steps:

1. Modify `setup.py` to include the queries directory in the package data.

```python
setup.py
<<<<<<< HEAD
    packages=find_packages(),
    include_package_data=True,
=======
    packages=find_packages(),
    include_package_data=True,
    package_data={
        '': ['queries/*'],
    },
>>>>>>> updated
```

2. Modify `aider/repomap.py` to use `pkg_resources` to access the scm files at runtime.

```python
aider/repomap.py
<<<<<<< HEAD
        scm_fname = (
            f"/Users/gauthier/tmp/py-tree-sitter-languages/queries/tree-sitter-{lang}-tags.scm"
        )
=======
        scm_fname = pkg_resources.resource_filename(
            __name__, f"queries/tree-sitter-{lang}-tags.scm"
        )
>>>>>>> updated
```

Please note that the `queries` directory should be in the same directory as the `repomap.py` file for this to work. If it's in a different location, you'll need to adjust the path in the `resource_filename` call accordingly.
2023-09-01 14:06:51 -07:00
Paul Gauthier
fa6ae80653 Merge branch 'main' into sitter-map 2023-09-01 12:00:48 -07:00
Joshua Vial
abbc93678b finishing openrouter integration 2023-08-23 21:26:27 +12:00
JV
041f3a4a38 initial code for working with openrouter 2023-08-23 14:39:12 +12:00