Skip to content

Commit

Permalink
Finish console completions DapCommand impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony-Eid committed Feb 13, 2025
1 parent db433f4 commit e6ea146
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
12 changes: 9 additions & 3 deletions crates/dap/src/proto_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions crates/debugger_ui/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,17 @@ impl ConsoleQueryBarCompletionProvider {
buffer_position: language::Anchor,
cx: &mut Context<Editor>,
) -> gpui::Task<gpui::Result<Vec<project::Completion>>> {
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")))
Expand Down
17 changes: 8 additions & 9 deletions crates/project/src/debugger/dap_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> <Self::DapRequest as dap::requests::Request>::Arguments {
dap::CompletionsArguments {
text: self.text.clone(),
text: self.query.clone(),
frame_id: self.frame_id,
column: None,
column: self.column,
line: None,
}
}
Expand All @@ -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),
}
Expand All @@ -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,
Expand All @@ -1416,9 +1416,8 @@ impl DapCommand for super::dap_session::CompletionsQuery {
&self,
message: <Self::ProtoRequest as proto::RequestMessage>::Response,
) -> Result<Self::Response> {
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),
})
}

Expand All @@ -1428,7 +1427,7 @@ impl DapCommand for super::dap_session::CompletionsQuery {
) -> <Self::ProtoRequest as proto::RequestMessage>::Response {
proto::DapCompletionResponse {
client_id: _debug_client_id.to_proto(),
completions: Vec::to_proto(message.completions),
completions: message.targets.to_proto(),
}
}
}
Expand Down
30 changes: 14 additions & 16 deletions crates/project/src/debugger/dap_session.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -60,7 +60,7 @@ pub struct Variable {
impl From<dap::Variable> for Variable {
fn from(dap: dap::Variable) -> Self {
Self {
dap: dap.clone(),
dap,
variables: vec![],
}
}
Expand All @@ -75,7 +75,7 @@ pub struct Scope {
impl From<dap::Scope> for Scope {
fn from(scope: dap::Scope) -> Self {
Self {
dap,
dap: scope,
variables: vec![],
}
}
Expand Down Expand Up @@ -502,21 +502,19 @@ impl Client {
}
}

pub async fn completions(
pub fn completions(
&mut self,
query: CompletionsQuery,
cx: &mut Context<Self>,
) -> Task<Result<dap::CompletionItem>> {
let task = self.request(
CompletionsCommand(CompletionsQuery),
Self::empty_response,
cx,
);
) -> Task<Result<Vec<dap::CompletionItem>>> {
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"))?,
)
})
}

Expand Down

0 comments on commit e6ea146

Please sign in to comment.