-
Notifications
You must be signed in to change notification settings - Fork 8
Chore: Add region location info with git relative path in prompts #48
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
Conversation
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.
Pull Request Overview
This PR enhances the code-change and ask-question commands by adding git-relative file paths and line number information to selected regions in prompts. The region location is formatted as path/to/file.el#L10-L20 (following GitHub's URL fragment syntax), helping AI models better focus on specific code regions.
Key Changes
- Added region location information (git-relative path + line numbers) to prompts when a region is selected
- Updated prompt formatting to use "Selected region:" label with optional location info
- Made note messages context-aware, distinguishing between region-specific and general operations
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| ai-code-discussion.el | Added region location info computation and updated prompt formatting for ask-question commands |
| ai-code-change.el | Added declare-function for ai-code--get-git-relative-paths, computed region location info, and updated prompt formatting for code-change commands |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| (region-end-line (when region-active | ||
| (line-number-at-pos (region-end)))) | ||
| (git-relative-path (when (and region-active buffer-file-name) | ||
| (car (ai-code--get-git-relative-paths (list buffer-file-name))))) | ||
| (region-location-info (when (and region-active git-relative-path region-start-line region-end-line) | ||
| (format "%s#L%d-L%d" git-relative-path region-start-line region-end-line))) |
Copilot
AI
Nov 15, 2025
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.
[nitpick] The logic for computing region-end-line, git-relative-path, and region-location-info is duplicated between this file and ai-code-change.el (lines 103-108). Consider extracting this into a shared helper function to reduce code duplication and improve maintainability.
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.
@copilot open a new pull request to apply changes based on this feedback
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
So code-change and ask-question can better focus on a particular selected region.