fixed file not found in autocompleter, issue #30

This commit is contained in:
Paul Gauthier 2023-07-04 12:38:36 -07:00
parent 4373006137
commit 5d18ebd724
2 changed files with 8 additions and 5 deletions

View file

@ -39,8 +39,11 @@ class AutoCompleter(Completer):
self.words.add(rel_fname) self.words.add(rel_fname)
fname = os.path.join(root, rel_fname) fname = os.path.join(root, rel_fname)
with open(fname, "r") as f: try:
content = f.read() with open(fname, "r") as f:
content = f.read()
except FileNotFoundError:
continue
try: try:
lexer = guess_lexer_for_filename(fname, content) lexer = guess_lexer_for_filename(fname, content)
except ClassNotFound: except ClassNotFound:

View file

@ -2,7 +2,7 @@ import os
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch
from aider.io import InputOutput, AutoCompleter from aider.io import AutoCompleter, InputOutput
class TestInputOutput(unittest.TestCase): class TestInputOutput(unittest.TestCase):
@ -13,11 +13,11 @@ class TestInputOutput(unittest.TestCase):
def test_autocompleter_with_non_existent_file(self): def test_autocompleter_with_non_existent_file(self):
root = "" root = ""
rel_fnames = ["non_existent_file"] rel_fnames = ["non_existent_file.txt"]
addable_rel_fnames = [] addable_rel_fnames = []
commands = None commands = None
autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands) autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands)
self.assertEqual(autocompleter.words, set()) self.assertEqual(autocompleter.words, set(rel_fnames))
if __name__ == "__main__": if __name__ == "__main__":