Compare commits

...

2 Commits

Author SHA1 Message Date
Piotr Osiewicz
61da7007b9 Add 200ms grace period before breakpoints show up 2025-03-28 16:43:59 +01:00
Piotr Osiewicz
8867debd0a language server: Fix restarts sometimes not working for buffers open in go-to-definition view (#27655)
Closes #ISSUE

Release Notes:

- Fixed language server restarts sometimes not restarting a language
server.
2025-03-28 16:03:28 +01:00
3 changed files with 43 additions and 66 deletions

View File

@@ -772,11 +772,11 @@ pub struct Editor {
expect_bounds_change: Option<Bounds<Pixels>>,
tasks: BTreeMap<(BufferId, BufferRow), RunnableTasks>,
tasks_update_task: Option<Task<()>>,
pub breakpoint_store: Option<Entity<BreakpointStore>>,
breakpoint_store: Option<Entity<BreakpointStore>>,
/// Allow's a user to create a breakpoint by selecting this indicator
/// It should be None while a user is not hovering over the gutter
/// Otherwise it represents the point that the breakpoint will be shown
pub gutter_breakpoint_indicator: Option<DisplayPoint>,
gutter_breakpoint_indicator: (Option<(DisplayPoint, bool)>, Option<Task<()>>),
in_project_search: bool,
previous_search_ranges: Option<Arc<[Range<Anchor>]>>,
breadcrumb_header: Option<String>,
@@ -1535,7 +1535,7 @@ impl Editor {
tasks: Default::default(),
breakpoint_store,
gutter_breakpoint_indicator: None,
gutter_breakpoint_indicator: (None, None),
_subscriptions: vec![
cx.observe(&buffer, Self::on_buffer_changed),
cx.subscribe_in(&buffer, window, Self::on_buffer_event),
@@ -6267,7 +6267,8 @@ impl Editor {
let (color, icon) = {
let color = if self
.gutter_breakpoint_indicator
.is_some_and(|point| point.row() == row)
.0
.is_some_and(|(point, is_visible)| is_visible && point.row() == row)
{
Color::Hint
} else if breakpoint.is_disabled() {

View File

@@ -72,6 +72,7 @@ use std::{
ops::{Deref, Range},
rc::Rc,
sync::Arc,
time::Duration,
};
use sum_tree::Bias;
use text::BufferId;
@@ -893,7 +894,6 @@ impl EditorElement {
let modifiers = event.modifiers;
let gutter_hovered = gutter_hitbox.is_hovered(window);
editor.set_gutter_hovered(gutter_hovered, cx);
editor.gutter_breakpoint_indicator = None;
editor.mouse_cursor_hidden = false;
if gutter_hovered {
@@ -910,8 +910,38 @@ impl EditorElement {
.buffer_for_excerpt(buffer_anchor.excerpt_id)
.is_some_and(|buffer| buffer.file().is_some())
{
editor.gutter_breakpoint_indicator = Some(new_point);
let was_hovered = editor.gutter_breakpoint_indicator.0.is_some();
let is_visible = editor
.gutter_breakpoint_indicator
.0
.map_or(false, |(_, is_active)| is_active);
editor.gutter_breakpoint_indicator.0 = Some((new_point, is_visible));
editor.gutter_breakpoint_indicator.1.get_or_insert_with(|| {
cx.spawn(async move |this, cx| {
if !was_hovered {
cx.background_executor()
.timer(Duration::from_millis(200))
.await;
}
this.update(cx, |this, cx| {
if let Some((_, is_active)) =
this.gutter_breakpoint_indicator.0.as_mut()
{
*is_active = true;
}
cx.notify();
})
.ok();
})
});
} else {
editor.gutter_breakpoint_indicator = (None, None);
}
} else {
editor.gutter_breakpoint_indicator = (None, None);
}
cx.notify();
@@ -6836,8 +6866,10 @@ impl Element for EditorElement {
// has their mouse over that line when a breakpoint isn't there
if cx.has_flag::<Debugger>() {
let gutter_breakpoint_indicator =
self.editor.read(cx).gutter_breakpoint_indicator;
if let Some(gutter_breakpoint_point) = gutter_breakpoint_indicator {
self.editor.read(cx).gutter_breakpoint_indicator.0;
if let Some((gutter_breakpoint_point, _)) =
gutter_breakpoint_indicator.filter(|(_, is_active)| *is_active)
{
breakpoint_rows
.entry(gutter_breakpoint_point.row())
.or_insert_with(|| {

View File

@@ -16,13 +16,10 @@ use dap::{
adapters::{DapStatus, DebugAdapterName},
client::SessionId,
messages::Message,
requests::{
Completions, Evaluate, Request as _, RunInTerminal, SetExpression, SetVariable,
StartDebugging,
},
requests::{Completions, Evaluate, Request as _, RunInTerminal, StartDebugging},
Capabilities, CompletionItem, CompletionsArguments, DapRegistry, ErrorResponse,
EvaluateArguments, EvaluateArgumentsContext, EvaluateResponse, RunInTerminalRequestArguments,
SetExpressionArguments, SetVariableArguments, Source, StartDebuggingRequestArguments,
Source, StartDebuggingRequestArguments,
};
use fs::Fs;
use futures::{
@@ -710,59 +707,6 @@ impl DapStore {
})
}
#[allow(clippy::too_many_arguments)]
pub fn set_variable_value(
&self,
session_id: &SessionId,
stack_frame_id: u64,
variables_reference: u64,
name: String,
value: String,
evaluate_name: Option<String>,
cx: &mut Context<Self>,
) -> Task<Result<()>> {
let Some(client) = self
.session_by_id(session_id)
.and_then(|client| client.read(cx).adapter_client())
else {
return Task::ready(Err(anyhow!("Could not find client: {:?}", session_id)));
};
let supports_set_expression = self
.capabilities_by_id(session_id, cx)
.and_then(|caps| caps.supports_set_expression)
.unwrap_or_default();
cx.background_executor().spawn(async move {
if let Some(evaluate_name) = supports_set_expression.then(|| evaluate_name).flatten() {
client
.request::<SetExpression>(SetExpressionArguments {
expression: evaluate_name,
value,
frame_id: Some(stack_frame_id),
format: None,
})
.await?;
} else {
client
.request::<SetVariable>(SetVariableArguments {
variables_reference,
name,
value,
format: None,
})
.await?;
}
Ok(())
})
}
// .. get the client and what not
// let _ = client.modules(); // This can fire a request to a dap adapter or be a cheap getter.
// client.wait_for_request(request::Modules); // This ensures that the request that we've fired off runs to completions
// let returned_value = client.modules(); // this is a cheap getter.
pub fn shutdown_sessions(&mut self, cx: &mut Context<Self>) -> Task<()> {
let mut tasks = vec![];
for session_id in self.sessions.keys().cloned().collect::<Vec<_>>() {