diff --git a/crates/dap/src/proto_conversions.rs b/crates/dap/src/proto_conversions.rs index 5b9db1b98bccd9..60d394fbb9b1df 100644 --- a/crates/dap/src/proto_conversions.rs +++ b/crates/dap/src/proto_conversions.rs @@ -501,7 +501,11 @@ impl ProtoConversion for dap_types::CompletionItem { label: self.label.clone(), text: self.text.clone(), detail: self.detail.clone(), - typ: self.type_.as_ref().map(ProtoConversion::to_proto), + typ: self + .type_ + .as_ref() + .map(ProtoConversion::to_proto) + .map(|typ| typ.into()), start: self.start, length: self.length, selection_start: self.selection_start, @@ -511,12 +515,14 @@ impl ProtoConversion for dap_types::CompletionItem { } fn from_proto(payload: Self::ProtoType) -> Self { + let typ = payload.typ(); // todo(debugger): This might be a potential issue/bug because it defaults to a type when it's None + Self { label: payload.label, detail: payload.detail, sort_text: payload.sort_text, - text: payload.text, - type_: Self::ProtoType::from_proto(payload.typ), + text: payload.text.clone(), + type_: Some(dap_types::CompletionItemType::from_proto(typ)), start: payload.start, length: payload.length, selection_start: payload.selection_start, diff --git a/crates/debugger_ui/src/console.rs b/crates/debugger_ui/src/console.rs index 91d58fb56d194d..bafaa8633f9aad 100644 --- a/crates/debugger_ui/src/console.rs +++ b/crates/debugger_ui/src/console.rs @@ -498,14 +498,17 @@ impl ConsoleQueryBarCompletionProvider { buffer_position: language::Anchor, cx: &mut Context, ) -> gpui::Task>> { - let buffer = buffer.read(cx); + let client_id = console.read(cx).client_id; let completion_task = console.update(cx, |console, cx| { if let Some(client_state) = console.session.read(cx).client_state(client_id) { client_state.update(cx, |state, cx| { let frame_id = Some(console.stack_frame_list.read(cx).current_stack_frame_id()); - state.completions(CompletionsQuery::new(buffer, buffer_position, frame_id), cx) + state.completions( + CompletionsQuery::new(buffer.read(cx), buffer_position, frame_id), + cx, + ) }) } else { Task::ready(Err(anyhow!("failed to fetch completions"))) diff --git a/crates/project/src/debugger/dap_command.rs b/crates/project/src/debugger/dap_command.rs index d7c1707d9e26da..da0df5b9c89020 100644 --- a/crates/project/src/debugger/dap_command.rs +++ b/crates/project/src/debugger/dap_command.rs @@ -1358,15 +1358,15 @@ impl DapCommand for ScopesCommand { } impl DapCommand for super::dap_session::CompletionsQuery { - type Response = dap::DapCompletionResponse; + type Response = dap::CompletionsResponse; type DapRequest = dap::requests::Completions; type ProtoRequest = proto::DapCompletionRequest; fn to_dap(&self) -> ::Arguments { dap::CompletionsArguments { - text: self.text.clone(), + text: self.query.clone(), frame_id: self.frame_id, - column: None, + column: self.column, line: None, } } @@ -1393,7 +1393,7 @@ impl DapCommand for super::dap_session::CompletionsQuery { client_id: debug_client_id.to_proto(), project_id: upstream_project_id, frame_id: self.frame_id, - query: self.query, + query: self.query.clone(), column: self.column, line: self.line.map(u64::from), } @@ -1405,7 +1405,7 @@ impl DapCommand for super::dap_session::CompletionsQuery { fn from_proto(request: &Self::ProtoRequest) -> Self { Self { - query: request.query, + query: request.query.clone(), frame_id: request.frame_id, column: request.column, line: request.line, @@ -1416,9 +1416,8 @@ impl DapCommand for super::dap_session::CompletionsQuery { &self, message: ::Response, ) -> Result { - Ok(dap::DapCompletionResponse { - client_id: DebugAdapterClientId::from_proto(message.client_id), - completions: Vec::from_proto(message.completions), + Ok(dap::CompletionsResponse { + targets: Vec::from_proto(message.completions), }) } @@ -1428,7 +1427,7 @@ impl DapCommand for super::dap_session::CompletionsQuery { ) -> ::Response { proto::DapCompletionResponse { client_id: _debug_client_id.to_proto(), - completions: Vec::to_proto(message.completions), + completions: message.targets.to_proto(), } } } diff --git a/crates/project/src/debugger/dap_session.rs b/crates/project/src/debugger/dap_session.rs index 0545f8d0e59f45..ddce2b602baea2 100644 --- a/crates/project/src/debugger/dap_session.rs +++ b/crates/project/src/debugger/dap_session.rs @@ -1,8 +1,8 @@ use super::dap_command::{ - self, CompletionsCommand, ContinueCommand, DapCommand, DisconnectCommand, EvaluateCommand, - NextCommand, PauseCommand, RestartCommand, RestartStackFrameCommand, ScopesCommand, - SetVariableValueCommand, StepBackCommand, StepCommand, StepInCommand, StepOutCommand, - TerminateCommand, TerminateThreadsCommand, VariablesCommand, + self, ContinueCommand, DapCommand, DisconnectCommand, EvaluateCommand, NextCommand, + PauseCommand, RestartCommand, RestartStackFrameCommand, ScopesCommand, SetVariableValueCommand, + StepBackCommand, StepCommand, StepInCommand, StepOutCommand, TerminateCommand, + TerminateThreadsCommand, VariablesCommand, }; use anyhow::{anyhow, Result}; use collections::{BTreeMap, HashMap}; @@ -60,7 +60,7 @@ pub struct Variable { impl From for Variable { fn from(dap: dap::Variable) -> Self { Self { - dap: dap.clone(), + dap, variables: vec![], } } @@ -75,7 +75,7 @@ pub struct Scope { impl From for Scope { fn from(scope: dap::Scope) -> Self { Self { - dap, + dap: scope, variables: vec![], } } @@ -502,21 +502,19 @@ impl Client { } } - pub async fn completions( + pub fn completions( &mut self, query: CompletionsQuery, cx: &mut Context, - ) -> Task> { - let task = self.request( - CompletionsCommand(CompletionsQuery), - Self::empty_response, - cx, - ); + ) -> Task>> { + let task = self.request(query, |_, _, _| {}, cx); cx.background_executor().spawn(async move { - Ok(task - .await - .ok_or_else(anyhow!("failed to fetch completions"))?) + anyhow::Ok( + task.await + .map(|response| response.targets) + .ok_or_else(|| anyhow!("failed to fetch completions"))?, + ) }) }