Merge branch 'main' into notifications
This commit is contained in:
commit
522b76e452
4 changed files with 180 additions and 138 deletions
|
@ -4,7 +4,9 @@ use lazy_static::lazy_static;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::{env, io::Write, mem, path::PathBuf, sync::Arc, time::Duration};
|
use std::{env, io::Write, mem, path::PathBuf, sync::Arc, time::Duration};
|
||||||
use sysinfo::{Pid, PidExt, ProcessExt, System, SystemExt};
|
use sysinfo::{
|
||||||
|
CpuRefreshKind, Pid, PidExt, ProcessExt, ProcessRefreshKind, RefreshKind, System, SystemExt,
|
||||||
|
};
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
use util::http::HttpClient;
|
use util::http::HttpClient;
|
||||||
use util::{channel::ReleaseChannel, TryFutureExt};
|
use util::{channel::ReleaseChannel, TryFutureExt};
|
||||||
|
@ -166,8 +168,16 @@ impl Telemetry {
|
||||||
|
|
||||||
let this = self.clone();
|
let this = self.clone();
|
||||||
cx.spawn(|mut cx| async move {
|
cx.spawn(|mut cx| async move {
|
||||||
let mut system = System::new_all();
|
// Avoiding calling `System::new_all()`, as there have been crashes related to it
|
||||||
system.refresh_all();
|
let refresh_kind = RefreshKind::new()
|
||||||
|
.with_memory() // For memory usage
|
||||||
|
.with_processes(ProcessRefreshKind::everything()) // For process usage
|
||||||
|
.with_cpu(CpuRefreshKind::everything()); // For core count
|
||||||
|
|
||||||
|
let mut system = System::new_with_specifics(refresh_kind);
|
||||||
|
|
||||||
|
// Avoiding calling `refresh_all()`, just update what we need
|
||||||
|
system.refresh_specifics(refresh_kind);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Waiting some amount of time before the first query is important to get a reasonable value
|
// Waiting some amount of time before the first query is important to get a reasonable value
|
||||||
|
@ -175,8 +185,7 @@ impl Telemetry {
|
||||||
const DURATION_BETWEEN_SYSTEM_EVENTS: Duration = Duration::from_secs(60);
|
const DURATION_BETWEEN_SYSTEM_EVENTS: Duration = Duration::from_secs(60);
|
||||||
smol::Timer::after(DURATION_BETWEEN_SYSTEM_EVENTS).await;
|
smol::Timer::after(DURATION_BETWEEN_SYSTEM_EVENTS).await;
|
||||||
|
|
||||||
system.refresh_memory();
|
system.refresh_specifics(refresh_kind);
|
||||||
system.refresh_processes();
|
|
||||||
|
|
||||||
let current_process = Pid::from_u32(std::process::id());
|
let current_process = Pid::from_u32(std::process::id());
|
||||||
let Some(process) = system.processes().get(¤t_process) else {
|
let Some(process) = system.processes().get(¤t_process) else {
|
||||||
|
|
|
@ -4158,7 +4158,10 @@ impl Editor {
|
||||||
if self.has_active_copilot_suggestion(cx) {
|
if self.has_active_copilot_suggestion(cx) {
|
||||||
self.cycle_copilot_suggestions(Direction::Next, cx);
|
self.cycle_copilot_suggestions(Direction::Next, cx);
|
||||||
} else {
|
} else {
|
||||||
self.refresh_copilot_suggestions(false, cx);
|
let is_copilot_disabled = self.refresh_copilot_suggestions(false, cx).is_none();
|
||||||
|
if is_copilot_disabled {
|
||||||
|
cx.propagate_action();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4170,7 +4173,10 @@ impl Editor {
|
||||||
if self.has_active_copilot_suggestion(cx) {
|
if self.has_active_copilot_suggestion(cx) {
|
||||||
self.cycle_copilot_suggestions(Direction::Prev, cx);
|
self.cycle_copilot_suggestions(Direction::Prev, cx);
|
||||||
} else {
|
} else {
|
||||||
self.refresh_copilot_suggestions(false, cx);
|
let is_copilot_disabled = self.refresh_copilot_suggestions(false, cx).is_none();
|
||||||
|
if is_copilot_disabled {
|
||||||
|
cx.propagate_action();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -498,9 +498,19 @@ impl MultiBuffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop(cursor);
|
||||||
|
drop(snapshot);
|
||||||
|
// Non-generic part of edit, hoisted out to avoid blowing up LLVM IR.
|
||||||
|
fn tail(
|
||||||
|
this: &mut MultiBuffer,
|
||||||
|
buffer_edits: HashMap<u64, Vec<BufferEdit>>,
|
||||||
|
autoindent_mode: Option<AutoindentMode>,
|
||||||
|
edited_excerpt_ids: Vec<ExcerptId>,
|
||||||
|
cx: &mut ModelContext<MultiBuffer>,
|
||||||
|
) {
|
||||||
for (buffer_id, mut edits) in buffer_edits {
|
for (buffer_id, mut edits) in buffer_edits {
|
||||||
edits.sort_unstable_by_key(|edit| edit.range.start);
|
edits.sort_unstable_by_key(|edit| edit.range.start);
|
||||||
self.buffers.borrow()[&buffer_id]
|
this.buffers.borrow()[&buffer_id]
|
||||||
.buffer
|
.buffer
|
||||||
.update(cx, |buffer, cx| {
|
.update(cx, |buffer, cx| {
|
||||||
let mut edits = edits.into_iter().peekable();
|
let mut edits = edits.into_iter().peekable();
|
||||||
|
@ -533,12 +543,14 @@ impl MultiBuffer {
|
||||||
if is_insertion {
|
if is_insertion {
|
||||||
original_indent_columns.push(original_indent_column);
|
original_indent_columns.push(original_indent_column);
|
||||||
insertions.push((
|
insertions.push((
|
||||||
buffer.anchor_before(range.start)..buffer.anchor_before(range.end),
|
buffer.anchor_before(range.start)
|
||||||
|
..buffer.anchor_before(range.end),
|
||||||
new_text.clone(),
|
new_text.clone(),
|
||||||
));
|
));
|
||||||
} else if !range.is_empty() {
|
} else if !range.is_empty() {
|
||||||
deletions.push((
|
deletions.push((
|
||||||
buffer.anchor_before(range.start)..buffer.anchor_before(range.end),
|
buffer.anchor_before(range.start)
|
||||||
|
..buffer.anchor_before(range.end),
|
||||||
empty_str.clone(),
|
empty_str.clone(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -570,6 +582,8 @@ impl MultiBuffer {
|
||||||
ids: edited_excerpt_ids,
|
ids: edited_excerpt_ids,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
tail(self, buffer_edits, autoindent_mode, edited_excerpt_ids, cx);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn start_transaction(&mut self, cx: &mut ModelContext<Self>) -> Option<TransactionId> {
|
pub fn start_transaction(&mut self, cx: &mut ModelContext<Self>) -> Option<TransactionId> {
|
||||||
self.start_transaction_at(Instant::now(), cx)
|
self.start_transaction_at(Instant::now(), cx)
|
||||||
|
|
|
@ -1448,12 +1448,19 @@ impl Buffer {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.start_transaction();
|
// Non-generic part hoisted out to reduce LLVM IR size.
|
||||||
self.pending_autoindent.take();
|
fn tail(
|
||||||
|
this: &mut Buffer,
|
||||||
|
edits: Vec<(Range<usize>, Arc<str>)>,
|
||||||
|
autoindent_mode: Option<AutoindentMode>,
|
||||||
|
cx: &mut ModelContext<Buffer>,
|
||||||
|
) -> Option<clock::Lamport> {
|
||||||
|
this.start_transaction();
|
||||||
|
this.pending_autoindent.take();
|
||||||
let autoindent_request = autoindent_mode
|
let autoindent_request = autoindent_mode
|
||||||
.and_then(|mode| self.language.as_ref().map(|_| (self.snapshot(), mode)));
|
.and_then(|mode| this.language.as_ref().map(|_| (this.snapshot(), mode)));
|
||||||
|
|
||||||
let edit_operation = self.text.edit(edits.iter().cloned());
|
let edit_operation = this.text.edit(edits.iter().cloned());
|
||||||
let edit_id = edit_operation.timestamp();
|
let edit_id = edit_operation.timestamp();
|
||||||
|
|
||||||
if let Some((before_edit, mode)) = autoindent_request {
|
if let Some((before_edit, mode)) = autoindent_request {
|
||||||
|
@ -1466,7 +1473,8 @@ impl Buffer {
|
||||||
let new_text_length = new_text.len();
|
let new_text_length = new_text.len();
|
||||||
let old_start = range.start.to_point(&before_edit);
|
let old_start = range.start.to_point(&before_edit);
|
||||||
let new_start = (delta + range.start as isize) as usize;
|
let new_start = (delta + range.start as isize) as usize;
|
||||||
delta += new_text_length as isize - (range.end as isize - range.start as isize);
|
delta +=
|
||||||
|
new_text_length as isize - (range.end as isize - range.start as isize);
|
||||||
|
|
||||||
let mut range_of_insertion_to_indent = 0..new_text_length;
|
let mut range_of_insertion_to_indent = 0..new_text_length;
|
||||||
let mut first_line_is_new = false;
|
let mut first_line_is_new = false;
|
||||||
|
@ -1475,7 +1483,8 @@ impl Buffer {
|
||||||
// When inserting an entire line at the beginning of an existing line,
|
// When inserting an entire line at the beginning of an existing line,
|
||||||
// treat the insertion as new.
|
// treat the insertion as new.
|
||||||
if new_text.contains('\n')
|
if new_text.contains('\n')
|
||||||
&& old_start.column <= before_edit.indent_size_for_line(old_start.row).len
|
&& old_start.column
|
||||||
|
<= before_edit.indent_size_for_line(old_start.row).len
|
||||||
{
|
{
|
||||||
first_line_is_new = true;
|
first_line_is_new = true;
|
||||||
}
|
}
|
||||||
|
@ -1492,13 +1501,14 @@ impl Buffer {
|
||||||
original_indent_columns,
|
original_indent_columns,
|
||||||
} = &mode
|
} = &mode
|
||||||
{
|
{
|
||||||
original_indent_column =
|
original_indent_column = Some(
|
||||||
Some(original_indent_columns.get(ix).copied().unwrap_or_else(|| {
|
original_indent_columns.get(ix).copied().unwrap_or_else(|| {
|
||||||
indent_size_for_text(
|
indent_size_for_text(
|
||||||
new_text[range_of_insertion_to_indent.clone()].chars(),
|
new_text[range_of_insertion_to_indent.clone()].chars(),
|
||||||
)
|
)
|
||||||
.len
|
.len
|
||||||
}));
|
}),
|
||||||
|
);
|
||||||
if new_text[range_of_insertion_to_indent.clone()].ends_with('\n') {
|
if new_text[range_of_insertion_to_indent.clone()].ends_with('\n') {
|
||||||
range_of_insertion_to_indent.end -= 1;
|
range_of_insertion_to_indent.end -= 1;
|
||||||
}
|
}
|
||||||
|
@ -1508,23 +1518,26 @@ impl Buffer {
|
||||||
first_line_is_new,
|
first_line_is_new,
|
||||||
original_indent_column,
|
original_indent_column,
|
||||||
indent_size: before_edit.language_indent_size_at(range.start, cx),
|
indent_size: before_edit.language_indent_size_at(range.start, cx),
|
||||||
range: self.anchor_before(new_start + range_of_insertion_to_indent.start)
|
range: this
|
||||||
..self.anchor_after(new_start + range_of_insertion_to_indent.end),
|
.anchor_before(new_start + range_of_insertion_to_indent.start)
|
||||||
|
..this.anchor_after(new_start + range_of_insertion_to_indent.end),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
self.autoindent_requests.push(Arc::new(AutoindentRequest {
|
this.autoindent_requests.push(Arc::new(AutoindentRequest {
|
||||||
before_edit,
|
before_edit,
|
||||||
entries,
|
entries,
|
||||||
is_block_mode: matches!(mode, AutoindentMode::Block { .. }),
|
is_block_mode: matches!(mode, AutoindentMode::Block { .. }),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.end_transaction(cx);
|
this.end_transaction(cx);
|
||||||
self.send_operation(Operation::Buffer(edit_operation), cx);
|
this.send_operation(Operation::Buffer(edit_operation), cx);
|
||||||
Some(edit_id)
|
Some(edit_id)
|
||||||
}
|
}
|
||||||
|
tail(self, edits, autoindent_mode, cx)
|
||||||
|
}
|
||||||
|
|
||||||
fn did_edit(
|
fn did_edit(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue