mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-09-12 00:07:42 +03:00
Use a newtype for ThreadId
This commit is contained in:
parent
83a8167402
commit
bda05ec4bf
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
transport::{Payload, Request, Transport},
|
||||
types::*,
|
||||
Error, Result,
|
||||
Error, Result, ThreadId,
|
||||
};
|
||||
use helix_core::syntax::DebuggerQuirks;
|
||||
|
||||
@ -30,9 +30,9 @@ pub struct Client {
|
||||
request_counter: AtomicU64,
|
||||
pub caps: Option<DebuggerCapabilities>,
|
||||
// thread_id -> frames
|
||||
pub stack_frames: HashMap<isize, Vec<StackFrame>>,
|
||||
pub thread_states: HashMap<isize, String>,
|
||||
pub thread_id: Option<isize>,
|
||||
pub stack_frames: HashMap<ThreadId, Vec<StackFrame>>,
|
||||
pub thread_states: HashMap<ThreadId, String>,
|
||||
pub thread_id: Option<ThreadId>,
|
||||
/// Currently active frame for the current thread.
|
||||
pub active_frame: Option<usize>,
|
||||
pub breakpoints: Vec<Breakpoint>,
|
||||
@ -311,7 +311,7 @@ pub async fn configuration_done(&mut self) -> Result<()> {
|
||||
self.request::<requests::ConfigurationDone>(()).await
|
||||
}
|
||||
|
||||
pub async fn continue_thread(&mut self, thread_id: isize) -> Result<Option<bool>> {
|
||||
pub async fn continue_thread(&mut self, thread_id: ThreadId) -> Result<Option<bool>> {
|
||||
let args = requests::ContinueArguments { thread_id };
|
||||
|
||||
let response = self.request::<requests::Continue>(args).await?;
|
||||
@ -320,7 +320,7 @@ pub async fn continue_thread(&mut self, thread_id: isize) -> Result<Option<bool>
|
||||
|
||||
pub async fn stack_trace(
|
||||
&mut self,
|
||||
thread_id: isize,
|
||||
thread_id: ThreadId,
|
||||
) -> Result<(Vec<StackFrame>, Option<usize>)> {
|
||||
let args = requests::StackTraceArguments {
|
||||
thread_id,
|
||||
@ -358,7 +358,7 @@ pub async fn variables(&mut self, variables_reference: usize) -> Result<Vec<Vari
|
||||
Ok(response.variables)
|
||||
}
|
||||
|
||||
pub async fn step_in(&mut self, thread_id: isize) -> Result<()> {
|
||||
pub async fn step_in(&mut self, thread_id: ThreadId) -> Result<()> {
|
||||
let args = requests::StepInArguments {
|
||||
thread_id,
|
||||
target_id: None,
|
||||
@ -368,7 +368,7 @@ pub async fn step_in(&mut self, thread_id: isize) -> Result<()> {
|
||||
self.request::<requests::StepIn>(args).await
|
||||
}
|
||||
|
||||
pub async fn step_out(&mut self, thread_id: isize) -> Result<()> {
|
||||
pub async fn step_out(&mut self, thread_id: ThreadId) -> Result<()> {
|
||||
let args = requests::StepOutArguments {
|
||||
thread_id,
|
||||
granularity: None,
|
||||
@ -377,7 +377,7 @@ pub async fn step_out(&mut self, thread_id: isize) -> Result<()> {
|
||||
self.request::<requests::StepOut>(args).await
|
||||
}
|
||||
|
||||
pub async fn next(&mut self, thread_id: isize) -> Result<()> {
|
||||
pub async fn next(&mut self, thread_id: ThreadId) -> Result<()> {
|
||||
let args = requests::NextArguments {
|
||||
thread_id,
|
||||
granularity: None,
|
||||
@ -386,7 +386,7 @@ pub async fn next(&mut self, thread_id: isize) -> Result<()> {
|
||||
self.request::<requests::Next>(args).await
|
||||
}
|
||||
|
||||
pub async fn pause(&mut self, thread_id: isize) -> Result<()> {
|
||||
pub async fn pause(&mut self, thread_id: ThreadId) -> Result<()> {
|
||||
let args = requests::PauseArguments { thread_id };
|
||||
|
||||
self.request::<requests::Pause>(args).await
|
||||
|
@ -2,6 +2,17 @@
|
||||
use serde_json::Value;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(
|
||||
Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize,
|
||||
)]
|
||||
pub struct ThreadId(isize);
|
||||
|
||||
impl std::fmt::Display for ThreadId {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Request {
|
||||
type Arguments: serde::de::DeserializeOwned + serde::Serialize;
|
||||
type Result: serde::de::DeserializeOwned + serde::Serialize;
|
||||
@ -157,7 +168,7 @@ pub struct StackFrame {
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Thread {
|
||||
pub id: isize,
|
||||
pub id: ThreadId,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
@ -317,7 +328,7 @@ impl Request for SetBreakpoints {
|
||||
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ContinueArguments {
|
||||
pub thread_id: isize,
|
||||
pub thread_id: ThreadId,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
@ -338,7 +349,7 @@ impl Request for Continue {
|
||||
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct StackTraceArguments {
|
||||
pub thread_id: isize,
|
||||
pub thread_id: ThreadId,
|
||||
pub start_frame: Option<usize>,
|
||||
pub levels: Option<usize>,
|
||||
pub format: Option<StackFrameFormat>,
|
||||
@ -424,7 +435,7 @@ impl Request for Variables {
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct StepInArguments {
|
||||
pub thread_id: isize,
|
||||
pub thread_id: ThreadId,
|
||||
pub target_id: Option<usize>,
|
||||
pub granularity: Option<String>,
|
||||
}
|
||||
@ -441,7 +452,7 @@ impl Request for StepIn {
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct StepOutArguments {
|
||||
pub thread_id: isize,
|
||||
pub thread_id: ThreadId,
|
||||
pub granularity: Option<String>,
|
||||
}
|
||||
|
||||
@ -457,7 +468,7 @@ impl Request for StepOut {
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct NextArguments {
|
||||
pub thread_id: isize,
|
||||
pub thread_id: ThreadId,
|
||||
pub granularity: Option<String>,
|
||||
}
|
||||
|
||||
@ -473,7 +484,7 @@ impl Request for Next {
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PauseArguments {
|
||||
pub thread_id: isize,
|
||||
pub thread_id: ThreadId,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -574,7 +585,7 @@ pub enum Event {
|
||||
pub struct Stopped {
|
||||
pub reason: String,
|
||||
pub description: Option<String>,
|
||||
pub thread_id: Option<isize>,
|
||||
pub thread_id: Option<ThreadId>,
|
||||
pub preserve_focus_hint: Option<bool>,
|
||||
pub text: Option<String>,
|
||||
pub all_threads_stopped: Option<bool>,
|
||||
@ -584,7 +595,7 @@ pub struct Stopped {
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Continued {
|
||||
pub thread_id: isize,
|
||||
pub thread_id: ThreadId,
|
||||
pub all_threads_continued: Option<bool>,
|
||||
}
|
||||
|
||||
@ -604,7 +615,7 @@ pub struct Terminated {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Thread {
|
||||
pub reason: String,
|
||||
pub thread_id: isize,
|
||||
pub thread_id: ThreadId,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
@ -661,7 +672,7 @@ pub struct Capabilities {
|
||||
// #[serde(rename_all = "camelCase")]
|
||||
// pub struct Invalidated {
|
||||
// pub areas: Vec<InvalidatedArea>,
|
||||
// pub thread_id: Option<usize>,
|
||||
// pub thread_id: Option<ThreadId>,
|
||||
// pub stack_frame_id: Option<usize>,
|
||||
// }
|
||||
|
||||
|
@ -320,7 +320,12 @@ pub async fn handle_debugger_message(&mut self, payload: helix_dap::Payload) {
|
||||
for thread in threads {
|
||||
fetch_stack_trace(debugger, thread.id).await;
|
||||
}
|
||||
select_thread_id(&mut self.editor, thread_id.unwrap_or(0), false).await;
|
||||
select_thread_id(
|
||||
&mut self.editor,
|
||||
thread_id.unwrap_or_default(),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
} else if let Some(thread_id) = thread_id {
|
||||
debugger.thread_states.insert(thread_id, reason.clone()); // TODO: dap uses "type" || "reason" here
|
||||
|
@ -6,7 +6,7 @@
|
||||
ui::{FilePicker, Prompt, PromptEvent},
|
||||
};
|
||||
use helix_core::{syntax::DebugConfigCompletion, Selection};
|
||||
use helix_dap::{self as dap, Client};
|
||||
use helix_dap::{self as dap, Client, ThreadId};
|
||||
use helix_lsp::block_on;
|
||||
|
||||
use serde_json::{to_value, Value};
|
||||
@ -34,7 +34,7 @@ pub fn resume_application(debugger: &mut Client) {
|
||||
debugger.thread_id = None;
|
||||
}
|
||||
|
||||
pub async fn select_thread_id(editor: &mut Editor, thread_id: isize, force: bool) {
|
||||
pub async fn select_thread_id(editor: &mut Editor, thread_id: ThreadId, force: bool) {
|
||||
let debugger = match &mut editor.debugger {
|
||||
Some(debugger) => debugger,
|
||||
None => return,
|
||||
@ -53,7 +53,7 @@ pub async fn select_thread_id(editor: &mut Editor, thread_id: isize, force: bool
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn fetch_stack_trace(debugger: &mut Client, thread_id: isize) {
|
||||
pub async fn fetch_stack_trace(debugger: &mut Client, thread_id: ThreadId) {
|
||||
let (frames, _) = match debugger.stack_trace(thread_id).await {
|
||||
Ok(frames) => frames,
|
||||
Err(_) => return,
|
||||
|
Loading…
Reference in New Issue
Block a user