paul-gauthier / aider

aider is AI pair programming in your terminal
https://aider.chat/
Apache License 2.0
14.53k stars 1.37k forks source link

getting invalid syntax at offset 275 #816

Closed nathanbraun closed 2 days ago

nathanbraun commented 2 weeks ago

Issue

Hi there, I just installed aider (in a virtual environment) version v0.43 (also tried with v0.43.1-dev) and am trying to run it. Whenever I do, the prompt loads correctly, but if I tell it to do something it throws this error:

❯ aider
Aider v0.43.1-dev
Models: gpt-4o with diff edit format, weak model gpt-3.5-turbo
Git repo: .git with 96 files
Repo-map: using 1024 tokens
Use /help <question> to ask for help, run with --help to see cmd line args
─────────────────────────────────────────────────────────────────────────────────────
> refactor index.ts

index.ts
Add these files to the chat? y
Traceback (most recent call last):
  File "/Users/nathanbraun/aider-python/venv/bin/aider", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/nathanbraun/aider-python/venv/lib/python3.12/site-packages/aider/main.py", line 573, in main
    coder.run()
  File "/Users/nathanbraun/aider-python/venv/lib/python3.12/site-packages/aider/coders/base_coder.py", line 631, in run
    list(self.send_new_user_message(new_user_message))
  File "/Users/nathanbraun/aider-python/venv/lib/python3.12/site-packages/aider/coders/base_coder.py", line 843, in send_new_user_message
    messages = self.format_messages()
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nathanbraun/aider-python/venv/lib/python3.12/site-packages/aider/coders/base_coder.py", line 799, in format_messages
    messages += self.get_files_messages()
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nathanbraun/aider-python/venv/lib/python3.12/site-packages/aider/coders/base_coder.py", line 551, in get_files_messages
    repo_content = self.get_repo_map()
                   ^^^^^^^^^^^^^^^^^^^
  File "/Users/nathanbraun/aider-python/venv/lib/python3.12/site-packages/aider/coders/base_coder.py", line 523, in get_repo_map
    repo_content = self.repo_map.get_repo_map(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nathanbraun/aider-python/venv/lib/python3.12/site-packages/aider/repomap.py", line 87, in get_repo_map
    files_listing = self.get_ranked_tags_map(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nathanbraun/aider-python/venv/lib/python3.12/site-packages/aider/repomap.py", line 393, in get_ranked_tags_map
    ranked_tags = self.get_ranked_tags(
                  ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nathanbraun/aider-python/venv/lib/python3.12/site-packages/aider/repomap.py", line 280, in get_ranked_tags
    tags = list(self.get_tags(fname, rel_fname))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nathanbraun/aider-python/venv/lib/python3.12/site-packages/aider/repomap.py", line 150, in get_tags
    data = list(self.get_tags_raw(fname, rel_fname))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nathanbraun/aider-python/venv/lib/python3.12/site-packages/aider/repomap.py", line 183, in get_tags_raw
    query = language.query(query_scm)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nathanbraun/aider-python/venv/lib/python3.12/site-packages/tree_sitter/__init__.py", line 222, in query
    return _language_query(self.language_id, source)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid syntax at offset 275

Version and model info

No response

nathanbraun commented 2 weeks ago

Update: I got it working on the repo I was using with the --no-git option. I'm really not sure what the deal is. I do have sub modules in this repo, but I tried installing this same submodule in a different test repository and it worked fine. I guess I'll use it with the --no-git option for now. Let me know if you want any more info to debug.

I did try running it on python versions 3.12, 3.11, and 3.10 and got the same behavior on all of them.

paul-gauthier commented 2 weeks ago

Thanks for trying aider and filing this issue.

How did you install aider? This looks like it might be a problem with your local python environment.

nathanbraun commented 2 weeks ago

I'm on a mac and made a new virtual environment for it, activated it, then ran:

$ pip install aider-chat

Then when I want to run it somewhere else, I have this environment activated, and run it in a different working directory. It works, but only with --no-git.

paul-gauthier commented 2 weeks ago

Does this happen for you with every .ts file? I am unable to reproduce this problem.

nathanbraun commented 2 weeks ago

It doesn't appear to be language specific. I just tried it same repo and it crashed with the same error when I ran:

/add package.json
paul-gauthier commented 4 days ago

This seems to be an issue with your local environment. Perhaps you should try uninstalling aider and re-installing it cleanly? Or try installing via pipx:

https://aider.chat/docs/install/pipx.html

I am unable to reproduce the problem. I've never received other user reports of similar issues. And nothing about this part of aider has changed for many months.

cjoach commented 4 days ago

Hi, I have the same problem. I installed using pip3 install --local aider-chat then pipx install aider-chat. I tried the --no-git option and it indeed works in this case.

$ aider ruff.toml
Aider v0.45.1
Models: gpt-4o with diff edit format, weak model gpt-4o-mini
Git repo: .git with 3,904 files
Warning: For large repos, consider using an .aiderignore file to ignore irrelevant files/dirs.
Repo-map: using 1024 tokens
Added ruff.toml to the chat.
Use /help <question> for help, run "aider --help" to see cmd line args
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
ruff.toml> refactor ruff.toml                                                                                                                

Traceback (most recent call last):
  File "/home/cjoach/.local/bin/aider", line 8, in <module>
    sys.exit(main())
  File "/home/cjoach/.local/share/pipx/venvs/aider-chat/lib/python3.10/site-packages/aider/main.py", line 586, in main
    coder.run()
  File "/home/cjoach/.local/share/pipx/venvs/aider-chat/lib/python3.10/site-packages/aider/coders/base_coder.py", line 631, in run
    list(self.send_new_user_message(new_user_message))
  File "/home/cjoach/.local/share/pipx/venvs/aider-chat/lib/python3.10/site-packages/aider/coders/base_coder.py", line 841, in send_new_user_message
    messages = self.format_messages()
  File "/home/cjoach/.local/share/pipx/venvs/aider-chat/lib/python3.10/site-packages/aider/coders/base_coder.py", line 797, in format_messages
    messages += self.get_files_messages()
  File "/home/cjoach/.local/share/pipx/venvs/aider-chat/lib/python3.10/site-packages/aider/coders/base_coder.py", line 551, in get_files_messages
    repo_content = self.get_repo_map()
  File "/home/cjoach/.local/share/pipx/venvs/aider-chat/lib/python3.10/site-packages/aider/coders/base_coder.py", line 523, in get_repo_map
    repo_content = self.repo_map.get_repo_map(
  File "/home/cjoach/.local/share/pipx/venvs/aider-chat/lib/python3.10/site-packages/aider/repomap.py", line 87, in get_repo_map
    files_listing = self.get_ranked_tags_map(
  File "/home/cjoach/.local/share/pipx/venvs/aider-chat/lib/python3.10/site-packages/aider/repomap.py", line 393, in get_ranked_tags_map
    ranked_tags = self.get_ranked_tags(
  File "/home/cjoach/.local/share/pipx/venvs/aider-chat/lib/python3.10/site-packages/aider/repomap.py", line 280, in get_ranked_tags
    tags = list(self.get_tags(fname, rel_fname))
  File "/home/cjoach/.local/share/pipx/venvs/aider-chat/lib/python3.10/site-packages/aider/repomap.py", line 150, in get_tags
    data = list(self.get_tags_raw(fname, rel_fname))
  File "/home/cjoach/.local/share/pipx/venvs/aider-chat/lib/python3.10/site-packages/aider/repomap.py", line 183, in get_tags_raw
    query = language.query(query_scm)
  File "/home/cjoach/.local/share/pipx/venvs/aider-chat/lib/python3.10/site-packages/tree_sitter/__init__.py", line 222, in query
    return _language_query(self.language_id, source)
SyntaxError: Invalid syntax at offset 275
cjoach commented 3 days ago

I was able to isolate my problem by creating a new repo with a single elm file then running the comment aider --show-repo-map. This seems to be related to the file tree-sitter-elm-tags.scm. I also tested the language.query(query_scm) for all scm files and the Ocaml one is the only other to fail but with the following error:

NameError: Invalid node type infix_operator
nathanbraun commented 3 days ago

Thanks for looking at this @cjoach -- my repo it's failing on indeed also does have Elm files in it.

paul-gauthier commented 2 days ago

@cjoach submitted a PR that should fix this. Thanks!

I had aider add test coverage for all supported languages as well. The tests failed on elm until the PR was merged, so this seems like it may be fixed.

The change is available in the main branch. You can get it by installing the latest version from github:

python -m pip install --upgrade git+https://github.com/paul-gauthier/aider.git

If you have a chance to try it, let me know if it works better for you.

cbrake commented 1 day ago

I ran into the same problem with this project:

https://github.com/simpleiot/simpleiot

And your fix works for me -- thanks!