Rename NewlineStyle -> LineEnding
This commit is contained in:
parent
0ba12eab22
commit
9804c683c0
7 changed files with 58 additions and 58 deletions
|
@ -1,7 +1,7 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use fsevent::EventStream;
|
||||
use futures::{Stream, StreamExt};
|
||||
use language::NewlineStyle;
|
||||
use language::LineEnding;
|
||||
use smol::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use std::{
|
||||
io,
|
||||
|
@ -22,7 +22,7 @@ pub trait Fs: Send + Sync {
|
|||
async fn remove_file(&self, path: &Path, options: RemoveOptions) -> Result<()>;
|
||||
async fn open_sync(&self, path: &Path) -> Result<Box<dyn io::Read>>;
|
||||
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 is_file(&self, path: &Path) -> bool;
|
||||
async fn metadata(&self, path: &Path) -> Result<Option<Metadata>>;
|
||||
|
@ -170,7 +170,7 @@ impl Fs for RealFs {
|
|||
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 file = smol::fs::File::create(path).await?;
|
||||
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 line in chunk.split('\n') {
|
||||
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?;
|
||||
newline = true;
|
||||
|
@ -654,7 +654,7 @@ impl Fs for FakeFs {
|
|||
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;
|
||||
let mut state = self.state.lock().await;
|
||||
let path = normalize_path(path);
|
||||
|
@ -665,7 +665,7 @@ impl Fs for FakeFs {
|
|||
} else {
|
||||
entry.content = Some(
|
||||
text.chunks()
|
||||
.map(|chunk| chunk.replace('\n', newline_style.as_str()))
|
||||
.map(|chunk| chunk.replace('\n', line_ending.as_str()))
|
||||
.collect(),
|
||||
);
|
||||
entry.metadata.mtime = SystemTime::now();
|
||||
|
|
|
@ -4,7 +4,7 @@ use futures::{future, StreamExt};
|
|||
use gpui::{executor::Deterministic, test::subscribe};
|
||||
use language::{
|
||||
tree_sitter_rust, tree_sitter_typescript, Diagnostic, FakeLspAdapter, LanguageConfig,
|
||||
NewlineStyle, OffsetRangeExt, Point, ToPoint,
|
||||
LineEnding, OffsetRangeExt, Point, ToPoint,
|
||||
};
|
||||
use lsp::Url;
|
||||
use serde_json::json;
|
||||
|
@ -2429,7 +2429,7 @@ async fn test_buffer_file_changes_on_disk(cx: &mut gpui::TestAppContext) {
|
|||
fs.save(
|
||||
"/dir/the-file".as_ref(),
|
||||
&new_contents.into(),
|
||||
NewlineStyle::Unix,
|
||||
LineEnding::Unix,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -2464,7 +2464,7 @@ async fn test_buffer_file_changes_on_disk(cx: &mut gpui::TestAppContext) {
|
|||
fs.save(
|
||||
"/dir/the-file".as_ref(),
|
||||
&"\n\n\nAAAA\naaa\nBB\nbbbbb\n".into(),
|
||||
NewlineStyle::Unix,
|
||||
LineEnding::Unix,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -2501,11 +2501,11 @@ async fn test_buffer_line_endings(cx: &mut gpui::TestAppContext) {
|
|||
|
||||
buffer1.read_with(cx, |buffer, _| {
|
||||
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, _| {
|
||||
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
|
||||
|
@ -2513,14 +2513,14 @@ async fn test_buffer_line_endings(cx: &mut gpui::TestAppContext) {
|
|||
fs.save(
|
||||
"/dir/file1".as_ref(),
|
||||
&"aaa\nb\nc\n".into(),
|
||||
NewlineStyle::Windows,
|
||||
LineEnding::Windows,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
cx.foreground().run_until_parked();
|
||||
buffer1.read_with(cx, |buffer, _| {
|
||||
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.
|
||||
|
|
|
@ -24,7 +24,7 @@ use gpui::{
|
|||
};
|
||||
use language::{
|
||||
proto::{deserialize_version, serialize_version},
|
||||
Buffer, DiagnosticEntry, NewlineStyle, PointUtf16, Rope,
|
||||
Buffer, DiagnosticEntry, LineEnding, PointUtf16, Rope,
|
||||
};
|
||||
use lazy_static::lazy_static;
|
||||
use parking_lot::Mutex;
|
||||
|
@ -595,7 +595,7 @@ impl LocalWorktree {
|
|||
let text = buffer.as_rope().clone();
|
||||
let fingerprint = text.fingerprint();
|
||||
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();
|
||||
cx.as_mut().spawn(|mut cx| async move {
|
||||
let entry = save.await?;
|
||||
|
@ -636,10 +636,10 @@ impl LocalWorktree {
|
|||
&self,
|
||||
path: impl Into<Arc<Path>>,
|
||||
text: Rope,
|
||||
newline_style: NewlineStyle,
|
||||
line_ending: LineEnding,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
) -> 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(
|
||||
|
@ -755,7 +755,7 @@ impl LocalWorktree {
|
|||
fn write_entry_internal(
|
||||
&self,
|
||||
path: impl Into<Arc<Path>>,
|
||||
text_if_file: Option<(Rope, NewlineStyle)>,
|
||||
text_if_file: Option<(Rope, LineEnding)>,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
) -> Task<Result<Entry>> {
|
||||
let path = path.into();
|
||||
|
@ -764,8 +764,8 @@ impl LocalWorktree {
|
|||
let fs = self.fs.clone();
|
||||
let abs_path = abs_path.clone();
|
||||
async move {
|
||||
if let Some((text, newline_style)) = text_if_file {
|
||||
fs.save(&abs_path, &text, newline_style).await
|
||||
if let Some((text, line_ending)) = text_if_file {
|
||||
fs.save(&abs_path, &text, line_ending).await
|
||||
} else {
|
||||
fs.create_dir(&abs_path).await
|
||||
}
|
||||
|
@ -1654,7 +1654,7 @@ impl language::File for File {
|
|||
buffer_id: u64,
|
||||
text: Rope,
|
||||
version: clock::Global,
|
||||
newline_style: NewlineStyle,
|
||||
line_ending: LineEnding,
|
||||
cx: &mut MutableAppContext,
|
||||
) -> Task<Result<(clock::Global, String, SystemTime)>> {
|
||||
self.worktree.update(cx, |worktree, cx| match worktree {
|
||||
|
@ -1662,7 +1662,7 @@ impl language::File for File {
|
|||
let rpc = worktree.client.clone();
|
||||
let project_id = worktree.share.as_ref().map(|share| share.project_id);
|
||||
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 {
|
||||
let entry = save.await?;
|
||||
if let Some(project_id) = project_id {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue