Merge branch 'main' into disconnected-status
This commit is contained in:
@@ -940,9 +940,15 @@ impl Editor {
|
|||||||
_: &workspace::OpenNew,
|
_: &workspace::OpenNew,
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
) {
|
) {
|
||||||
let buffer = cx
|
let project = workspace.project();
|
||||||
.add_model(|cx| Buffer::new(0, "", cx).with_language(language::PLAIN_TEXT.clone(), cx));
|
if project.read(cx).is_remote() {
|
||||||
workspace.open_item(BufferItemHandle(buffer), cx);
|
cx.propagate_action();
|
||||||
|
} else if let Some(buffer) = project
|
||||||
|
.update(cx, |project, cx| project.create_buffer(cx))
|
||||||
|
.log_err()
|
||||||
|
{
|
||||||
|
workspace.open_item(BufferItemHandle(buffer), cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn replica_id(&self, cx: &AppContext) -> ReplicaId {
|
pub fn replica_id(&self, cx: &AppContext) -> ReplicaId {
|
||||||
|
|||||||
@@ -524,6 +524,8 @@ impl LanguageServer {
|
|||||||
ServerCapabilities {
|
ServerCapabilities {
|
||||||
document_highlight_provider: Some(OneOf::Left(true)),
|
document_highlight_provider: Some(OneOf::Left(true)),
|
||||||
code_action_provider: Some(CodeActionProviderCapability::Simple(true)),
|
code_action_provider: Some(CodeActionProviderCapability::Simple(true)),
|
||||||
|
document_formatting_provider: Some(OneOf::Left(true)),
|
||||||
|
document_range_formatting_provider: Some(OneOf::Left(true)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -715,6 +715,18 @@ impl Project {
|
|||||||
!self.is_local()
|
!self.is_local()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_buffer(&mut self, cx: &mut ModelContext<Self>) -> Result<ModelHandle<Buffer>> {
|
||||||
|
if self.is_remote() {
|
||||||
|
return Err(anyhow!("creating buffers as a guest is not supported yet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
let buffer = cx.add_model(|cx| {
|
||||||
|
Buffer::new(self.replica_id(), "", cx).with_language(language::PLAIN_TEXT.clone(), cx)
|
||||||
|
});
|
||||||
|
self.register_buffer(&buffer, None, cx)?;
|
||||||
|
Ok(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn open_buffer(
|
pub fn open_buffer(
|
||||||
&mut self,
|
&mut self,
|
||||||
path: impl Into<ProjectPath>,
|
path: impl Into<ProjectPath>,
|
||||||
@@ -1342,15 +1354,47 @@ impl Project {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (buffer, buffer_abs_path, lang_server) in local_buffers {
|
for (buffer, buffer_abs_path, lang_server) in local_buffers {
|
||||||
let lsp_edits = lang_server
|
let capabilities = if let Some(capabilities) = lang_server.capabilities().await {
|
||||||
.request::<lsp::request::Formatting>(lsp::DocumentFormattingParams {
|
capabilities
|
||||||
text_document: lsp::TextDocumentIdentifier::new(
|
} else {
|
||||||
lsp::Url::from_file_path(&buffer_abs_path).unwrap(),
|
continue;
|
||||||
),
|
};
|
||||||
options: Default::default(),
|
|
||||||
work_done_progress_params: Default::default(),
|
let text_document = lsp::TextDocumentIdentifier::new(
|
||||||
})
|
lsp::Url::from_file_path(&buffer_abs_path).unwrap(),
|
||||||
.await?;
|
);
|
||||||
|
let lsp_edits = if capabilities
|
||||||
|
.document_formatting_provider
|
||||||
|
.map_or(false, |provider| provider != lsp::OneOf::Left(false))
|
||||||
|
{
|
||||||
|
lang_server
|
||||||
|
.request::<lsp::request::Formatting>(lsp::DocumentFormattingParams {
|
||||||
|
text_document,
|
||||||
|
options: Default::default(),
|
||||||
|
work_done_progress_params: Default::default(),
|
||||||
|
})
|
||||||
|
.await?
|
||||||
|
} else if capabilities
|
||||||
|
.document_range_formatting_provider
|
||||||
|
.map_or(false, |provider| provider != lsp::OneOf::Left(false))
|
||||||
|
{
|
||||||
|
let buffer_start = lsp::Position::new(0, 0);
|
||||||
|
let buffer_end = buffer
|
||||||
|
.read_with(&cx, |buffer, _| buffer.max_point_utf16())
|
||||||
|
.to_lsp_position();
|
||||||
|
lang_server
|
||||||
|
.request::<lsp::request::RangeFormatting>(
|
||||||
|
lsp::DocumentRangeFormattingParams {
|
||||||
|
text_document,
|
||||||
|
range: lsp::Range::new(buffer_start, buffer_end),
|
||||||
|
options: Default::default(),
|
||||||
|
work_done_progress_params: Default::default(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(lsp_edits) = lsp_edits {
|
if let Some(lsp_edits) = lsp_edits {
|
||||||
let edits = buffer
|
let edits = buffer
|
||||||
@@ -4128,6 +4172,48 @@ mod tests {
|
|||||||
assert_eq!(new_text, buffer.read_with(cx, |buffer, _| buffer.text()));
|
assert_eq!(new_text, buffer.read_with(cx, |buffer, _| buffer.text()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_save_as(cx: &mut gpui::TestAppContext) {
|
||||||
|
let fs = FakeFs::new(cx.background());
|
||||||
|
fs.insert_tree("/dir", json!({})).await;
|
||||||
|
|
||||||
|
let project = Project::test(fs.clone(), cx);
|
||||||
|
let (worktree, _) = project
|
||||||
|
.update(cx, |project, cx| {
|
||||||
|
project.find_or_create_local_worktree("/dir", true, cx)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let worktree_id = worktree.read_with(cx, |worktree, _| worktree.id());
|
||||||
|
|
||||||
|
let buffer = project.update(cx, |project, cx| project.create_buffer(cx).unwrap());
|
||||||
|
buffer.update(cx, |buffer, cx| {
|
||||||
|
buffer.edit([0..0], "abc", cx);
|
||||||
|
assert!(buffer.is_dirty());
|
||||||
|
assert!(!buffer.has_conflict());
|
||||||
|
});
|
||||||
|
project
|
||||||
|
.update(cx, |project, cx| {
|
||||||
|
project.save_buffer_as(buffer.clone(), "/dir/file1".into(), cx)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(fs.load(Path::new("/dir/file1")).await.unwrap(), "abc");
|
||||||
|
buffer.read_with(cx, |buffer, cx| {
|
||||||
|
assert_eq!(buffer.file().unwrap().full_path(cx), Path::new("dir/file1"));
|
||||||
|
assert!(!buffer.is_dirty());
|
||||||
|
assert!(!buffer.has_conflict());
|
||||||
|
});
|
||||||
|
|
||||||
|
let opened_buffer = project
|
||||||
|
.update(cx, |project, cx| {
|
||||||
|
project.open_buffer((worktree_id, "file1"), cx)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(opened_buffer, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test(retries = 5)]
|
#[gpui::test(retries = 5)]
|
||||||
async fn test_rescan_and_remote_updates(cx: &mut gpui::TestAppContext) {
|
async fn test_rescan_and_remote_updates(cx: &mut gpui::TestAppContext) {
|
||||||
let dir = temp_tree(json!({
|
let dir = temp_tree(json!({
|
||||||
|
|||||||
@@ -126,6 +126,10 @@ impl Rope {
|
|||||||
self.chunks.extent(&())
|
self.chunks.extent(&())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn max_point_utf16(&self) -> PointUtf16 {
|
||||||
|
self.chunks.extent(&())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn cursor(&self, offset: usize) -> Cursor {
|
pub fn cursor(&self, offset: usize) -> Cursor {
|
||||||
Cursor::new(self, offset)
|
Cursor::new(self, offset)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1526,6 +1526,10 @@ impl BufferSnapshot {
|
|||||||
self.visible_text.max_point()
|
self.visible_text.max_point()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn max_point_utf16(&self) -> PointUtf16 {
|
||||||
|
self.visible_text.max_point_utf16()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn point_to_offset(&self, point: Point) -> usize {
|
pub fn point_to_offset(&self, point: Point) -> usize {
|
||||||
self.visible_text.point_to_offset(point)
|
self.visible_text.point_to_offset(point)
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -849,7 +849,7 @@ mod tests {
|
|||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref DEFAULT_THEME: parking_lot::Mutex<Option<Arc<Theme>>> = Default::default();
|
static ref DEFAULT_THEME: parking_lot::Mutex<Option<Arc<Theme>>> = Default::default();
|
||||||
static ref FONTS: Vec<Arc<Vec<u8>>> = vec![
|
static ref FONTS: Vec<Arc<Vec<u8>>> = vec![
|
||||||
Assets.load("fonts/zed-sans/zed-sans-regular.ttf").unwrap().to_vec().into()
|
Assets.load("fonts/zed-sans/zed-sans-extended.ttf").unwrap().to_vec().into()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user