Use single languages::{rust_lang, markdown_lang} in tests across the codebase (#44282)
This allows referencing proper queries and keeping the tests up-to-date. Release Notes: - N/A
This commit is contained in:
@@ -6,6 +6,7 @@ use futures::FutureExt as _;
|
||||
use gpui::{App, AppContext as _, BorrowAppContext, Entity};
|
||||
use gpui::{HighlightStyle, TestAppContext};
|
||||
use indoc::indoc;
|
||||
use pretty_assertions::assert_eq;
|
||||
use proto::deserialize_operation;
|
||||
use rand::prelude::*;
|
||||
use regex::RegexBuilder;
|
||||
@@ -46,8 +47,7 @@ fn test_line_endings(cx: &mut gpui::App) {
|
||||
init_settings(cx, |_| {});
|
||||
|
||||
cx.new(|cx| {
|
||||
let mut buffer =
|
||||
Buffer::local("one\r\ntwo\rthree", cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let mut buffer = Buffer::local("one\r\ntwo\rthree", cx).with_language(rust_lang(), cx);
|
||||
assert_eq!(buffer.text(), "one\ntwo\nthree");
|
||||
assert_eq!(buffer.line_ending(), LineEnding::Windows);
|
||||
|
||||
@@ -608,7 +608,7 @@ async fn test_normalize_whitespace(cx: &mut gpui::TestAppContext) {
|
||||
#[gpui::test]
|
||||
async fn test_reparse(cx: &mut gpui::TestAppContext) {
|
||||
let text = "fn a() {}";
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(rust_lang(), cx));
|
||||
|
||||
// Wait for the initial text to parse
|
||||
cx.executor().run_until_parked();
|
||||
@@ -735,7 +735,7 @@ async fn test_reparse(cx: &mut gpui::TestAppContext) {
|
||||
#[gpui::test]
|
||||
async fn test_resetting_language(cx: &mut gpui::TestAppContext) {
|
||||
let buffer = cx.new(|cx| {
|
||||
let mut buffer = Buffer::local("{}", cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let mut buffer = Buffer::local("{}", cx).with_language(rust_lang(), cx);
|
||||
buffer.set_sync_parse_timeout(Duration::ZERO);
|
||||
buffer
|
||||
});
|
||||
@@ -783,11 +783,11 @@ async fn test_outline(cx: &mut gpui::TestAppContext) {
|
||||
"#
|
||||
.unindent();
|
||||
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(rust_lang(), cx));
|
||||
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
|
||||
let outline = snapshot.outline(None);
|
||||
|
||||
pretty_assertions::assert_eq!(
|
||||
assert_eq!(
|
||||
outline
|
||||
.items
|
||||
.iter()
|
||||
@@ -819,7 +819,7 @@ async fn test_outline(cx: &mut gpui::TestAppContext) {
|
||||
("LoggedIn", 2, Some("person: Person, time: Instant,".to_string())),
|
||||
("person", 3, None),
|
||||
("time", 3, None),
|
||||
("impl Eq for Person", 0, None),
|
||||
("impl Eq for Person", 0, Some("".to_string())),
|
||||
(
|
||||
"impl Drop for Person",
|
||||
0,
|
||||
@@ -890,7 +890,7 @@ async fn test_outline_nodes_with_newlines(cx: &mut gpui::TestAppContext) {
|
||||
"#
|
||||
.unindent();
|
||||
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(rust_lang(), cx));
|
||||
let outline = buffer.update(cx, |buffer, _| buffer.snapshot().outline(None));
|
||||
|
||||
assert_eq!(
|
||||
@@ -970,7 +970,7 @@ fn test_outline_annotations(cx: &mut App) {
|
||||
"#
|
||||
.unindent();
|
||||
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(rust_lang(), cx));
|
||||
let outline = buffer.update(cx, |buffer, _| buffer.snapshot().outline(None));
|
||||
|
||||
assert_eq!(
|
||||
@@ -1018,7 +1018,7 @@ async fn test_symbols_containing(cx: &mut gpui::TestAppContext) {
|
||||
"#
|
||||
.unindent();
|
||||
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(rust_lang(), cx));
|
||||
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
|
||||
|
||||
// point is at the start of an item
|
||||
@@ -1093,7 +1093,7 @@ async fn test_symbols_containing(cx: &mut gpui::TestAppContext) {
|
||||
"
|
||||
.unindent(),
|
||||
);
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(rust_lang(), cx));
|
||||
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
|
||||
|
||||
// note, it would be nice to actually return the method test in this
|
||||
@@ -1112,8 +1112,7 @@ fn test_text_objects(cx: &mut App) {
|
||||
false,
|
||||
);
|
||||
|
||||
let buffer =
|
||||
cx.new(|cx| Buffer::local(text.clone(), cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text.clone(), cx).with_language(rust_lang(), cx));
|
||||
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
|
||||
|
||||
let matches = snapshot
|
||||
@@ -1130,6 +1129,14 @@ fn test_text_objects(cx: &mut App) {
|
||||
"fn say() -> u8 { return /* hi */ 1 }",
|
||||
TextObject::AroundFunction
|
||||
),
|
||||
(
|
||||
"fn say() -> u8 { return /* hi */ 1 }",
|
||||
TextObject::InsideClass
|
||||
),
|
||||
(
|
||||
"impl Hello {\n fn say() -> u8 { return /* hi */ 1 }\n}",
|
||||
TextObject::AroundClass
|
||||
),
|
||||
],
|
||||
)
|
||||
}
|
||||
@@ -1260,7 +1267,12 @@ fn test_enclosing_bracket_ranges(cx: &mut App) {
|
||||
#[gpui::test]
|
||||
fn test_enclosing_bracket_ranges_where_brackets_are_not_outermost_children(cx: &mut App) {
|
||||
let mut assert = |selection_text, bracket_pair_texts| {
|
||||
assert_bracket_pairs(selection_text, bracket_pair_texts, javascript_lang(), cx)
|
||||
assert_bracket_pairs(
|
||||
selection_text,
|
||||
bracket_pair_texts,
|
||||
Arc::new(javascript_lang()),
|
||||
cx,
|
||||
)
|
||||
};
|
||||
|
||||
assert(
|
||||
@@ -1293,7 +1305,7 @@ fn test_enclosing_bracket_ranges_where_brackets_are_not_outermost_children(cx: &
|
||||
fn test_range_for_syntax_ancestor(cx: &mut App) {
|
||||
cx.new(|cx| {
|
||||
let text = "fn a() { b(|c| {}) }";
|
||||
let buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let buffer = Buffer::local(text, cx).with_language(rust_lang(), cx);
|
||||
let snapshot = buffer.snapshot();
|
||||
|
||||
assert_eq!(
|
||||
@@ -1345,7 +1357,7 @@ fn test_autoindent_with_soft_tabs(cx: &mut App) {
|
||||
|
||||
cx.new(|cx| {
|
||||
let text = "fn a() {}";
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let mut buffer = Buffer::local(text, cx).with_language(rust_lang(), cx);
|
||||
|
||||
buffer.edit([(8..8, "\n\n")], Some(AutoindentMode::EachLine), cx);
|
||||
assert_eq!(buffer.text(), "fn a() {\n \n}");
|
||||
@@ -1387,7 +1399,7 @@ fn test_autoindent_with_hard_tabs(cx: &mut App) {
|
||||
|
||||
cx.new(|cx| {
|
||||
let text = "fn a() {}";
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let mut buffer = Buffer::local(text, cx).with_language(rust_lang(), cx);
|
||||
|
||||
buffer.edit([(8..8, "\n\n")], Some(AutoindentMode::EachLine), cx);
|
||||
assert_eq!(buffer.text(), "fn a() {\n\t\n}");
|
||||
@@ -1436,7 +1448,7 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut App)
|
||||
.unindent(),
|
||||
cx,
|
||||
)
|
||||
.with_language(Arc::new(rust_lang()), cx);
|
||||
.with_language(rust_lang(), cx);
|
||||
|
||||
// Lines 2 and 3 don't match the indentation suggestion. When editing these lines,
|
||||
// their indentation is not adjusted.
|
||||
@@ -1577,7 +1589,7 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut App)
|
||||
.unindent(),
|
||||
cx,
|
||||
)
|
||||
.with_language(Arc::new(rust_lang()), cx);
|
||||
.with_language(rust_lang(), cx);
|
||||
|
||||
// Insert a closing brace. It is outdented.
|
||||
buffer.edit_via_marked_text(
|
||||
@@ -1640,7 +1652,7 @@ fn test_autoindent_does_not_adjust_lines_within_newly_created_errors(cx: &mut Ap
|
||||
.unindent(),
|
||||
cx,
|
||||
)
|
||||
.with_language(Arc::new(rust_lang()), cx);
|
||||
.with_language(rust_lang(), cx);
|
||||
|
||||
// Regression test: line does not get outdented due to syntax error
|
||||
buffer.edit_via_marked_text(
|
||||
@@ -1699,7 +1711,7 @@ fn test_autoindent_adjusts_lines_when_only_text_changes(cx: &mut App) {
|
||||
.unindent(),
|
||||
cx,
|
||||
)
|
||||
.with_language(Arc::new(rust_lang()), cx);
|
||||
.with_language(rust_lang(), cx);
|
||||
|
||||
buffer.edit_via_marked_text(
|
||||
&"
|
||||
@@ -1749,7 +1761,7 @@ fn test_autoindent_with_edit_at_end_of_buffer(cx: &mut App) {
|
||||
|
||||
cx.new(|cx| {
|
||||
let text = "a\nb";
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let mut buffer = Buffer::local(text, cx).with_language(rust_lang(), cx);
|
||||
buffer.edit(
|
||||
[(0..1, "\n"), (2..3, "\n")],
|
||||
Some(AutoindentMode::EachLine),
|
||||
@@ -1775,7 +1787,7 @@ fn test_autoindent_multi_line_insertion(cx: &mut App) {
|
||||
"
|
||||
.unindent();
|
||||
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let mut buffer = Buffer::local(text, cx).with_language(rust_lang(), cx);
|
||||
buffer.edit(
|
||||
[(Point::new(3, 0)..Point::new(3, 0), "e(\n f()\n);\n")],
|
||||
Some(AutoindentMode::EachLine),
|
||||
@@ -1812,7 +1824,7 @@ fn test_autoindent_block_mode(cx: &mut App) {
|
||||
}
|
||||
"#
|
||||
.unindent();
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let mut buffer = Buffer::local(text, cx).with_language(rust_lang(), cx);
|
||||
|
||||
// When this text was copied, both of the quotation marks were at the same
|
||||
// indent level, but the indentation of the first line was not included in
|
||||
@@ -1895,7 +1907,7 @@ fn test_autoindent_block_mode_with_newline(cx: &mut App) {
|
||||
}
|
||||
"#
|
||||
.unindent();
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let mut buffer = Buffer::local(text, cx).with_language(rust_lang(), cx);
|
||||
|
||||
// First line contains just '\n', it's indentation is stored in "original_indent_columns"
|
||||
let original_indent_columns = vec![Some(4)];
|
||||
@@ -1947,7 +1959,7 @@ fn test_autoindent_block_mode_without_original_indent_columns(cx: &mut App) {
|
||||
}
|
||||
"#
|
||||
.unindent();
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let mut buffer = Buffer::local(text, cx).with_language(rust_lang(), cx);
|
||||
|
||||
// The original indent columns are not known, so this text is
|
||||
// auto-indented in a block as if the first line was copied in
|
||||
@@ -2038,7 +2050,7 @@ fn test_autoindent_block_mode_multiple_adjacent_ranges(cx: &mut App) {
|
||||
false,
|
||||
);
|
||||
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let mut buffer = Buffer::local(text, cx).with_language(rust_lang(), cx);
|
||||
|
||||
buffer.edit(
|
||||
[
|
||||
@@ -2052,7 +2064,7 @@ fn test_autoindent_block_mode_multiple_adjacent_ranges(cx: &mut App) {
|
||||
cx,
|
||||
);
|
||||
|
||||
pretty_assertions::assert_eq!(
|
||||
assert_eq!(
|
||||
buffer.text(),
|
||||
"
|
||||
mod numbers {
|
||||
@@ -2246,7 +2258,7 @@ async fn test_async_autoindents_preserve_preview(cx: &mut TestAppContext) {
|
||||
// Then we request that a preview tab be preserved for the new version, even though it's edited.
|
||||
let buffer = cx.new(|cx| {
|
||||
let text = "fn a() {}";
|
||||
let mut buffer = Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let mut buffer = Buffer::local(text, cx).with_language(rust_lang(), cx);
|
||||
|
||||
// This causes autoindent to be async.
|
||||
buffer.set_sync_parse_timeout(Duration::ZERO);
|
||||
@@ -2704,7 +2716,7 @@ fn test_language_at_with_hidden_languages(cx: &mut App) {
|
||||
.unindent();
|
||||
|
||||
let language_registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
|
||||
language_registry.add(Arc::new(markdown_lang()));
|
||||
language_registry.add(markdown_lang());
|
||||
language_registry.add(Arc::new(markdown_inline_lang()));
|
||||
|
||||
let mut buffer = Buffer::local(text, cx);
|
||||
@@ -2746,9 +2758,9 @@ fn test_language_at_for_markdown_code_block(cx: &mut App) {
|
||||
.unindent();
|
||||
|
||||
let language_registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
|
||||
language_registry.add(Arc::new(markdown_lang()));
|
||||
language_registry.add(markdown_lang());
|
||||
language_registry.add(Arc::new(markdown_inline_lang()));
|
||||
language_registry.add(Arc::new(rust_lang()));
|
||||
language_registry.add(rust_lang());
|
||||
|
||||
let mut buffer = Buffer::local(text, cx);
|
||||
buffer.set_language_registry(language_registry.clone());
|
||||
@@ -3145,7 +3157,7 @@ async fn test_preview_edits(cx: &mut TestAppContext) {
|
||||
cx: &mut TestAppContext,
|
||||
assert_fn: impl Fn(HighlightedText),
|
||||
) {
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(rust_lang(), cx));
|
||||
let edits = buffer.read_with(cx, |buffer, _| {
|
||||
edits
|
||||
.into_iter()
|
||||
@@ -3556,7 +3568,7 @@ let word=öäpple.bar你 Öäpple word2-öÄpPlE-Pizza-word ÖÄPPLE word
|
||||
"#;
|
||||
|
||||
let buffer = cx.new(|cx| {
|
||||
let buffer = Buffer::local(contents, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
let buffer = Buffer::local(contents, cx).with_language(rust_lang(), cx);
|
||||
assert_eq!(buffer.text(), contents);
|
||||
buffer.check_invariants();
|
||||
buffer
|
||||
@@ -3781,78 +3793,6 @@ fn erb_lang() -> Language {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn rust_lang() -> Language {
|
||||
Language::new(
|
||||
LanguageConfig {
|
||||
name: "Rust".into(),
|
||||
matcher: LanguageMatcher {
|
||||
path_suffixes: vec!["rs".to_string()],
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
Some(tree_sitter_rust::LANGUAGE.into()),
|
||||
)
|
||||
.with_indents_query(
|
||||
r#"
|
||||
(call_expression) @indent
|
||||
(field_expression) @indent
|
||||
(_ "(" ")" @end) @indent
|
||||
(_ "{" "}" @end) @indent
|
||||
"#,
|
||||
)
|
||||
.unwrap()
|
||||
.with_brackets_query(
|
||||
r#"
|
||||
("{" @open "}" @close)
|
||||
"#,
|
||||
)
|
||||
.unwrap()
|
||||
.with_text_object_query(
|
||||
r#"
|
||||
(function_item
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}" )) @function.around
|
||||
|
||||
(line_comment)+ @comment.around
|
||||
|
||||
(block_comment) @comment.around
|
||||
"#,
|
||||
)
|
||||
.unwrap()
|
||||
.with_outline_query(
|
||||
r#"
|
||||
(line_comment) @annotation
|
||||
|
||||
(struct_item
|
||||
"struct" @context
|
||||
name: (_) @name) @item
|
||||
(enum_item
|
||||
"enum" @context
|
||||
name: (_) @name) @item
|
||||
(enum_variant
|
||||
name: (_) @name) @item
|
||||
(field_declaration
|
||||
name: (_) @name) @item
|
||||
(impl_item
|
||||
"impl" @context
|
||||
trait: (_)? @name
|
||||
"for"? @context
|
||||
type: (_) @name
|
||||
body: (_ "{" (_)* "}")) @item
|
||||
(function_item
|
||||
"fn" @context
|
||||
name: (_) @name) @item
|
||||
(mod_item
|
||||
"mod" @context
|
||||
name: (_) @name) @item
|
||||
"#,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn json_lang() -> Language {
|
||||
Language::new(
|
||||
LanguageConfig {
|
||||
@@ -3890,32 +3830,6 @@ fn javascript_lang() -> Language {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn markdown_lang() -> Language {
|
||||
Language::new(
|
||||
LanguageConfig {
|
||||
name: "Markdown".into(),
|
||||
matcher: LanguageMatcher {
|
||||
path_suffixes: vec!["md".into()],
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
Some(tree_sitter_md::LANGUAGE.into()),
|
||||
)
|
||||
.with_injection_query(
|
||||
r#"
|
||||
(fenced_code_block
|
||||
(info_string
|
||||
(language) @injection.language)
|
||||
(code_fence_content) @injection.content)
|
||||
|
||||
((inline) @injection.content
|
||||
(#set! injection.language "markdown-inline"))
|
||||
"#,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn markdown_inline_lang() -> Language {
|
||||
Language::new(
|
||||
LanguageConfig {
|
||||
@@ -3942,12 +3856,11 @@ fn get_tree_sexp(buffer: &Entity<Buffer>, cx: &mut gpui::TestAppContext) -> Stri
|
||||
fn assert_bracket_pairs(
|
||||
selection_text: &'static str,
|
||||
bracket_pair_texts: Vec<&'static str>,
|
||||
language: Language,
|
||||
language: Arc<Language>,
|
||||
cx: &mut App,
|
||||
) {
|
||||
let (expected_text, selection_ranges) = marked_text_ranges(selection_text, false);
|
||||
let buffer =
|
||||
cx.new(|cx| Buffer::local(expected_text.clone(), cx).with_language(Arc::new(language), cx));
|
||||
let buffer = cx.new(|cx| Buffer::local(expected_text.clone(), cx).with_language(language, cx));
|
||||
let buffer = buffer.update(cx, |buffer, _cx| buffer.snapshot());
|
||||
|
||||
let selection_range = selection_ranges[0].clone();
|
||||
|
||||
@@ -2656,7 +2656,28 @@ pub fn rust_lang() -> Arc<Language> {
|
||||
text_objects: Some(Cow::from(include_str!(
|
||||
"../../languages/src/rust/textobjects.scm"
|
||||
))),
|
||||
..LanguageQueries::default()
|
||||
highlights: Some(Cow::from(include_str!(
|
||||
"../../languages/src/rust/highlights.scm"
|
||||
))),
|
||||
embedding: Some(Cow::from(include_str!(
|
||||
"../../languages/src/rust/embedding.scm"
|
||||
))),
|
||||
injections: Some(Cow::from(include_str!(
|
||||
"../../languages/src/rust/injections.scm"
|
||||
))),
|
||||
overrides: Some(Cow::from(include_str!(
|
||||
"../../languages/src/rust/overrides.scm"
|
||||
))),
|
||||
redactions: None,
|
||||
runnables: Some(Cow::from(include_str!(
|
||||
"../../languages/src/rust/runnables.scm"
|
||||
))),
|
||||
debugger: Some(Cow::from(include_str!(
|
||||
"../../languages/src/rust/debugger.scm"
|
||||
))),
|
||||
imports: Some(Cow::from(include_str!(
|
||||
"../../languages/src/rust/imports.scm"
|
||||
))),
|
||||
})
|
||||
.expect("Could not parse queries");
|
||||
Arc::new(language)
|
||||
@@ -2685,6 +2706,15 @@ pub fn markdown_lang() -> Arc<Language> {
|
||||
injections: Some(Cow::from(include_str!(
|
||||
"../../languages/src/markdown/injections.scm"
|
||||
))),
|
||||
highlights: Some(Cow::from(include_str!(
|
||||
"../../languages/src/markdown/highlights.scm"
|
||||
))),
|
||||
indents: Some(Cow::from(include_str!(
|
||||
"../../languages/src/markdown/indents.scm"
|
||||
))),
|
||||
outline: Some(Cow::from(include_str!(
|
||||
"../../languages/src/markdown/outline.scm"
|
||||
))),
|
||||
..LanguageQueries::default()
|
||||
})
|
||||
.expect("Could not parse markdown queries");
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::*;
|
||||
use crate::{
|
||||
LanguageConfig, LanguageMatcher,
|
||||
buffer_tests::{markdown_inline_lang, markdown_lang},
|
||||
LanguageConfig, LanguageMatcher, buffer_tests::markdown_inline_lang, markdown_lang, rust_lang,
|
||||
};
|
||||
use gpui::App;
|
||||
use pretty_assertions::assert_eq;
|
||||
use rand::rngs::StdRng;
|
||||
use std::{env, ops::Range, sync::Arc};
|
||||
use text::{Buffer, BufferId, ReplicaId};
|
||||
@@ -84,7 +84,7 @@ fn test_splice_included_ranges() {
|
||||
#[gpui::test]
|
||||
fn test_syntax_map_layers_for_range(cx: &mut App) {
|
||||
let registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
|
||||
let language = Arc::new(rust_lang());
|
||||
let language = rust_lang();
|
||||
registry.add(language.clone());
|
||||
|
||||
let mut buffer = Buffer::new(
|
||||
@@ -181,11 +181,11 @@ fn test_syntax_map_layers_for_range(cx: &mut App) {
|
||||
#[gpui::test]
|
||||
fn test_dynamic_language_injection(cx: &mut App) {
|
||||
let registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
|
||||
let markdown = Arc::new(markdown_lang());
|
||||
let markdown = markdown_lang();
|
||||
let markdown_inline = Arc::new(markdown_inline_lang());
|
||||
registry.add(markdown.clone());
|
||||
registry.add(markdown_inline.clone());
|
||||
registry.add(Arc::new(rust_lang()));
|
||||
registry.add(rust_lang());
|
||||
registry.add(Arc::new(ruby_lang()));
|
||||
|
||||
let mut buffer = Buffer::new(
|
||||
@@ -291,7 +291,7 @@ fn test_typing_multiple_new_injections(cx: &mut App) {
|
||||
assert_capture_ranges(
|
||||
&syntax_map,
|
||||
&buffer,
|
||||
&["field"],
|
||||
&["property"],
|
||||
"fn a() { test_macro!(b.«c»(vec![d.«e»])) }",
|
||||
);
|
||||
}
|
||||
@@ -329,16 +329,16 @@ fn test_pasting_new_injection_line_between_others(cx: &mut App) {
|
||||
assert_capture_ranges(
|
||||
&syntax_map,
|
||||
&buffer,
|
||||
&["struct"],
|
||||
&["type"],
|
||||
"
|
||||
fn a() {
|
||||
b!(«B {}»);
|
||||
c!(«C {}»);
|
||||
d!(«D {}»);
|
||||
h!(«H {}»);
|
||||
e!(«E {}»);
|
||||
f!(«F {}»);
|
||||
g!(«G {}»);
|
||||
b!(«B» {});
|
||||
c!(«C» {});
|
||||
d!(«D» {});
|
||||
h!(«H» {});
|
||||
e!(«E» {});
|
||||
f!(«F» {});
|
||||
g!(«G» {});
|
||||
}
|
||||
",
|
||||
);
|
||||
@@ -376,7 +376,7 @@ fn test_joining_injections_with_child_injections(cx: &mut App) {
|
||||
assert_capture_ranges(
|
||||
&syntax_map,
|
||||
&buffer,
|
||||
&["field"],
|
||||
&["property"],
|
||||
"
|
||||
fn a() {
|
||||
b!(
|
||||
@@ -900,7 +900,7 @@ fn test_random_syntax_map_edits_rust_macros(rng: StdRng, cx: &mut App) {
|
||||
.repeat(2);
|
||||
|
||||
let registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
|
||||
let language = Arc::new(rust_lang());
|
||||
let language = rust_lang();
|
||||
registry.add(language.clone());
|
||||
|
||||
test_random_edits(text, registry, language, rng);
|
||||
@@ -1147,11 +1147,11 @@ fn test_edit_sequence(language_name: &str, steps: &[&str], cx: &mut App) -> (Buf
|
||||
let registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
|
||||
registry.add(Arc::new(elixir_lang()));
|
||||
registry.add(Arc::new(heex_lang()));
|
||||
registry.add(Arc::new(rust_lang()));
|
||||
registry.add(rust_lang());
|
||||
registry.add(Arc::new(ruby_lang()));
|
||||
registry.add(Arc::new(html_lang()));
|
||||
registry.add(Arc::new(erb_lang()));
|
||||
registry.add(Arc::new(markdown_lang()));
|
||||
registry.add(markdown_lang());
|
||||
registry.add(Arc::new(markdown_inline_lang()));
|
||||
|
||||
let language = registry
|
||||
@@ -1287,35 +1287,6 @@ fn erb_lang() -> Language {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn rust_lang() -> Language {
|
||||
Language::new(
|
||||
LanguageConfig {
|
||||
name: "Rust".into(),
|
||||
matcher: LanguageMatcher {
|
||||
path_suffixes: vec!["rs".to_string()],
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
Some(tree_sitter_rust::LANGUAGE.into()),
|
||||
)
|
||||
.with_highlights_query(
|
||||
r#"
|
||||
(field_identifier) @field
|
||||
(struct_expression) @struct
|
||||
"#,
|
||||
)
|
||||
.unwrap()
|
||||
.with_injection_query(
|
||||
r#"
|
||||
(macro_invocation
|
||||
(token_tree) @injection.content
|
||||
(#set! injection.language "rust"))
|
||||
"#,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn elixir_lang() -> Language {
|
||||
Language::new(
|
||||
LanguageConfig {
|
||||
@@ -1425,6 +1396,7 @@ fn assert_capture_ranges(
|
||||
actual_ranges.push(capture.node.byte_range());
|
||||
}
|
||||
}
|
||||
actual_ranges.dedup();
|
||||
|
||||
let (text, expected_ranges) = marked_text_ranges(&marked_string.unindent(), false);
|
||||
assert_eq!(text, buffer.text());
|
||||
|
||||
Reference in New Issue
Block a user