-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add auto completions #79
Conversation
Just fyi, in my commands PR #59 I change how we use prompt toolkit a lot; you might want to work off of that branch until it gets merged. |
@biobootloader would love your thoughts are on |
mentat/mentat_prompt_session.py
Outdated
# 4. Decide on what words to auto complete (right now it's everything) | ||
# a. Use ctags to add types (e.g. function, class) to completions | ||
# 5. Use ctags if available, fallback to pygments lexer if not | ||
# 6. Consider fuzzy matching completions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love fuzzy matching in general. I guess the downside could be too many options popping up for everything you type?
Rift has an @
syntax for referencing files, maybe something like that could be good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can limit the number of completions shown. Prompt Toolkit has a built-in fuzzy matcher that's pretty fast too.
Yea I like the @
directive for Rift and Cursor. Happy to make that character show file completions specifically.
I think it is going to require changes to
Both Maybe a better name for Another question is what we should auto-complete - just stuff in context or also stuff that's not in context, like from the I'm not really sure about any of this, but those are some initial thoughts! |
I don't think this branch has the partial files changes from #69, sorry that that complicates things! |
Yup that sounds good. Make |
Right now it's just stuff inside the context, however I don't think it would hurt to add completions for files/syntax inside git repos? I think we could enable/disable this depending on if the code-map is enabled/disabled. |
Good callout! Will fetch from main and update this |
@@ -4,3 +4,4 @@ known_first_party = "mentat" | |||
|
|||
[tool.ruff] | |||
line-length = 120 | |||
ignore = ["E731"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this rule to ignore lambda assignment (https://beta.ruff.rs/docs/rules/lambda-assignment/) as we have these everywhere and imo they're ok as long as you don't have a ton of logic in them.
In an effort to keep the number of changes down in this PR, I think we should add fuzzy matching in a separate feature branch. Same goes for the |
I don't think it's worth the effort to generate completions from I also decided to not include completions from all files in the git repo (if there is one), only files explicitly added in the code context, since there's too much irrelevant information being suggested. This is the how VSCode does their compeltions anyways which I think is a good choice. |
I read through this and tested it out, and it looks good to me. One comment: eventually it'd be nice if this works with different interfaces. Like if I could call |
Agreed, "core" Mentat would provide lists of available completions to all interfaces |
Agreed, let's make followup issues for these. The |
Totally. I'd like to have the completions using pygls to pull from language servers (assuming we can get it working outside of VSCode). Would make the auto-completions tool-agnostic and higher quality. |
Do you have any preference on how we should handle this? It's pretty common for me to see both completion sources, so I think it's worth looking into. I'm thinking we could copy how ipython does it and have arrow keys finish/cycle command history completions, and have tab/shift+tab or ctrl+n/ctrl+p finish/cycle auto-completions. |
mentat/code_file_manager.py
Outdated
if self.files: | ||
if self.code_context.files: | ||
cprint("Files included in context:", "green") | ||
else: | ||
cprint("No files included in context.\n", "red") | ||
cprint("Git project: ", "green", end="") | ||
cprint(self.git_root.name, "blue") | ||
cprint(self.config.git_root.name, "blue") | ||
_print_path_tree( | ||
_build_path_tree(self.files, self.git_root), | ||
get_paths_with_git_diffs(self.git_root), | ||
self.git_root, | ||
_build_path_tree(self.code_context.files.values(), self.config.git_root), | ||
get_paths_with_git_diffs(self.config.git_root), | ||
self.config.git_root, | ||
) | ||
print() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think displaying the project tree / include files should be done by CodeContext. And instead of being in the init should be in something like CodeContext.display_context_tree(), called in app.py after initializing the CodeContext.
That sounds great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome!
Summary
This PR adds completions for syntax (classes, variables, functions, etc.) and file names for the prompt session.
Completions kept in sync as files are added/updated/deleted (they are "refreshed" every 5 seconds atm). Whenever a user starts a prompt with "/" we return command completions only.
Since we need to keep track of what files are in the context for keeping completions up-to-date, I've added a
CodeFileIndex
class that currently just holds a set of file names added into the context.CodeFileIndex
is shared betweenCodeFileManager
andUserInputManager
. This is done so that whenCodeFileIndex
modifies the filesystem, `UserInputManager can see these modifications and make updates to completions.To-Do
CodeFileManager
MentatCompleter