Improve content generation prompt to reduce over-generation (#16333)
I focused on cases where we're inserting doc comments or annotations above symbols. I added 5 new examples to the content generation prompt, covering various scenarios: 1. Inserting documentation for a Rust struct 2. Writing docstrings for a Python class 3. Adding comments to a TypeScript method 4. Adding a derive attribute to a Rust struct 5. Adding a decorator to a Python class These examples demonstrate how to handle different languages and common tasks like adding documentation, attributes, and decorators. To improve context integration, I've made the following changes: 1. Added a `transform_context_range` that includes 3 lines before and after the transform range 2. Introduced `rewrite_section_prefix` and `rewrite_section_suffix` to provide more context around the section being rewritten 3. Updated the prompt template to include this additional context in a separate code snippet Release Notes: - Reduced instances of over-generation when inserting docs or annotations above a symbol.
This commit is contained in:
parent
bac39d7743
commit
ad44b459cd
3 changed files with 434 additions and 33 deletions
|
@ -45,6 +45,7 @@ use std::{
|
|||
task::{self, Poll},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use text::OffsetRangeExt as _;
|
||||
use theme::ThemeSettings;
|
||||
use ui::{prelude::*, CheckboxWithLabel, IconButtonShape, Popover, Tooltip};
|
||||
use util::{RangeExt, ResultExt};
|
||||
|
@ -2354,6 +2355,15 @@ impl Codegen {
|
|||
return Err(anyhow::anyhow!("invalid transformation range"));
|
||||
};
|
||||
|
||||
let mut transform_context_range = transform_range.to_point(&transform_buffer);
|
||||
transform_context_range.start.row = transform_context_range.start.row.saturating_sub(3);
|
||||
transform_context_range.start.column = 0;
|
||||
transform_context_range.end =
|
||||
(transform_context_range.end + Point::new(3, 0)).min(transform_buffer.max_point());
|
||||
transform_context_range.end.column =
|
||||
transform_buffer.line_len(transform_context_range.end.row);
|
||||
let transform_context_range = transform_context_range.to_offset(&transform_buffer);
|
||||
|
||||
let selected_ranges = self
|
||||
.selected_ranges
|
||||
.iter()
|
||||
|
@ -2376,6 +2386,7 @@ impl Codegen {
|
|||
transform_buffer,
|
||||
transform_range,
|
||||
selected_ranges,
|
||||
transform_context_range,
|
||||
)
|
||||
.map_err(|e| anyhow::anyhow!("Failed to generate content prompt: {}", e))?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue