Add "Fix with Assistant" code action on lines with diagnostics (#18163)
Release Notes: - Added a new "Fix with Assistant" action on code with errors or warnings. --------- Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
1efe87029b
commit
7051bc00c2
13 changed files with 418 additions and 72 deletions
|
@ -1431,7 +1431,7 @@ impl LspStore {
|
|||
buffer_handle: &Model<Buffer>,
|
||||
range: Range<Anchor>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Vec<CodeAction>> {
|
||||
) -> Task<Result<Vec<CodeAction>>> {
|
||||
if let Some((upstream_client, project_id)) = self.upstream_client() {
|
||||
let request_task = upstream_client.request(proto::MultiLspQuery {
|
||||
buffer_id: buffer_handle.read(cx).remote_id().into(),
|
||||
|
@ -1451,14 +1451,11 @@ impl LspStore {
|
|||
let buffer = buffer_handle.clone();
|
||||
cx.spawn(|weak_project, cx| async move {
|
||||
let Some(project) = weak_project.upgrade() else {
|
||||
return Vec::new();
|
||||
return Ok(Vec::new());
|
||||
};
|
||||
join_all(
|
||||
request_task
|
||||
.await
|
||||
.log_err()
|
||||
.map(|response| response.responses)
|
||||
.unwrap_or_default()
|
||||
let responses = request_task.await?.responses;
|
||||
let actions = join_all(
|
||||
responses
|
||||
.into_iter()
|
||||
.filter_map(|lsp_response| match lsp_response.response? {
|
||||
proto::lsp_response::Response::GetCodeActionsResponse(response) => {
|
||||
|
@ -1470,7 +1467,7 @@ impl LspStore {
|
|||
}
|
||||
})
|
||||
.map(|code_actions_response| {
|
||||
let response = GetCodeActions {
|
||||
GetCodeActions {
|
||||
range: range.clone(),
|
||||
kinds: None,
|
||||
}
|
||||
|
@ -1479,14 +1476,17 @@ impl LspStore {
|
|||
project.clone(),
|
||||
buffer.clone(),
|
||||
cx.clone(),
|
||||
);
|
||||
async move { response.await.log_err().unwrap_or_default() }
|
||||
)
|
||||
}),
|
||||
)
|
||||
.await
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
Ok(actions
|
||||
.into_iter()
|
||||
.collect::<Result<Vec<Vec<_>>>>()?
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect())
|
||||
})
|
||||
} else {
|
||||
let all_actions_task = self.request_multiple_lsp_locally(
|
||||
|
@ -1498,7 +1498,9 @@ impl LspStore {
|
|||
},
|
||||
cx,
|
||||
);
|
||||
cx.spawn(|_, _| async move { all_actions_task.await.into_iter().flatten().collect() })
|
||||
cx.spawn(
|
||||
|_, _| async move { Ok(all_actions_task.await.into_iter().flatten().collect()) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3247,7 +3247,7 @@ impl Project {
|
|||
buffer_handle: &Model<Buffer>,
|
||||
range: Range<T>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Vec<CodeAction>> {
|
||||
) -> Task<Result<Vec<CodeAction>>> {
|
||||
let buffer = buffer_handle.read(cx);
|
||||
let range = buffer.anchor_before(range.start)..buffer.anchor_before(range.end);
|
||||
self.lsp_store.update(cx, |lsp_store, cx| {
|
||||
|
|
|
@ -2708,7 +2708,7 @@ async fn test_apply_code_actions_with_commands(cx: &mut gpui::TestAppContext) {
|
|||
.next()
|
||||
.await;
|
||||
|
||||
let action = actions.await[0].clone();
|
||||
let action = actions.await.unwrap()[0].clone();
|
||||
let apply = project.update(cx, |project, cx| {
|
||||
project.apply_code_action(buffer.clone(), action, true, cx)
|
||||
});
|
||||
|
@ -5046,6 +5046,7 @@ async fn test_multiple_language_server_actions(cx: &mut gpui::TestAppContext) {
|
|||
vec!["TailwindServer code action", "TypeScriptServer code action"],
|
||||
code_actions_task
|
||||
.await
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|code_action| code_action.lsp_action.title)
|
||||
.sorted()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue