-
Notifications
You must be signed in to change notification settings - Fork 162
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
Support adding files in directories to context #438
base: master
Are you sure you want to change the base?
Support adding files in directories to context #438
Conversation
Looks good! I'll test it when I can and merge. |
I just noticed this in the docstring of this function (emphasis added):
I may not be understanding what this means, but as far as I can tell the function does not behave in the manner described: if I select a region, add it to the context, then re-select it and call |
It could probably be worded better. Here is an updated description, let me know if it makes more sense:
|
We should also add the ability to add directories to the context when running |
I wasn’t familiar with this command, but yeah, it seems it should mirror the behavior of |
Perhaps we should change |
Please go ahead.
|
8e0419c
to
dcedf1c
Compare
@karthink, I undid the previous attempt and pushed a new version, which (1) works with both |
dcedf1c
to
147fe6e
Compare
Will take a look soon, thanks for the update! |
ACTION should be either `add' or `remove'." | ||
(cl-block gptel-context--handle-directory | ||
(when (eq action 'add) | ||
(unless (y-or-n-p (format "Recursively add all files from directory %s? " path)) |
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.
gptel-context--handle-directory
is a non-interactive function. Running an interactive y-or-n-p
check inside a non-interactive function is not a good idea, since gptel-add
can be used non-interactively for scripting. Here's an example. So this check should happen in gptel-context-add-file
.
The other advantage is that we only need to ask once per call to gptel-add
, which is less annoying than asking per-directory.
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.
The other advantage is that we only need to ask once per call to
gptel-add
, which is less annoying than asking per-directory.
Apologies if I’m misunderstanding something, but since gptel-add
calls gptel-context-add-file
once per directory, moving the logic to the latter would still prompt once per directory rather than once per gptel-add
call, I think. Can you clarify?
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 are correct, I think I misunderstood something more basic about your proposed changes:
- You are not adding all files inside a directory recursively -- instead you're only descending one level, and ignoring directories below that. Is this the behavior we want? I thought you wanted to add all files inside a directory -- why stop at the immediate children? For example, see Adding context files recursively from a directory #513.
- On the other hand, if we do it this way, users will naturally want to exclude certain directories, like
.git
. If we use a rule where we ignore dotfiles, we'll also have to make an exception to that for when users want to send a configuration file.foo
. They'll also want to see the tree view in the context inspection buffer instead a flat list of file contents, and we'll end up having to reimplementmagit-section
or part ofdired
, which gets messy very fast.
So there's a more important issue than where to run the y-or-n-p
here. What do you think we should do?
(setf (alist-get file gptel-context--alist nil 'remove #'equal) nil) | ||
(message "File \"%s\" removed from context." file))))) | ||
files)))) | ||
|
||
(defun gptel-context-add-file (path) |
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.
We can add an &optional confirm-dir
argument to this function that the (interactive ...)
form can set to t
.
(message "File \"%s\" added to context." path) | ||
path)) | ||
(cond ((file-directory-p path) | ||
(gptel-context--handle-directory path 'add)) |
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.
Unless conirm-dir
is nil
, we can run the y-or-n-p
check here before calling gptel-context--handle-directory
.
Currently, attempting to add directories to the context in Dired will throw an error. This PR provides support for adding files in directories to the context: if there is a directory at point, or the marked files include one or more directories, their files will recursively be added to the context.