Uncomment tests
This commit is contained in:
@@ -10,9 +10,6 @@ use crate::{
|
||||
use drag_and_drop::DragAndDrop;
|
||||
use futures::StreamExt;
|
||||
use gpui::{
|
||||
executor::Deterministic,
|
||||
geometry::{rect::RectF, vector::vec2f},
|
||||
platform::{WindowBounds, WindowOptions},
|
||||
serde_json::{self, json},
|
||||
TestAppContext,
|
||||
};
|
||||
@@ -42,8 +39,8 @@ use workspace::{
|
||||
fn test_edit_events(cx: &mut TestAppContext) {
|
||||
init_test(cx, |_| {});
|
||||
|
||||
let buffer = cx.add_model(|cx| {
|
||||
let mut buffer = language::Buffer::new(0, cx.model_id() as u64, "123456");
|
||||
let buffer = cx.build_model(|cx| {
|
||||
let mut buffer = language::Buffer::new(0, cx.entity_id().as_u64(), "123456");
|
||||
buffer.set_group_interval(Duration::from_secs(1));
|
||||
buffer
|
||||
});
|
||||
@@ -53,11 +50,8 @@ fn test_edit_events(cx: &mut TestAppContext) {
|
||||
.add_window({
|
||||
let events = events.clone();
|
||||
|cx| {
|
||||
cx.subscribe(&cx.handle(), move |_, _, event, _| {
|
||||
if matches!(
|
||||
event,
|
||||
Event::Edited | Event::BufferEdited | Event::DirtyChanged
|
||||
) {
|
||||
cx.subscribe(cx.view(), move |_, _, event, _| {
|
||||
if matches!(event, Event::Edited | Event::BufferEdited) {
|
||||
events.borrow_mut().push(("editor1", event.clone()));
|
||||
}
|
||||
})
|
||||
@@ -65,16 +59,14 @@ fn test_edit_events(cx: &mut TestAppContext) {
|
||||
Editor::for_buffer(buffer.clone(), None, cx)
|
||||
}
|
||||
})
|
||||
.root(cx);
|
||||
.root(cx)
|
||||
.unwrap();
|
||||
let editor2 = cx
|
||||
.add_window({
|
||||
let events = events.clone();
|
||||
|cx| {
|
||||
cx.subscribe(&cx.handle(), move |_, _, event, _| {
|
||||
if matches!(
|
||||
event,
|
||||
Event::Edited | Event::BufferEdited | Event::DirtyChanged
|
||||
) {
|
||||
cx.subscribe(cx.view(), move |_, _, event, _| {
|
||||
if matches!(event, Event::Edited | Event::BufferEdited) {
|
||||
events.borrow_mut().push(("editor2", event.clone()));
|
||||
}
|
||||
})
|
||||
@@ -82,7 +74,8 @@ fn test_edit_events(cx: &mut TestAppContext) {
|
||||
Editor::for_buffer(buffer.clone(), None, cx)
|
||||
}
|
||||
})
|
||||
.root(cx);
|
||||
.root(cx)
|
||||
.unwrap();
|
||||
assert_eq!(mem::take(&mut *events.borrow_mut()), []);
|
||||
|
||||
// Mutating editor 1 will emit an `Edited` event only for that editor.
|
||||
@@ -93,8 +86,6 @@ fn test_edit_events(cx: &mut TestAppContext) {
|
||||
("editor1", Event::Edited),
|
||||
("editor1", Event::BufferEdited),
|
||||
("editor2", Event::BufferEdited),
|
||||
("editor1", Event::DirtyChanged),
|
||||
("editor2", Event::DirtyChanged)
|
||||
]
|
||||
);
|
||||
|
||||
@@ -365,7 +356,7 @@ fn test_selection_with_mouse(cx: &mut TestAppContext) {
|
||||
);
|
||||
|
||||
editor.update(cx, |view, cx| {
|
||||
view.update_selection(DisplayPoint::new(3, 3), 0, Point<Pixels>::zero(), cx);
|
||||
view.update_selection(DisplayPoint::new(3, 3), 0, Point::<Pixels>::zero(), cx);
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
@@ -374,7 +365,7 @@ fn test_selection_with_mouse(cx: &mut TestAppContext) {
|
||||
);
|
||||
|
||||
editor.update(cx, |view, cx| {
|
||||
view.update_selection(DisplayPoint::new(1, 1), 0, Point<Pixels>::zero(), cx);
|
||||
view.update_selection(DisplayPoint::new(1, 1), 0, Point::<Pixels>::zero(), cx);
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
@@ -384,7 +375,7 @@ fn test_selection_with_mouse(cx: &mut TestAppContext) {
|
||||
|
||||
editor.update(cx, |view, cx| {
|
||||
view.end_selection(cx);
|
||||
view.update_selection(DisplayPoint::new(3, 3), 0, Point<Pixels>::zero(), cx);
|
||||
view.update_selection(DisplayPoint::new(3, 3), 0, Point::<Pixels>::zero(), cx);
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
@@ -394,7 +385,7 @@ fn test_selection_with_mouse(cx: &mut TestAppContext) {
|
||||
|
||||
editor.update(cx, |view, cx| {
|
||||
view.begin_selection(DisplayPoint::new(3, 3), true, 1, cx);
|
||||
view.update_selection(DisplayPoint::new(0, 0), 0, Point<Pixels>::zero(), cx);
|
||||
view.update_selection(DisplayPoint::new(0, 0), 0, Point::<Pixels>::zero(), cx);
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
@@ -435,7 +426,7 @@ fn test_canceling_pending_selection(cx: &mut TestAppContext) {
|
||||
});
|
||||
|
||||
view.update(cx, |view, cx| {
|
||||
view.update_selection(DisplayPoint::new(3, 3), 0, Point<Pixels>::zero(), cx);
|
||||
view.update_selection(DisplayPoint::new(3, 3), 0, Point::<Pixels>::zero(), cx);
|
||||
assert_eq!(
|
||||
view.selections.display_ranges(cx),
|
||||
[DisplayPoint::new(2, 2)..DisplayPoint::new(3, 3)]
|
||||
@@ -444,7 +435,7 @@ fn test_canceling_pending_selection(cx: &mut TestAppContext) {
|
||||
|
||||
view.update(cx, |view, cx| {
|
||||
view.cancel(&Cancel, cx);
|
||||
view.update_selection(DisplayPoint::new(1, 1), 0, Point<Pixels>::zero(), cx);
|
||||
view.update_selection(DisplayPoint::new(1, 1), 0, Point::<Pixels>::zero(), cx);
|
||||
assert_eq!(
|
||||
view.selections.display_ranges(cx),
|
||||
[DisplayPoint::new(2, 2)..DisplayPoint::new(3, 3)]
|
||||
@@ -589,12 +580,12 @@ async fn test_navigation_history(cx: &mut TestAppContext) {
|
||||
assert!(pop_history(&mut editor, cx).is_none());
|
||||
|
||||
// Set scroll position to check later
|
||||
editor.set_scroll_position(Point<Pixels>::new(5.5, 5.5), cx);
|
||||
editor.set_scroll_position(Point::<Pixels>::new(5.5, 5.5), cx);
|
||||
let original_scroll_position = editor.scroll_manager.anchor();
|
||||
|
||||
// Jump to the end of the document and adjust scroll
|
||||
editor.move_to_end(&MoveToEnd, cx);
|
||||
editor.set_scroll_position(Point<Pixels>::new(-2.5, -0.5), cx);
|
||||
editor.set_scroll_position(Point::<Pixels>::new(-2.5, -0.5), cx);
|
||||
assert_ne!(editor.scroll_manager.anchor(), original_scroll_position);
|
||||
|
||||
let nav_entry = pop_history(&mut editor, cx).unwrap();
|
||||
@@ -643,11 +634,11 @@ fn test_cancel(cx: &mut TestAppContext) {
|
||||
|
||||
view.update(cx, |view, cx| {
|
||||
view.begin_selection(DisplayPoint::new(3, 4), false, 1, cx);
|
||||
view.update_selection(DisplayPoint::new(1, 1), 0, Point<Pixels>::zero(), cx);
|
||||
view.update_selection(DisplayPoint::new(1, 1), 0, Point::<Pixels>::zero(), cx);
|
||||
view.end_selection(cx);
|
||||
|
||||
view.begin_selection(DisplayPoint::new(0, 1), true, 1, cx);
|
||||
view.update_selection(DisplayPoint::new(0, 3), 0, Point<Pixels>::zero(), cx);
|
||||
view.update_selection(DisplayPoint::new(0, 3), 0, Point::<Pixels>::zero(), cx);
|
||||
view.end_selection(cx);
|
||||
assert_eq!(
|
||||
view.selections.display_ranges(cx),
|
||||
|
||||
@@ -60,7 +60,7 @@ pub fn assert_text_with_selections(
|
||||
#[allow(dead_code)]
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub(crate) fn build_editor(buffer: Model<MultiBuffer>, cx: &mut ViewContext<Editor>) -> Editor {
|
||||
Editor::new(EditorMode::Full, buffer, None, None, cx)
|
||||
Editor::new(EditorMode::Full, buffer, None, /*None,*/ cx)
|
||||
}
|
||||
|
||||
pub(crate) fn build_editor_with_project(
|
||||
@@ -68,5 +68,5 @@ pub(crate) fn build_editor_with_project(
|
||||
buffer: Model<MultiBuffer>,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) -> Editor {
|
||||
Editor::new(EditorMode::Full, buffer, Some(project), None, cx)
|
||||
Editor::new(EditorMode::Full, buffer, Some(project), /*None,*/ cx)
|
||||
}
|
||||
|
||||
@@ -1,297 +1,297 @@
|
||||
// use std::{
|
||||
// borrow::Cow,
|
||||
// ops::{Deref, DerefMut, Range},
|
||||
// sync::Arc,
|
||||
// };
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
ops::{Deref, DerefMut, Range},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
// use anyhow::Result;
|
||||
use anyhow::Result;
|
||||
|
||||
// use crate::{Editor, ToPoint};
|
||||
// use collections::HashSet;
|
||||
// use futures::Future;
|
||||
// use gpui::{json, View, ViewContext};
|
||||
// use indoc::indoc;
|
||||
// use language::{point_to_lsp, FakeLspAdapter, Language, LanguageConfig, LanguageQueries};
|
||||
// use lsp::{notification, request};
|
||||
// use multi_buffer::ToPointUtf16;
|
||||
// use project::Project;
|
||||
// use smol::stream::StreamExt;
|
||||
// use workspace::{AppState, Workspace, WorkspaceHandle};
|
||||
use crate::{Editor, ToPoint};
|
||||
use collections::HashSet;
|
||||
use futures::Future;
|
||||
use gpui::{json, View, ViewContext};
|
||||
use indoc::indoc;
|
||||
use language::{point_to_lsp, FakeLspAdapter, Language, LanguageConfig, LanguageQueries};
|
||||
use lsp::{notification, request};
|
||||
use multi_buffer::ToPointUtf16;
|
||||
use project::Project;
|
||||
use smol::stream::StreamExt;
|
||||
use workspace::{AppState, Workspace, WorkspaceHandle};
|
||||
|
||||
// use super::editor_test_context::EditorTestContext;
|
||||
use super::editor_test_context::EditorTestContext;
|
||||
|
||||
// pub struct EditorLspTestContext<'a> {
|
||||
// pub cx: EditorTestContext<'a>,
|
||||
// pub lsp: lsp::FakeLanguageServer,
|
||||
// pub workspace: View<Workspace>,
|
||||
// pub buffer_lsp_url: lsp::Url,
|
||||
// }
|
||||
pub struct EditorLspTestContext<'a> {
|
||||
pub cx: EditorTestContext<'a>,
|
||||
pub lsp: lsp::FakeLanguageServer,
|
||||
pub workspace: View<Workspace>,
|
||||
pub buffer_lsp_url: lsp::Url,
|
||||
}
|
||||
|
||||
// impl<'a> EditorLspTestContext<'a> {
|
||||
// pub async fn new(
|
||||
// mut language: Language,
|
||||
// capabilities: lsp::ServerCapabilities,
|
||||
// cx: &'a mut gpui::TestAppContext,
|
||||
// ) -> EditorLspTestContext<'a> {
|
||||
// use json::json;
|
||||
impl<'a> EditorLspTestContext<'a> {
|
||||
pub async fn new(
|
||||
mut language: Language,
|
||||
capabilities: lsp::ServerCapabilities,
|
||||
cx: &'a mut gpui::TestAppContext,
|
||||
) -> EditorLspTestContext<'a> {
|
||||
use json::json;
|
||||
|
||||
// let app_state = cx.update(AppState::test);
|
||||
let app_state = cx.update(AppState::test);
|
||||
|
||||
// cx.update(|cx| {
|
||||
// language::init(cx);
|
||||
// crate::init(cx);
|
||||
// workspace::init(app_state.clone(), cx);
|
||||
// Project::init_settings(cx);
|
||||
// });
|
||||
cx.update(|cx| {
|
||||
language::init(cx);
|
||||
crate::init(cx);
|
||||
workspace::init(app_state.clone(), cx);
|
||||
Project::init_settings(cx);
|
||||
});
|
||||
|
||||
// let file_name = format!(
|
||||
// "file.{}",
|
||||
// language
|
||||
// .path_suffixes()
|
||||
// .first()
|
||||
// .expect("language must have a path suffix for EditorLspTestContext")
|
||||
// );
|
||||
let file_name = format!(
|
||||
"file.{}",
|
||||
language
|
||||
.path_suffixes()
|
||||
.first()
|
||||
.expect("language must have a path suffix for EditorLspTestContext")
|
||||
);
|
||||
|
||||
// let mut fake_servers = language
|
||||
// .set_fake_lsp_adapter(Arc::new(FakeLspAdapter {
|
||||
// capabilities,
|
||||
// ..Default::default()
|
||||
// }))
|
||||
// .await;
|
||||
let mut fake_servers = language
|
||||
.set_fake_lsp_adapter(Arc::new(FakeLspAdapter {
|
||||
capabilities,
|
||||
..Default::default()
|
||||
}))
|
||||
.await;
|
||||
|
||||
// let project = Project::test(app_state.fs.clone(), [], cx).await;
|
||||
// project.update(cx, |project, _| project.languages().add(Arc::new(language)));
|
||||
let project = Project::test(app_state.fs.clone(), [], cx).await;
|
||||
project.update(cx, |project, _| project.languages().add(Arc::new(language)));
|
||||
|
||||
// app_state
|
||||
// .fs
|
||||
// .as_fake()
|
||||
// .insert_tree("/root", json!({ "dir": { file_name.clone(): "" }}))
|
||||
// .await;
|
||||
app_state
|
||||
.fs
|
||||
.as_fake()
|
||||
.insert_tree("/root", json!({ "dir": { file_name.clone(): "" }}))
|
||||
.await;
|
||||
|
||||
// let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
// let workspace = window.root(cx);
|
||||
// project
|
||||
// .update(cx, |project, cx| {
|
||||
// project.find_or_create_local_worktree("/root", true, cx)
|
||||
// })
|
||||
// .await
|
||||
// .unwrap();
|
||||
// cx.read(|cx| workspace.read(cx).worktree_scans_complete(cx))
|
||||
// .await;
|
||||
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let workspace = window.root(cx);
|
||||
project
|
||||
.update(cx, |project, cx| {
|
||||
project.find_or_create_local_worktree("/root", true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
cx.read(|cx| workspace.read(cx).worktree_scans_complete(cx))
|
||||
.await;
|
||||
|
||||
// let file = cx.read(|cx| workspace.file_project_paths(cx)[0].clone());
|
||||
// let item = workspace
|
||||
// .update(cx, |workspace, cx| {
|
||||
// workspace.open_path(file, None, true, cx)
|
||||
// })
|
||||
// .await
|
||||
// .expect("Could not open test file");
|
||||
let file = cx.read(|cx| workspace.file_project_paths(cx)[0].clone());
|
||||
let item = workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.open_path(file, None, true, cx)
|
||||
})
|
||||
.await
|
||||
.expect("Could not open test file");
|
||||
|
||||
// let editor = cx.update(|cx| {
|
||||
// item.act_as::<Editor>(cx)
|
||||
// .expect("Opened test file wasn't an editor")
|
||||
// });
|
||||
// editor.update(cx, |_, cx| cx.focus_self());
|
||||
let editor = cx.update(|cx| {
|
||||
item.act_as::<Editor>(cx)
|
||||
.expect("Opened test file wasn't an editor")
|
||||
});
|
||||
editor.update(cx, |_, cx| cx.focus_self());
|
||||
|
||||
// let lsp = fake_servers.next().await.unwrap();
|
||||
let lsp = fake_servers.next().await.unwrap();
|
||||
|
||||
// Self {
|
||||
// cx: EditorTestContext {
|
||||
// cx,
|
||||
// window: window.into(),
|
||||
// editor,
|
||||
// },
|
||||
// lsp,
|
||||
// workspace,
|
||||
// buffer_lsp_url: lsp::Url::from_file_path(format!("/root/dir/{file_name}")).unwrap(),
|
||||
// }
|
||||
// }
|
||||
Self {
|
||||
cx: EditorTestContext {
|
||||
cx,
|
||||
window: window.into(),
|
||||
editor,
|
||||
},
|
||||
lsp,
|
||||
workspace,
|
||||
buffer_lsp_url: lsp::Url::from_file_path(format!("/root/dir/{file_name}")).unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
// pub async fn new_rust(
|
||||
// capabilities: lsp::ServerCapabilities,
|
||||
// cx: &'a mut gpui::TestAppContext,
|
||||
// ) -> EditorLspTestContext<'a> {
|
||||
// let language = Language::new(
|
||||
// LanguageConfig {
|
||||
// name: "Rust".into(),
|
||||
// path_suffixes: vec!["rs".to_string()],
|
||||
// ..Default::default()
|
||||
// },
|
||||
// Some(tree_sitter_rust::language()),
|
||||
// )
|
||||
// .with_queries(LanguageQueries {
|
||||
// indents: Some(Cow::from(indoc! {r#"
|
||||
// [
|
||||
// ((where_clause) _ @end)
|
||||
// (field_expression)
|
||||
// (call_expression)
|
||||
// (assignment_expression)
|
||||
// (let_declaration)
|
||||
// (let_chain)
|
||||
// (await_expression)
|
||||
// ] @indent
|
||||
pub async fn new_rust(
|
||||
capabilities: lsp::ServerCapabilities,
|
||||
cx: &'a mut gpui::TestAppContext,
|
||||
) -> EditorLspTestContext<'a> {
|
||||
let language = Language::new(
|
||||
LanguageConfig {
|
||||
name: "Rust".into(),
|
||||
path_suffixes: vec!["rs".to_string()],
|
||||
..Default::default()
|
||||
},
|
||||
Some(tree_sitter_rust::language()),
|
||||
)
|
||||
.with_queries(LanguageQueries {
|
||||
indents: Some(Cow::from(indoc! {r#"
|
||||
[
|
||||
((where_clause) _ @end)
|
||||
(field_expression)
|
||||
(call_expression)
|
||||
(assignment_expression)
|
||||
(let_declaration)
|
||||
(let_chain)
|
||||
(await_expression)
|
||||
] @indent
|
||||
|
||||
// (_ "[" "]" @end) @indent
|
||||
// (_ "<" ">" @end) @indent
|
||||
// (_ "{" "}" @end) @indent
|
||||
// (_ "(" ")" @end) @indent"#})),
|
||||
// brackets: Some(Cow::from(indoc! {r#"
|
||||
// ("(" @open ")" @close)
|
||||
// ("[" @open "]" @close)
|
||||
// ("{" @open "}" @close)
|
||||
// ("<" @open ">" @close)
|
||||
// ("\"" @open "\"" @close)
|
||||
// (closure_parameters "|" @open "|" @close)"#})),
|
||||
// ..Default::default()
|
||||
// })
|
||||
// .expect("Could not parse queries");
|
||||
(_ "[" "]" @end) @indent
|
||||
(_ "<" ">" @end) @indent
|
||||
(_ "{" "}" @end) @indent
|
||||
(_ "(" ")" @end) @indent"#})),
|
||||
brackets: Some(Cow::from(indoc! {r#"
|
||||
("(" @open ")" @close)
|
||||
("[" @open "]" @close)
|
||||
("{" @open "}" @close)
|
||||
("<" @open ">" @close)
|
||||
("\"" @open "\"" @close)
|
||||
(closure_parameters "|" @open "|" @close)"#})),
|
||||
..Default::default()
|
||||
})
|
||||
.expect("Could not parse queries");
|
||||
|
||||
// Self::new(language, capabilities, cx).await
|
||||
// }
|
||||
Self::new(language, capabilities, cx).await
|
||||
}
|
||||
|
||||
// pub async fn new_typescript(
|
||||
// capabilities: lsp::ServerCapabilities,
|
||||
// cx: &'a mut gpui::TestAppContext,
|
||||
// ) -> EditorLspTestContext<'a> {
|
||||
// let mut word_characters: HashSet<char> = Default::default();
|
||||
// word_characters.insert('$');
|
||||
// word_characters.insert('#');
|
||||
// let language = Language::new(
|
||||
// LanguageConfig {
|
||||
// name: "Typescript".into(),
|
||||
// path_suffixes: vec!["ts".to_string()],
|
||||
// brackets: language::BracketPairConfig {
|
||||
// pairs: vec![language::BracketPair {
|
||||
// start: "{".to_string(),
|
||||
// end: "}".to_string(),
|
||||
// close: true,
|
||||
// newline: true,
|
||||
// }],
|
||||
// disabled_scopes_by_bracket_ix: Default::default(),
|
||||
// },
|
||||
// word_characters,
|
||||
// ..Default::default()
|
||||
// },
|
||||
// Some(tree_sitter_typescript::language_typescript()),
|
||||
// )
|
||||
// .with_queries(LanguageQueries {
|
||||
// brackets: Some(Cow::from(indoc! {r#"
|
||||
// ("(" @open ")" @close)
|
||||
// ("[" @open "]" @close)
|
||||
// ("{" @open "}" @close)
|
||||
// ("<" @open ">" @close)
|
||||
// ("\"" @open "\"" @close)"#})),
|
||||
// indents: Some(Cow::from(indoc! {r#"
|
||||
// [
|
||||
// (call_expression)
|
||||
// (assignment_expression)
|
||||
// (member_expression)
|
||||
// (lexical_declaration)
|
||||
// (variable_declaration)
|
||||
// (assignment_expression)
|
||||
// (if_statement)
|
||||
// (for_statement)
|
||||
// ] @indent
|
||||
pub async fn new_typescript(
|
||||
capabilities: lsp::ServerCapabilities,
|
||||
cx: &'a mut gpui::TestAppContext,
|
||||
) -> EditorLspTestContext<'a> {
|
||||
let mut word_characters: HashSet<char> = Default::default();
|
||||
word_characters.insert('$');
|
||||
word_characters.insert('#');
|
||||
let language = Language::new(
|
||||
LanguageConfig {
|
||||
name: "Typescript".into(),
|
||||
path_suffixes: vec!["ts".to_string()],
|
||||
brackets: language::BracketPairConfig {
|
||||
pairs: vec![language::BracketPair {
|
||||
start: "{".to_string(),
|
||||
end: "}".to_string(),
|
||||
close: true,
|
||||
newline: true,
|
||||
}],
|
||||
disabled_scopes_by_bracket_ix: Default::default(),
|
||||
},
|
||||
word_characters,
|
||||
..Default::default()
|
||||
},
|
||||
Some(tree_sitter_typescript::language_typescript()),
|
||||
)
|
||||
.with_queries(LanguageQueries {
|
||||
brackets: Some(Cow::from(indoc! {r#"
|
||||
("(" @open ")" @close)
|
||||
("[" @open "]" @close)
|
||||
("{" @open "}" @close)
|
||||
("<" @open ">" @close)
|
||||
("\"" @open "\"" @close)"#})),
|
||||
indents: Some(Cow::from(indoc! {r#"
|
||||
[
|
||||
(call_expression)
|
||||
(assignment_expression)
|
||||
(member_expression)
|
||||
(lexical_declaration)
|
||||
(variable_declaration)
|
||||
(assignment_expression)
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
] @indent
|
||||
|
||||
// (_ "[" "]" @end) @indent
|
||||
// (_ "<" ">" @end) @indent
|
||||
// (_ "{" "}" @end) @indent
|
||||
// (_ "(" ")" @end) @indent
|
||||
// "#})),
|
||||
// ..Default::default()
|
||||
// })
|
||||
// .expect("Could not parse queries");
|
||||
(_ "[" "]" @end) @indent
|
||||
(_ "<" ">" @end) @indent
|
||||
(_ "{" "}" @end) @indent
|
||||
(_ "(" ")" @end) @indent
|
||||
"#})),
|
||||
..Default::default()
|
||||
})
|
||||
.expect("Could not parse queries");
|
||||
|
||||
// Self::new(language, capabilities, cx).await
|
||||
// }
|
||||
Self::new(language, capabilities, cx).await
|
||||
}
|
||||
|
||||
// // Constructs lsp range using a marked string with '[', ']' range delimiters
|
||||
// pub fn lsp_range(&mut self, marked_text: &str) -> lsp::Range {
|
||||
// let ranges = self.ranges(marked_text);
|
||||
// self.to_lsp_range(ranges[0].clone())
|
||||
// }
|
||||
// Constructs lsp range using a marked string with '[', ']' range delimiters
|
||||
pub fn lsp_range(&mut self, marked_text: &str) -> lsp::Range {
|
||||
let ranges = self.ranges(marked_text);
|
||||
self.to_lsp_range(ranges[0].clone())
|
||||
}
|
||||
|
||||
// pub fn to_lsp_range(&mut self, range: Range<usize>) -> lsp::Range {
|
||||
// let snapshot = self.update_editor(|editor, cx| editor.snapshot(cx));
|
||||
// let start_point = range.start.to_point(&snapshot.buffer_snapshot);
|
||||
// let end_point = range.end.to_point(&snapshot.buffer_snapshot);
|
||||
pub fn to_lsp_range(&mut self, range: Range<usize>) -> lsp::Range {
|
||||
let snapshot = self.update_editor(|editor, cx| editor.snapshot(cx));
|
||||
let start_point = range.start.to_point(&snapshot.buffer_snapshot);
|
||||
let end_point = range.end.to_point(&snapshot.buffer_snapshot);
|
||||
|
||||
// self.editor(|editor, cx| {
|
||||
// let buffer = editor.buffer().read(cx);
|
||||
// let start = point_to_lsp(
|
||||
// buffer
|
||||
// .point_to_buffer_offset(start_point, cx)
|
||||
// .unwrap()
|
||||
// .1
|
||||
// .to_point_utf16(&buffer.read(cx)),
|
||||
// );
|
||||
// let end = point_to_lsp(
|
||||
// buffer
|
||||
// .point_to_buffer_offset(end_point, cx)
|
||||
// .unwrap()
|
||||
// .1
|
||||
// .to_point_utf16(&buffer.read(cx)),
|
||||
// );
|
||||
self.editor(|editor, cx| {
|
||||
let buffer = editor.buffer().read(cx);
|
||||
let start = point_to_lsp(
|
||||
buffer
|
||||
.point_to_buffer_offset(start_point, cx)
|
||||
.unwrap()
|
||||
.1
|
||||
.to_point_utf16(&buffer.read(cx)),
|
||||
);
|
||||
let end = point_to_lsp(
|
||||
buffer
|
||||
.point_to_buffer_offset(end_point, cx)
|
||||
.unwrap()
|
||||
.1
|
||||
.to_point_utf16(&buffer.read(cx)),
|
||||
);
|
||||
|
||||
// lsp::Range { start, end }
|
||||
// })
|
||||
// }
|
||||
lsp::Range { start, end }
|
||||
})
|
||||
}
|
||||
|
||||
// pub fn to_lsp(&mut self, offset: usize) -> lsp::Position {
|
||||
// let snapshot = self.update_editor(|editor, cx| editor.snapshot(cx));
|
||||
// let point = offset.to_point(&snapshot.buffer_snapshot);
|
||||
pub fn to_lsp(&mut self, offset: usize) -> lsp::Position {
|
||||
let snapshot = self.update_editor(|editor, cx| editor.snapshot(cx));
|
||||
let point = offset.to_point(&snapshot.buffer_snapshot);
|
||||
|
||||
// self.editor(|editor, cx| {
|
||||
// let buffer = editor.buffer().read(cx);
|
||||
// point_to_lsp(
|
||||
// buffer
|
||||
// .point_to_buffer_offset(point, cx)
|
||||
// .unwrap()
|
||||
// .1
|
||||
// .to_point_utf16(&buffer.read(cx)),
|
||||
// )
|
||||
// })
|
||||
// }
|
||||
self.editor(|editor, cx| {
|
||||
let buffer = editor.buffer().read(cx);
|
||||
point_to_lsp(
|
||||
buffer
|
||||
.point_to_buffer_offset(point, cx)
|
||||
.unwrap()
|
||||
.1
|
||||
.to_point_utf16(&buffer.read(cx)),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// pub fn update_workspace<F, T>(&mut self, update: F) -> T
|
||||
// where
|
||||
// F: FnOnce(&mut Workspace, &mut ViewContext<Workspace>) -> T,
|
||||
// {
|
||||
// self.workspace.update(self.cx.cx, update)
|
||||
// }
|
||||
pub fn update_workspace<F, T>(&mut self, update: F) -> T
|
||||
where
|
||||
F: FnOnce(&mut Workspace, &mut ViewContext<Workspace>) -> T,
|
||||
{
|
||||
self.workspace.update(self.cx.cx, update)
|
||||
}
|
||||
|
||||
// pub fn handle_request<T, F, Fut>(
|
||||
// &self,
|
||||
// mut handler: F,
|
||||
// ) -> futures::channel::mpsc::UnboundedReceiver<()>
|
||||
// where
|
||||
// T: 'static + request::Request,
|
||||
// T::Params: 'static + Send,
|
||||
// F: 'static + Send + FnMut(lsp::Url, T::Params, gpui::AsyncAppContext) -> Fut,
|
||||
// Fut: 'static + Send + Future<Output = Result<T::Result>>,
|
||||
// {
|
||||
// let url = self.buffer_lsp_url.clone();
|
||||
// self.lsp.handle_request::<T, _, _>(move |params, cx| {
|
||||
// let url = url.clone();
|
||||
// handler(url, params, cx)
|
||||
// })
|
||||
// }
|
||||
pub fn handle_request<T, F, Fut>(
|
||||
&self,
|
||||
mut handler: F,
|
||||
) -> futures::channel::mpsc::UnboundedReceiver<()>
|
||||
where
|
||||
T: 'static + request::Request,
|
||||
T::Params: 'static + Send,
|
||||
F: 'static + Send + FnMut(lsp::Url, T::Params, gpui::AsyncAppContext) -> Fut,
|
||||
Fut: 'static + Send + Future<Output = Result<T::Result>>,
|
||||
{
|
||||
let url = self.buffer_lsp_url.clone();
|
||||
self.lsp.handle_request::<T, _, _>(move |params, cx| {
|
||||
let url = url.clone();
|
||||
handler(url, params, cx)
|
||||
})
|
||||
}
|
||||
|
||||
// pub fn notify<T: notification::Notification>(&self, params: T::Params) {
|
||||
// self.lsp.notify::<T>(params);
|
||||
// }
|
||||
// }
|
||||
pub fn notify<T: notification::Notification>(&self, params: T::Params) {
|
||||
self.lsp.notify::<T>(params);
|
||||
}
|
||||
}
|
||||
|
||||
// impl<'a> Deref for EditorLspTestContext<'a> {
|
||||
// type Target = EditorTestContext<'a>;
|
||||
impl<'a> Deref for EditorLspTestContext<'a> {
|
||||
type Target = EditorTestContext<'a>;
|
||||
|
||||
// fn deref(&self) -> &Self::Target {
|
||||
// &self.cx
|
||||
// }
|
||||
// }
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.cx
|
||||
}
|
||||
}
|
||||
|
||||
// impl<'a> DerefMut for EditorLspTestContext<'a> {
|
||||
// fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
// &mut self.cx
|
||||
// }
|
||||
// }
|
||||
impl<'a> DerefMut for EditorLspTestContext<'a> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.cx
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user