-
Notifications
You must be signed in to change notification settings - Fork 1
Add summarize selection context menu feature #130
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 summarize selection context menu feature #130
Conversation
- Add new context menu item in Noted submenu for summarizing selected text - Works in any file (not just Notes folder) - Uses VS Code LLM API (GitHub Copilot) for AI-powered summarization - Generates concise 2-3 sentence summary - Inserts summary below selection with "## Summary of Selection" header - Shows error message if Copilot is unavailable
Summary of ChangesHello @jsonify, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request implements a new 'Summarize Selection' feature, allowing users to quickly obtain AI-generated summaries of any text they highlight in the editor. The functionality is integrated into the editor's context menu and automatically inserts the summary below the selection, enhancing productivity by providing instant insights into chosen text segments. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a useful 'Summarize Selection' feature. The implementation is mostly solid, with good use of progress notifications and error handling. I've identified a high-severity issue regarding cancellation token propagation which prevents the AI request from being cancelled by the user. I've also suggested a refactoring to simplify and improve the consistency of how the summary is inserted into the editor. Addressing these points will make the feature more robust and reliable.
| // Insert summary below the selection | ||
| const endPosition = selection.end; | ||
| const insertPosition = new vscode.Position(endPosition.line + 1, 0); | ||
|
|
||
| // Format the summary with header (extra blank line before header) | ||
| const summaryText = `\n\n## Summary of Selection\n\n${summary}\n`; | ||
|
|
||
| await editor.edit(editBuilder => { | ||
| // If we're at the end of a line, add a newline first | ||
| const lineText = editor.document.lineAt(endPosition.line).text; | ||
| if (endPosition.character === lineText.length) { | ||
| editBuilder.insert(new vscode.Position(endPosition.line, lineText.length), summaryText); | ||
| } else { | ||
| // Insert at the beginning of the next line | ||
| editBuilder.insert(insertPosition, summaryText); | ||
| } | ||
| }); |
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 current logic for inserting the summary is a bit complex and can lead to inconsistent vertical spacing depending on whether the selection ends at the end of a line or mid-line. This can be simplified to a single, consistent behavior by always inserting the summary at the end of the line where the selection terminates. This makes the code easier to read and ensures predictable output.
// Insert summary at the end of the line containing the selection's end point
// to ensure consistent spacing.
const endLine = editor.document.lineAt(selection.end.line);
const insertPosition = endLine.range.end;
// Format the summary with header (extra blank line before header)
const summaryText = `\n\n## Summary of Selection\n\n${summary}\n`;
await editor.edit(editBuilder => {
editBuilder.insert(insertPosition, summaryText);
});Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…tion - Add cancellation token parameter to summarizeSelection method - Pass token from withProgress to enable proper cancellation - Simplify insertion logic to always insert at end of selection line
No description provided.