mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 12:55:00 +00:00
feat: enhance autocomplete functionality for code tokens and filenames
This commit is contained in:
parent
d407a878c4
commit
31f7856f41
2 changed files with 7 additions and 6 deletions
|
@ -78,7 +78,9 @@ class AutoCompleter(Completer):
|
||||||
except ClassNotFound:
|
except ClassNotFound:
|
||||||
continue
|
continue
|
||||||
tokens = list(lexer.get_tokens(content))
|
tokens = list(lexer.get_tokens(content))
|
||||||
self.words.update(token[1] for token in tokens if token[0] in Token.Name)
|
self.words.update(
|
||||||
|
(token[1], f"`{token[1]}`") for token in tokens if token[0] in Token.Name
|
||||||
|
)
|
||||||
|
|
||||||
def get_command_completions(self, text, words):
|
def get_command_completions(self, text, words):
|
||||||
candidates = []
|
candidates = []
|
||||||
|
@ -125,10 +127,7 @@ class AutoCompleter(Completer):
|
||||||
|
|
||||||
candidates = self.words
|
candidates = self.words
|
||||||
candidates.update(set(self.fname_to_rel_fnames))
|
candidates.update(set(self.fname_to_rel_fnames))
|
||||||
candidates = [
|
candidates = [word if type(word) is tuple else (word, word) for word in candidates]
|
||||||
(word, f"`{word}`" if word not in self.fname_to_rel_fnames else word)
|
|
||||||
for word in candidates
|
|
||||||
]
|
|
||||||
|
|
||||||
last_word = words[-1]
|
last_word = words[-1]
|
||||||
for word_match, word_insert in candidates:
|
for word_match, word_insert in candidates:
|
||||||
|
|
|
@ -3,6 +3,7 @@ import unittest
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
from aider.dump import dump # noqa: F401
|
||||||
from aider.io import AutoCompleter, ConfirmGroup, InputOutput
|
from aider.io import AutoCompleter, ConfirmGroup, InputOutput
|
||||||
from aider.utils import ChdirTemporaryDirectory
|
from aider.utils import ChdirTemporaryDirectory
|
||||||
|
|
||||||
|
@ -33,7 +34,8 @@ class TestInputOutput(unittest.TestCase):
|
||||||
|
|
||||||
Path(fname).write_text("def hello(): pass\n")
|
Path(fname).write_text("def hello(): pass\n")
|
||||||
autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
|
autocompleter = AutoCompleter(root, rel_fnames, addable_rel_fnames, commands, "utf-8")
|
||||||
self.assertEqual(autocompleter.words, set(rel_fnames + ["hello"]))
|
dump(autocompleter.words)
|
||||||
|
self.assertEqual(autocompleter.words, set(rel_fnames + [("hello", "`hello`")]))
|
||||||
|
|
||||||
encoding = "utf-16"
|
encoding = "utf-16"
|
||||||
some_content_which_will_error_if_read_with_encoding_utf8 = "ÅÍÎÏ".encode(encoding)
|
some_content_which_will_error_if_read_with_encoding_utf8 = "ÅÍÎÏ".encode(encoding)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue