Merge branch 'main' into new-signup-flow
This commit is contained in:
commit
5d0b6a3da7
26 changed files with 1030 additions and 366 deletions
|
@ -39,7 +39,7 @@ use postage::watch;
|
|||
use rand::prelude::*;
|
||||
use search::SearchQuery;
|
||||
use serde::Serialize;
|
||||
use settings::Settings;
|
||||
use settings::{FormatOnSave, Formatter, Settings};
|
||||
use sha2::{Digest, Sha256};
|
||||
use similar::{ChangeTag, TextDiff};
|
||||
use std::{
|
||||
|
@ -363,6 +363,22 @@ impl ProjectEntryId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum FormatTrigger {
|
||||
Save,
|
||||
Manual,
|
||||
}
|
||||
|
||||
impl FormatTrigger {
|
||||
fn from_proto(value: i32) -> FormatTrigger {
|
||||
match value {
|
||||
0 => FormatTrigger::Save,
|
||||
1 => FormatTrigger::Manual,
|
||||
_ => FormatTrigger::Save,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Project {
|
||||
pub fn init(client: &Arc<Client>) {
|
||||
client.add_model_message_handler(Self::handle_request_join_project);
|
||||
|
@ -3046,6 +3062,7 @@ impl Project {
|
|||
&self,
|
||||
buffers: HashSet<ModelHandle<Buffer>>,
|
||||
push_to_history: bool,
|
||||
trigger: FormatTrigger,
|
||||
cx: &mut ModelContext<Project>,
|
||||
) -> Task<Result<ProjectTransaction>> {
|
||||
let mut local_buffers = Vec::new();
|
||||
|
@ -3075,6 +3092,7 @@ impl Project {
|
|||
let response = client
|
||||
.request(proto::FormatBuffers {
|
||||
project_id,
|
||||
trigger: trigger as i32,
|
||||
buffer_ids: remote_buffers
|
||||
.iter()
|
||||
.map(|buffer| buffer.read_with(&cx, |buffer, _| buffer.remote_id()))
|
||||
|
@ -3091,18 +3109,21 @@ impl Project {
|
|||
}
|
||||
|
||||
for (buffer, buffer_abs_path, language_server) in local_buffers {
|
||||
let (format_on_save, tab_size) = buffer.read_with(&cx, |buffer, cx| {
|
||||
let (format_on_save, formatter, tab_size) = buffer.read_with(&cx, |buffer, cx| {
|
||||
let settings = cx.global::<Settings>();
|
||||
let language_name = buffer.language().map(|language| language.name());
|
||||
(
|
||||
settings.format_on_save(language_name.as_deref()),
|
||||
settings.formatter(language_name.as_deref()),
|
||||
settings.tab_size(language_name.as_deref()),
|
||||
)
|
||||
});
|
||||
|
||||
let transaction = match format_on_save {
|
||||
settings::FormatOnSave::Off => continue,
|
||||
settings::FormatOnSave::LanguageServer => Self::format_via_lsp(
|
||||
let transaction = match (formatter, format_on_save) {
|
||||
(_, FormatOnSave::Off) if trigger == FormatTrigger::Save => continue,
|
||||
|
||||
(Formatter::LanguageServer, FormatOnSave::On | FormatOnSave::Off)
|
||||
| (_, FormatOnSave::LanguageServer) => Self::format_via_lsp(
|
||||
&this,
|
||||
&buffer,
|
||||
&buffer_abs_path,
|
||||
|
@ -3112,7 +3133,12 @@ impl Project {
|
|||
)
|
||||
.await
|
||||
.context("failed to format via language server")?,
|
||||
settings::FormatOnSave::External { command, arguments } => {
|
||||
|
||||
(
|
||||
Formatter::External { command, arguments },
|
||||
FormatOnSave::On | FormatOnSave::Off,
|
||||
)
|
||||
| (_, FormatOnSave::External { command, arguments }) => {
|
||||
Self::format_via_external_command(
|
||||
&buffer,
|
||||
&buffer_abs_path,
|
||||
|
@ -5295,7 +5321,8 @@ impl Project {
|
|||
.ok_or_else(|| anyhow!("unknown buffer id {}", buffer_id))?,
|
||||
);
|
||||
}
|
||||
Ok::<_, anyhow::Error>(this.format(buffers, false, cx))
|
||||
let trigger = FormatTrigger::from_proto(envelope.payload.trigger);
|
||||
Ok::<_, anyhow::Error>(this.format(buffers, false, trigger, cx))
|
||||
})?;
|
||||
|
||||
let project_transaction = format.await?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue