Add diagnostic information to context of inline assistant (#18096)
Release Notes: - Added Diagnostic information to inline assistant. This enables users to just say "Fix this" and have the model know what the errors are.
This commit is contained in:
parent
fbbf0393cb
commit
28a54ce122
2 changed files with 32 additions and 2 deletions
|
@ -47,6 +47,17 @@ And here's the section to rewrite based on that prompt again for reference:
|
||||||
<rewrite_this>
|
<rewrite_this>
|
||||||
{{{rewrite_section}}}
|
{{{rewrite_section}}}
|
||||||
</rewrite_this>
|
</rewrite_this>
|
||||||
|
|
||||||
|
{{#if diagnostic_errors}}
|
||||||
|
{{#each diagnostic_errors}}
|
||||||
|
<diagnostic_error>
|
||||||
|
<line_number>{{line_number}}</line_number>
|
||||||
|
<error_message>{{error_message}}</error_message>
|
||||||
|
<code_content>{{code_content}}</code_content>
|
||||||
|
</diagnostic_error>
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
Only make changes that are necessary to fulfill the prompt, leave everything else as-is. All surrounding {{content_type}} will be preserved.
|
Only make changes that are necessary to fulfill the prompt, leave everything else as-is. All surrounding {{content_type}} will be preserved.
|
||||||
|
|
|
@ -4,13 +4,20 @@ use fs::Fs;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use gpui::AssetSource;
|
use gpui::AssetSource;
|
||||||
use handlebars::{Handlebars, RenderError};
|
use handlebars::{Handlebars, RenderError};
|
||||||
use language::{BufferSnapshot, LanguageName};
|
use language::{BufferSnapshot, LanguageName, Point};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::{ops::Range, path::PathBuf, sync::Arc, time::Duration};
|
use std::{ops::Range, path::PathBuf, sync::Arc, time::Duration};
|
||||||
use text::LineEnding;
|
use text::LineEnding;
|
||||||
use util::ResultExt;
|
use util::ResultExt;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct ContentPromptDiagnosticContext {
|
||||||
|
pub line_number: usize,
|
||||||
|
pub error_message: String,
|
||||||
|
pub code_content: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct ContentPromptContext {
|
pub struct ContentPromptContext {
|
||||||
pub content_type: String,
|
pub content_type: String,
|
||||||
|
@ -20,6 +27,7 @@ pub struct ContentPromptContext {
|
||||||
pub document_content: String,
|
pub document_content: String,
|
||||||
pub user_prompt: String,
|
pub user_prompt: String,
|
||||||
pub rewrite_section: Option<String>,
|
pub rewrite_section: Option<String>,
|
||||||
|
pub diagnostic_errors: Vec<ContentPromptDiagnosticContext>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
@ -261,6 +269,17 @@ impl PromptBuilder {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
let diagnostics = buffer.diagnostics_in_range::<_, Point>(range, false);
|
||||||
|
let diagnostic_errors: Vec<ContentPromptDiagnosticContext> = diagnostics
|
||||||
|
.map(|entry| {
|
||||||
|
let start = entry.range.start;
|
||||||
|
ContentPromptDiagnosticContext {
|
||||||
|
line_number: (start.row + 1) as usize,
|
||||||
|
error_message: entry.diagnostic.message.clone(),
|
||||||
|
code_content: buffer.text_for_range(entry.range.clone()).collect(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
let context = ContentPromptContext {
|
let context = ContentPromptContext {
|
||||||
content_type: content_type.to_string(),
|
content_type: content_type.to_string(),
|
||||||
|
@ -270,8 +289,8 @@ impl PromptBuilder {
|
||||||
document_content,
|
document_content,
|
||||||
user_prompt,
|
user_prompt,
|
||||||
rewrite_section,
|
rewrite_section,
|
||||||
|
diagnostic_errors,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.handlebars.lock().render("content_prompt", &context)
|
self.handlebars.lock().render("content_prompt", &context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue