Rename NewlineStyle -> LineEnding
This commit is contained in:
parent
0ba12eab22
commit
9804c683c0
7 changed files with 58 additions and 58 deletions
|
@ -22,7 +22,7 @@ use gpui::{
|
||||||
};
|
};
|
||||||
use language::{
|
use language::{
|
||||||
range_to_lsp, tree_sitter_rust, Diagnostic, DiagnosticEntry, FakeLspAdapter, Language,
|
range_to_lsp, tree_sitter_rust, Diagnostic, DiagnosticEntry, FakeLspAdapter, Language,
|
||||||
LanguageConfig, LanguageRegistry, NewlineStyle, OffsetRangeExt, Point, Rope,
|
LanguageConfig, LanguageRegistry, LineEnding, OffsetRangeExt, Point, Rope,
|
||||||
};
|
};
|
||||||
use lsp::{self, FakeLanguageServer};
|
use lsp::{self, FakeLanguageServer};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
@ -1266,7 +1266,7 @@ async fn test_buffer_reloading(cx_a: &mut TestAppContext, cx_b: &mut TestAppCont
|
||||||
.save(
|
.save(
|
||||||
"/dir/a.txt".as_ref(),
|
"/dir/a.txt".as_ref(),
|
||||||
&"new contents".into(),
|
&"new contents".into(),
|
||||||
NewlineStyle::Unix,
|
LineEnding::Unix,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1864,7 +1864,7 @@ async fn test_reloading_buffer_manually(cx_a: &mut TestAppContext, cx_b: &mut Te
|
||||||
.save(
|
.save(
|
||||||
"/a/a.rs".as_ref(),
|
"/a/a.rs".as_ref(),
|
||||||
&Rope::from("let seven = 7;"),
|
&Rope::from("let seven = 7;"),
|
||||||
NewlineStyle::Unix,
|
LineEnding::Unix,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -53,7 +53,7 @@ pub struct Buffer {
|
||||||
saved_version: clock::Global,
|
saved_version: clock::Global,
|
||||||
saved_version_fingerprint: String,
|
saved_version_fingerprint: String,
|
||||||
saved_mtime: SystemTime,
|
saved_mtime: SystemTime,
|
||||||
newline_style: NewlineStyle,
|
line_ending: LineEnding,
|
||||||
transaction_depth: usize,
|
transaction_depth: usize,
|
||||||
was_dirty_before_starting_transaction: Option<bool>,
|
was_dirty_before_starting_transaction: Option<bool>,
|
||||||
language: Option<Arc<Language>>,
|
language: Option<Arc<Language>>,
|
||||||
|
@ -99,7 +99,7 @@ pub enum IndentKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Debug, Clone, PartialEq, Eq)]
|
#[derive(Copy, Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum NewlineStyle {
|
pub enum LineEnding {
|
||||||
Unix,
|
Unix,
|
||||||
Windows,
|
Windows,
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ pub trait File: Send + Sync {
|
||||||
buffer_id: u64,
|
buffer_id: u64,
|
||||||
text: Rope,
|
text: Rope,
|
||||||
version: clock::Global,
|
version: clock::Global,
|
||||||
newline_style: NewlineStyle,
|
line_ending: LineEnding,
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
) -> Task<Result<(clock::Global, String, SystemTime)>>;
|
) -> Task<Result<(clock::Global, String, SystemTime)>>;
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ pub(crate) struct Diff {
|
||||||
base_version: clock::Global,
|
base_version: clock::Global,
|
||||||
new_text: Arc<str>,
|
new_text: Arc<str>,
|
||||||
changes: Vec<(ChangeTag, usize)>,
|
changes: Vec<(ChangeTag, usize)>,
|
||||||
newline_style: NewlineStyle,
|
line_ending: LineEnding,
|
||||||
start_offset: usize,
|
start_offset: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,11 +319,11 @@ impl Buffer {
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let history = History::new(base_text.into());
|
let history = History::new(base_text.into());
|
||||||
let newline_style = NewlineStyle::detect(&history.base_text);
|
let line_ending = LineEnding::detect(&history.base_text);
|
||||||
Self::build(
|
Self::build(
|
||||||
TextBuffer::new(replica_id, cx.model_id() as u64, history),
|
TextBuffer::new(replica_id, cx.model_id() as u64, history),
|
||||||
None,
|
None,
|
||||||
newline_style,
|
line_ending,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,11 +334,11 @@ impl Buffer {
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let history = History::new(base_text.into());
|
let history = History::new(base_text.into());
|
||||||
let newline_style = NewlineStyle::detect(&history.base_text);
|
let line_ending = LineEnding::detect(&history.base_text);
|
||||||
Self::build(
|
Self::build(
|
||||||
TextBuffer::new(replica_id, cx.model_id() as u64, history),
|
TextBuffer::new(replica_id, cx.model_id() as u64, history),
|
||||||
Some(file),
|
Some(file),
|
||||||
newline_style,
|
line_ending,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,9 +353,9 @@ impl Buffer {
|
||||||
message.id,
|
message.id,
|
||||||
History::new(Arc::from(message.base_text)),
|
History::new(Arc::from(message.base_text)),
|
||||||
);
|
);
|
||||||
let newline_style = proto::NewlineStyle::from_i32(message.newline_style)
|
let line_ending = proto::LineEnding::from_i32(message.line_ending)
|
||||||
.ok_or_else(|| anyhow!("missing newline_style"))?;
|
.ok_or_else(|| anyhow!("missing line_ending"))?;
|
||||||
let mut this = Self::build(buffer, file, NewlineStyle::from_proto(newline_style));
|
let mut this = Self::build(buffer, file, LineEnding::from_proto(line_ending));
|
||||||
let ops = message
|
let ops = message
|
||||||
.operations
|
.operations
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -420,7 +420,7 @@ impl Buffer {
|
||||||
diagnostics: proto::serialize_diagnostics(self.diagnostics.iter()),
|
diagnostics: proto::serialize_diagnostics(self.diagnostics.iter()),
|
||||||
diagnostics_timestamp: self.diagnostics_timestamp.value,
|
diagnostics_timestamp: self.diagnostics_timestamp.value,
|
||||||
completion_triggers: self.completion_triggers.clone(),
|
completion_triggers: self.completion_triggers.clone(),
|
||||||
newline_style: self.newline_style.to_proto() as i32,
|
line_ending: self.line_ending.to_proto() as i32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,7 +429,7 @@ impl Buffer {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(buffer: TextBuffer, file: Option<Arc<dyn File>>, newline_style: NewlineStyle) -> Self {
|
fn build(buffer: TextBuffer, file: Option<Arc<dyn File>>, line_ending: LineEnding) -> Self {
|
||||||
let saved_mtime;
|
let saved_mtime;
|
||||||
if let Some(file) = file.as_ref() {
|
if let Some(file) = file.as_ref() {
|
||||||
saved_mtime = file.mtime();
|
saved_mtime = file.mtime();
|
||||||
|
@ -445,7 +445,7 @@ impl Buffer {
|
||||||
was_dirty_before_starting_transaction: None,
|
was_dirty_before_starting_transaction: None,
|
||||||
text: buffer,
|
text: buffer,
|
||||||
file,
|
file,
|
||||||
newline_style,
|
line_ending,
|
||||||
syntax_tree: Mutex::new(None),
|
syntax_tree: Mutex::new(None),
|
||||||
parsing_in_background: false,
|
parsing_in_background: false,
|
||||||
parse_count: 0,
|
parse_count: 0,
|
||||||
|
@ -506,7 +506,7 @@ impl Buffer {
|
||||||
self.remote_id(),
|
self.remote_id(),
|
||||||
text,
|
text,
|
||||||
version,
|
version,
|
||||||
self.newline_style,
|
self.line_ending,
|
||||||
cx.as_mut(),
|
cx.as_mut(),
|
||||||
);
|
);
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
|
@ -974,7 +974,7 @@ impl Buffer {
|
||||||
let base_version = self.version();
|
let base_version = self.version();
|
||||||
cx.background().spawn(async move {
|
cx.background().spawn(async move {
|
||||||
let old_text = old_text.to_string();
|
let old_text = old_text.to_string();
|
||||||
let newline_style = NewlineStyle::detect(&new_text);
|
let line_ending = LineEnding::detect(&new_text);
|
||||||
let new_text = new_text.replace("\r\n", "\n").replace('\r', "\n");
|
let new_text = new_text.replace("\r\n", "\n").replace('\r', "\n");
|
||||||
let changes = TextDiff::from_lines(old_text.as_str(), new_text.as_str())
|
let changes = TextDiff::from_lines(old_text.as_str(), new_text.as_str())
|
||||||
.iter_all_changes()
|
.iter_all_changes()
|
||||||
|
@ -984,7 +984,7 @@ impl Buffer {
|
||||||
base_version,
|
base_version,
|
||||||
new_text: new_text.into(),
|
new_text: new_text.into(),
|
||||||
changes,
|
changes,
|
||||||
newline_style,
|
line_ending,
|
||||||
start_offset: 0,
|
start_offset: 0,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -998,7 +998,7 @@ impl Buffer {
|
||||||
if self.version == diff.base_version {
|
if self.version == diff.base_version {
|
||||||
self.finalize_last_transaction();
|
self.finalize_last_transaction();
|
||||||
self.start_transaction();
|
self.start_transaction();
|
||||||
self.newline_style = diff.newline_style;
|
self.line_ending = diff.line_ending;
|
||||||
let mut offset = diff.start_offset;
|
let mut offset = diff.start_offset;
|
||||||
for (tag, len) in diff.changes {
|
for (tag, len) in diff.changes {
|
||||||
let range = offset..(offset + len);
|
let range = offset..(offset + len);
|
||||||
|
@ -1514,8 +1514,8 @@ impl Buffer {
|
||||||
&self.completion_triggers
|
&self.completion_triggers
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn newline_style(&self) -> NewlineStyle {
|
pub fn line_ending(&self) -> LineEnding {
|
||||||
self.newline_style
|
self.line_ending
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2537,11 +2537,11 @@ impl std::ops::SubAssign for IndentSize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NewlineStyle {
|
impl LineEnding {
|
||||||
fn from_proto(style: proto::NewlineStyle) -> Self {
|
fn from_proto(style: proto::LineEnding) -> Self {
|
||||||
match style {
|
match style {
|
||||||
proto::NewlineStyle::Unix => Self::Unix,
|
proto::LineEnding::Unix => Self::Unix,
|
||||||
proto::NewlineStyle::Windows => Self::Windows,
|
proto::LineEnding::Windows => Self::Windows,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2560,20 +2560,20 @@ impl NewlineStyle {
|
||||||
|
|
||||||
pub fn as_str(self) -> &'static str {
|
pub fn as_str(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
NewlineStyle::Unix => "\n",
|
LineEnding::Unix => "\n",
|
||||||
NewlineStyle::Windows => "\r\n",
|
LineEnding::Windows => "\r\n",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_proto(self) -> proto::NewlineStyle {
|
fn to_proto(self) -> proto::LineEnding {
|
||||||
match self {
|
match self {
|
||||||
NewlineStyle::Unix => proto::NewlineStyle::Unix,
|
LineEnding::Unix => proto::LineEnding::Unix,
|
||||||
NewlineStyle::Windows => proto::NewlineStyle::Windows,
|
LineEnding::Windows => proto::LineEnding::Windows,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for NewlineStyle {
|
impl Default for LineEnding {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
return Self::Unix;
|
return Self::Unix;
|
||||||
|
|
|
@ -9,7 +9,7 @@ use rpc::proto;
|
||||||
use std::{ops::Range, sync::Arc};
|
use std::{ops::Range, sync::Arc};
|
||||||
use text::*;
|
use text::*;
|
||||||
|
|
||||||
pub use proto::{Buffer, BufferState, NewlineStyle, SelectionSet};
|
pub use proto::{Buffer, BufferState, LineEnding, SelectionSet};
|
||||||
|
|
||||||
pub fn serialize_operation(operation: &Operation) -> proto::Operation {
|
pub fn serialize_operation(operation: &Operation) -> proto::Operation {
|
||||||
proto::Operation {
|
proto::Operation {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use fsevent::EventStream;
|
use fsevent::EventStream;
|
||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
use language::NewlineStyle;
|
use language::LineEnding;
|
||||||
use smol::io::{AsyncReadExt, AsyncWriteExt};
|
use smol::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
use std::{
|
use std::{
|
||||||
io,
|
io,
|
||||||
|
@ -22,7 +22,7 @@ pub trait Fs: Send + Sync {
|
||||||
async fn remove_file(&self, path: &Path, options: RemoveOptions) -> Result<()>;
|
async fn remove_file(&self, path: &Path, options: RemoveOptions) -> Result<()>;
|
||||||
async fn open_sync(&self, path: &Path) -> Result<Box<dyn io::Read>>;
|
async fn open_sync(&self, path: &Path) -> Result<Box<dyn io::Read>>;
|
||||||
async fn load(&self, path: &Path) -> Result<String>;
|
async fn load(&self, path: &Path) -> Result<String>;
|
||||||
async fn save(&self, path: &Path, text: &Rope, newline_style: NewlineStyle) -> Result<()>;
|
async fn save(&self, path: &Path, text: &Rope, line_ending: LineEnding) -> Result<()>;
|
||||||
async fn canonicalize(&self, path: &Path) -> Result<PathBuf>;
|
async fn canonicalize(&self, path: &Path) -> Result<PathBuf>;
|
||||||
async fn is_file(&self, path: &Path) -> bool;
|
async fn is_file(&self, path: &Path) -> bool;
|
||||||
async fn metadata(&self, path: &Path) -> Result<Option<Metadata>>;
|
async fn metadata(&self, path: &Path) -> Result<Option<Metadata>>;
|
||||||
|
@ -170,7 +170,7 @@ impl Fs for RealFs {
|
||||||
Ok(text)
|
Ok(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, path: &Path, text: &Rope, newline_style: NewlineStyle) -> Result<()> {
|
async fn save(&self, path: &Path, text: &Rope, line_ending: LineEnding) -> Result<()> {
|
||||||
let buffer_size = text.summary().bytes.min(10 * 1024);
|
let buffer_size = text.summary().bytes.min(10 * 1024);
|
||||||
let file = smol::fs::File::create(path).await?;
|
let file = smol::fs::File::create(path).await?;
|
||||||
let mut writer = smol::io::BufWriter::with_capacity(buffer_size, file);
|
let mut writer = smol::io::BufWriter::with_capacity(buffer_size, file);
|
||||||
|
@ -178,7 +178,7 @@ impl Fs for RealFs {
|
||||||
for chunk in text.chunks() {
|
for chunk in text.chunks() {
|
||||||
for line in chunk.split('\n') {
|
for line in chunk.split('\n') {
|
||||||
if newline {
|
if newline {
|
||||||
writer.write_all(newline_style.as_str().as_bytes()).await?;
|
writer.write_all(line_ending.as_str().as_bytes()).await?;
|
||||||
}
|
}
|
||||||
writer.write_all(line.as_bytes()).await?;
|
writer.write_all(line.as_bytes()).await?;
|
||||||
newline = true;
|
newline = true;
|
||||||
|
@ -654,7 +654,7 @@ impl Fs for FakeFs {
|
||||||
Ok(text.clone())
|
Ok(text.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn save(&self, path: &Path, text: &Rope, newline_style: NewlineStyle) -> Result<()> {
|
async fn save(&self, path: &Path, text: &Rope, line_ending: LineEnding) -> Result<()> {
|
||||||
self.simulate_random_delay().await;
|
self.simulate_random_delay().await;
|
||||||
let mut state = self.state.lock().await;
|
let mut state = self.state.lock().await;
|
||||||
let path = normalize_path(path);
|
let path = normalize_path(path);
|
||||||
|
@ -665,7 +665,7 @@ impl Fs for FakeFs {
|
||||||
} else {
|
} else {
|
||||||
entry.content = Some(
|
entry.content = Some(
|
||||||
text.chunks()
|
text.chunks()
|
||||||
.map(|chunk| chunk.replace('\n', newline_style.as_str()))
|
.map(|chunk| chunk.replace('\n', line_ending.as_str()))
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
entry.metadata.mtime = SystemTime::now();
|
entry.metadata.mtime = SystemTime::now();
|
||||||
|
|
|
@ -4,7 +4,7 @@ use futures::{future, StreamExt};
|
||||||
use gpui::{executor::Deterministic, test::subscribe};
|
use gpui::{executor::Deterministic, test::subscribe};
|
||||||
use language::{
|
use language::{
|
||||||
tree_sitter_rust, tree_sitter_typescript, Diagnostic, FakeLspAdapter, LanguageConfig,
|
tree_sitter_rust, tree_sitter_typescript, Diagnostic, FakeLspAdapter, LanguageConfig,
|
||||||
NewlineStyle, OffsetRangeExt, Point, ToPoint,
|
LineEnding, OffsetRangeExt, Point, ToPoint,
|
||||||
};
|
};
|
||||||
use lsp::Url;
|
use lsp::Url;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
@ -2429,7 +2429,7 @@ async fn test_buffer_file_changes_on_disk(cx: &mut gpui::TestAppContext) {
|
||||||
fs.save(
|
fs.save(
|
||||||
"/dir/the-file".as_ref(),
|
"/dir/the-file".as_ref(),
|
||||||
&new_contents.into(),
|
&new_contents.into(),
|
||||||
NewlineStyle::Unix,
|
LineEnding::Unix,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -2464,7 +2464,7 @@ async fn test_buffer_file_changes_on_disk(cx: &mut gpui::TestAppContext) {
|
||||||
fs.save(
|
fs.save(
|
||||||
"/dir/the-file".as_ref(),
|
"/dir/the-file".as_ref(),
|
||||||
&"\n\n\nAAAA\naaa\nBB\nbbbbb\n".into(),
|
&"\n\n\nAAAA\naaa\nBB\nbbbbb\n".into(),
|
||||||
NewlineStyle::Unix,
|
LineEnding::Unix,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -2501,11 +2501,11 @@ async fn test_buffer_line_endings(cx: &mut gpui::TestAppContext) {
|
||||||
|
|
||||||
buffer1.read_with(cx, |buffer, _| {
|
buffer1.read_with(cx, |buffer, _| {
|
||||||
assert_eq!(buffer.text(), "a\nb\nc\n");
|
assert_eq!(buffer.text(), "a\nb\nc\n");
|
||||||
assert_eq!(buffer.newline_style(), NewlineStyle::Unix);
|
assert_eq!(buffer.line_ending(), LineEnding::Unix);
|
||||||
});
|
});
|
||||||
buffer2.read_with(cx, |buffer, _| {
|
buffer2.read_with(cx, |buffer, _| {
|
||||||
assert_eq!(buffer.text(), "one\ntwo\nthree\n");
|
assert_eq!(buffer.text(), "one\ntwo\nthree\n");
|
||||||
assert_eq!(buffer.newline_style(), NewlineStyle::Windows);
|
assert_eq!(buffer.line_ending(), LineEnding::Windows);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Change a file's line endings on disk from unix to windows. The buffer's
|
// Change a file's line endings on disk from unix to windows. The buffer's
|
||||||
|
@ -2513,14 +2513,14 @@ async fn test_buffer_line_endings(cx: &mut gpui::TestAppContext) {
|
||||||
fs.save(
|
fs.save(
|
||||||
"/dir/file1".as_ref(),
|
"/dir/file1".as_ref(),
|
||||||
&"aaa\nb\nc\n".into(),
|
&"aaa\nb\nc\n".into(),
|
||||||
NewlineStyle::Windows,
|
LineEnding::Windows,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
buffer1.read_with(cx, |buffer, _| {
|
buffer1.read_with(cx, |buffer, _| {
|
||||||
assert_eq!(buffer.text(), "aaa\nb\nc\n");
|
assert_eq!(buffer.text(), "aaa\nb\nc\n");
|
||||||
assert_eq!(buffer.newline_style(), NewlineStyle::Windows);
|
assert_eq!(buffer.line_ending(), LineEnding::Windows);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save a file with windows line endings. The file is written correctly.
|
// Save a file with windows line endings. The file is written correctly.
|
||||||
|
|
|
@ -24,7 +24,7 @@ use gpui::{
|
||||||
};
|
};
|
||||||
use language::{
|
use language::{
|
||||||
proto::{deserialize_version, serialize_version},
|
proto::{deserialize_version, serialize_version},
|
||||||
Buffer, DiagnosticEntry, NewlineStyle, PointUtf16, Rope,
|
Buffer, DiagnosticEntry, LineEnding, PointUtf16, Rope,
|
||||||
};
|
};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
@ -595,7 +595,7 @@ impl LocalWorktree {
|
||||||
let text = buffer.as_rope().clone();
|
let text = buffer.as_rope().clone();
|
||||||
let fingerprint = text.fingerprint();
|
let fingerprint = text.fingerprint();
|
||||||
let version = buffer.version();
|
let version = buffer.version();
|
||||||
let save = self.write_file(path, text, buffer.newline_style(), cx);
|
let save = self.write_file(path, text, buffer.line_ending(), cx);
|
||||||
let handle = cx.handle();
|
let handle = cx.handle();
|
||||||
cx.as_mut().spawn(|mut cx| async move {
|
cx.as_mut().spawn(|mut cx| async move {
|
||||||
let entry = save.await?;
|
let entry = save.await?;
|
||||||
|
@ -636,10 +636,10 @@ impl LocalWorktree {
|
||||||
&self,
|
&self,
|
||||||
path: impl Into<Arc<Path>>,
|
path: impl Into<Arc<Path>>,
|
||||||
text: Rope,
|
text: Rope,
|
||||||
newline_style: NewlineStyle,
|
line_ending: LineEnding,
|
||||||
cx: &mut ModelContext<Worktree>,
|
cx: &mut ModelContext<Worktree>,
|
||||||
) -> Task<Result<Entry>> {
|
) -> Task<Result<Entry>> {
|
||||||
self.write_entry_internal(path, Some((text, newline_style)), cx)
|
self.write_entry_internal(path, Some((text, line_ending)), cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_entry(
|
pub fn delete_entry(
|
||||||
|
@ -755,7 +755,7 @@ impl LocalWorktree {
|
||||||
fn write_entry_internal(
|
fn write_entry_internal(
|
||||||
&self,
|
&self,
|
||||||
path: impl Into<Arc<Path>>,
|
path: impl Into<Arc<Path>>,
|
||||||
text_if_file: Option<(Rope, NewlineStyle)>,
|
text_if_file: Option<(Rope, LineEnding)>,
|
||||||
cx: &mut ModelContext<Worktree>,
|
cx: &mut ModelContext<Worktree>,
|
||||||
) -> Task<Result<Entry>> {
|
) -> Task<Result<Entry>> {
|
||||||
let path = path.into();
|
let path = path.into();
|
||||||
|
@ -764,8 +764,8 @@ impl LocalWorktree {
|
||||||
let fs = self.fs.clone();
|
let fs = self.fs.clone();
|
||||||
let abs_path = abs_path.clone();
|
let abs_path = abs_path.clone();
|
||||||
async move {
|
async move {
|
||||||
if let Some((text, newline_style)) = text_if_file {
|
if let Some((text, line_ending)) = text_if_file {
|
||||||
fs.save(&abs_path, &text, newline_style).await
|
fs.save(&abs_path, &text, line_ending).await
|
||||||
} else {
|
} else {
|
||||||
fs.create_dir(&abs_path).await
|
fs.create_dir(&abs_path).await
|
||||||
}
|
}
|
||||||
|
@ -1654,7 +1654,7 @@ impl language::File for File {
|
||||||
buffer_id: u64,
|
buffer_id: u64,
|
||||||
text: Rope,
|
text: Rope,
|
||||||
version: clock::Global,
|
version: clock::Global,
|
||||||
newline_style: NewlineStyle,
|
line_ending: LineEnding,
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
) -> Task<Result<(clock::Global, String, SystemTime)>> {
|
) -> Task<Result<(clock::Global, String, SystemTime)>> {
|
||||||
self.worktree.update(cx, |worktree, cx| match worktree {
|
self.worktree.update(cx, |worktree, cx| match worktree {
|
||||||
|
@ -1662,7 +1662,7 @@ impl language::File for File {
|
||||||
let rpc = worktree.client.clone();
|
let rpc = worktree.client.clone();
|
||||||
let project_id = worktree.share.as_ref().map(|share| share.project_id);
|
let project_id = worktree.share.as_ref().map(|share| share.project_id);
|
||||||
let fingerprint = text.fingerprint();
|
let fingerprint = text.fingerprint();
|
||||||
let save = worktree.write_file(self.path.clone(), text, newline_style, cx);
|
let save = worktree.write_file(self.path.clone(), text, line_ending, cx);
|
||||||
cx.background().spawn(async move {
|
cx.background().spawn(async move {
|
||||||
let entry = save.await?;
|
let entry = save.await?;
|
||||||
if let Some(project_id) = project_id {
|
if let Some(project_id) = project_id {
|
||||||
|
|
|
@ -810,10 +810,10 @@ message BufferState {
|
||||||
repeated Diagnostic diagnostics = 6;
|
repeated Diagnostic diagnostics = 6;
|
||||||
uint32 diagnostics_timestamp = 7;
|
uint32 diagnostics_timestamp = 7;
|
||||||
repeated string completion_triggers = 8;
|
repeated string completion_triggers = 8;
|
||||||
NewlineStyle newline_style = 9;
|
LineEnding line_ending = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum NewlineStyle {
|
enum LineEnding {
|
||||||
Unix = 0;
|
Unix = 0;
|
||||||
Windows = 1;
|
Windows = 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue