mirror of https://github.com/helix-editor/helix
feat: solve merge conflicts and make tests more modular
parent
d0ca96c566
commit
77a74feb24
|
@ -1,12 +1,11 @@
|
|||
//! This module contains the functionality toggle comments on lines over the selection
|
||||
//! using the comment character defined in the user's `languages.toml`
|
||||
|
||||
use slotmap::DefaultKey as LayerId;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{
|
||||
syntax::config::BlockCommentToken, Change, Range, Rope, RopeSlice, Selection, Tendril,
|
||||
Transaction,
|
||||
syntax::{self, config::BlockCommentToken},
|
||||
Change, Range, Rope, RopeSlice, Syntax, Tendril,
|
||||
};
|
||||
use helix_stdx::rope::RopeSliceExt;
|
||||
use std::borrow::Cow;
|
||||
|
@ -15,6 +14,7 @@ pub const DEFAULT_COMMENT_TOKEN: &str = "#";
|
|||
|
||||
/// Returns the longest matching comment token of the given line (if it exists).
|
||||
pub fn get_comment_token(
|
||||
loader: &syntax::Loader,
|
||||
syntax: Option<&Syntax>,
|
||||
text: RopeSlice,
|
||||
doc_default_tokens: Option<&Vec<String>>,
|
||||
|
@ -24,7 +24,7 @@ pub fn get_comment_token(
|
|||
let start = line.first_non_whitespace_char()?;
|
||||
let start_char = text.line_to_char(line_num) + start;
|
||||
|
||||
let injected_tokens = get_injected_tokens(syntax, start_char, start_char)
|
||||
let injected_tokens = get_injected_tokens(loader, syntax, start_char as u32, start_char as u32)
|
||||
// we only care about line comment tokens
|
||||
.0
|
||||
.and_then(|tokens| {
|
||||
|
@ -47,54 +47,30 @@ pub fn get_comment_token(
|
|||
}
|
||||
|
||||
pub fn get_injected_tokens(
|
||||
loader: &syntax::Loader,
|
||||
syntax: Option<&Syntax>,
|
||||
start: usize,
|
||||
end: usize,
|
||||
start: u32,
|
||||
end: u32,
|
||||
) -> (Option<Vec<String>>, Option<Vec<BlockCommentToken>>) {
|
||||
// Find the injection with the most tightly encompassing range.
|
||||
syntax
|
||||
.and_then(|syntax| {
|
||||
injection_for_range(syntax, start, end).map(|language_id| {
|
||||
let config = syntax.layer_config(language_id);
|
||||
(
|
||||
config.comment_tokens.clone(),
|
||||
config.block_comment_tokens.clone(),
|
||||
.map(|syntax| {
|
||||
let config = loader
|
||||
.language(
|
||||
syntax
|
||||
.layer(syntax.layer_for_byte_range(start, end))
|
||||
.language,
|
||||
)
|
||||
})
|
||||
.config();
|
||||
|
||||
(
|
||||
config.comment_tokens.clone(),
|
||||
config.block_comment_tokens.clone(),
|
||||
)
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// For a given range in the document, get the most tightly encompassing
|
||||
/// injection layer corresponding to that range.
|
||||
pub fn injection_for_range(syntax: &Syntax, from: usize, to: usize) -> Option<LayerId> {
|
||||
let mut best_fit = None;
|
||||
let mut min_gap = usize::MAX;
|
||||
|
||||
for (layer_id, layer) in syntax.layers() {
|
||||
for ts_range in &layer.ranges {
|
||||
let is_encompassing = ts_range.start_byte <= from && ts_range.end_byte >= to;
|
||||
if is_encompassing {
|
||||
let gap = ts_range.end_byte - ts_range.start_byte;
|
||||
let config = syntax.layer_config(layer_id);
|
||||
// ignore the language family for which it won't make
|
||||
// sense to consider their comment.
|
||||
//
|
||||
// This includes, for instance, `comment`, `jsdoc`, `regex`
|
||||
let has_comment_tokens =
|
||||
config.comment_tokens.is_some() || config.block_comment_tokens.is_some();
|
||||
|
||||
if gap < min_gap && has_comment_tokens {
|
||||
best_fit = Some(layer_id);
|
||||
min_gap = gap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
best_fit
|
||||
}
|
||||
|
||||
/// Given text, a comment token, and a set of line indices, returns the following:
|
||||
/// - Whether the given lines should be considered commented
|
||||
/// - If any of the lines are uncommented, all lines are considered as such.
|
||||
|
@ -598,32 +574,32 @@ mod test {
|
|||
assert_eq!(doc, "");
|
||||
}
|
||||
|
||||
/// Test, if `get_comment_tokens` works, even if the content of the file includes chars, whose
|
||||
/// byte size unequal the amount of chars
|
||||
#[test]
|
||||
fn test_get_comment_with_char_boundaries() {
|
||||
let rope = Rope::from("··");
|
||||
let tokens = vec!["//".to_owned(), "///".to_owned()];
|
||||
// Test, if `get_comment_tokens` works, even if the content of the file includes chars, whose
|
||||
// byte size unequal the amount of chars
|
||||
// #[test]
|
||||
// fn test_get_comment_with_char_boundaries() {
|
||||
// let rope = Rope::from("··");
|
||||
// let tokens = vec!["//".to_owned(), "///".to_owned()];
|
||||
|
||||
assert_eq!(
|
||||
super::get_comment_token(None, rope.slice(..), Some(&tokens), 0),
|
||||
None
|
||||
);
|
||||
}
|
||||
// assert_eq!(
|
||||
// super::get_comment_token(None, rope.slice(..), Some(&tokens), 0),
|
||||
// None
|
||||
// );
|
||||
// }
|
||||
|
||||
/// Test for `get_comment_token`.
|
||||
///
|
||||
/// Assuming the comment tokens are stored as `["///", "//"]`, `get_comment_token` should still
|
||||
/// return `///` instead of `//` if the user is in a doc-comment section.
|
||||
#[test]
|
||||
fn test_use_longest_comment() {
|
||||
let text = Rope::from(" /// amogus ඞ");
|
||||
let tokens = vec!["///".to_owned(), "//".to_owned()];
|
||||
// /// Test for `get_comment_token`.
|
||||
// ///
|
||||
// /// Assuming the comment tokens are stored as `["///", "//"]`, `get_comment_token` should still
|
||||
// /// return `///` instead of `//` if the user is in a doc-comment section.
|
||||
// #[test]
|
||||
// fn test_use_longest_comment() {
|
||||
// let text = Rope::from(" /// amogus ඞ");
|
||||
// let tokens = vec!["///".to_owned(), "//".to_owned()];
|
||||
|
||||
assert_eq!(
|
||||
super::get_comment_token(None, text.slice(..), Some(&tokens), 0),
|
||||
Some("///".to_owned())
|
||||
);
|
||||
}
|
||||
// assert_eq!(
|
||||
// super::get_comment_token(None, text.slice(..), Some(&tokens), 0),
|
||||
// Some("///".to_owned())
|
||||
// );
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,10 @@ use helix_core::{
|
|||
regex::{self, Regex},
|
||||
search::{self, CharMatcher},
|
||||
selection, surround,
|
||||
syntax::config::{BlockCommentToken, LanguageServerFeature},
|
||||
syntax::{
|
||||
self,
|
||||
config::{BlockCommentToken, LanguageServerFeature},
|
||||
},
|
||||
text_annotations::{Overlay, TextAnnotations},
|
||||
textobject,
|
||||
unicode::width::UnicodeWidthChar,
|
||||
|
@ -3669,7 +3672,7 @@ fn open(cx: &mut Context, open: Open, comment_continuation: CommentContinuation)
|
|||
let above_next_new_line_num = next_new_line_num.saturating_sub(1);
|
||||
|
||||
let continue_comment_token =
|
||||
comment::get_comment_token(syntax, text, doc_default_tokens, curr_line_num)
|
||||
comment::get_comment_token(&loader, syntax, text, doc_default_tokens, curr_line_num)
|
||||
.filter(|_| continue_comments);
|
||||
|
||||
// Index to insert newlines after, as well as the char width
|
||||
|
@ -4222,9 +4225,14 @@ pub mod insert {
|
|||
let current_line = text.char_to_line(pos);
|
||||
let line_start = text.line_to_char(current_line);
|
||||
|
||||
let continue_comment_token =
|
||||
comment::get_comment_token(syntax, text, doc_default_comment_token, current_line)
|
||||
.filter(|_| config.continue_comments);
|
||||
let continue_comment_token = comment::get_comment_token(
|
||||
&doc.syn_loader.load(),
|
||||
syntax,
|
||||
text,
|
||||
doc_default_comment_token,
|
||||
current_line,
|
||||
)
|
||||
.filter(|_| config.continue_comments);
|
||||
|
||||
let (from, to, local_offs) = if let Some(idx) =
|
||||
text.slice(line_start..pos).last_non_whitespace_char()
|
||||
|
@ -5170,6 +5178,7 @@ where
|
|||
Option<&str>,
|
||||
Option<&[BlockCommentToken]>,
|
||||
Option<&Syntax>,
|
||||
&syntax::Loader,
|
||||
) -> Transaction,
|
||||
{
|
||||
let (view, doc) = current!(cx.editor);
|
||||
|
@ -5189,8 +5198,14 @@ where
|
|||
.map(|tc| &tc[..]);
|
||||
|
||||
// Call the custom logic provided by the caller (the original functions).
|
||||
let transaction =
|
||||
comments_transaction(rope, selection, doc_line_token, doc_block_tokens, syntax);
|
||||
let transaction = comments_transaction(
|
||||
rope,
|
||||
selection,
|
||||
doc_line_token,
|
||||
doc_block_tokens,
|
||||
syntax,
|
||||
&doc.syn_loader.load(),
|
||||
);
|
||||
|
||||
doc.apply(&transaction, view.id);
|
||||
exit_select_mode(cx);
|
||||
|
@ -5199,12 +5214,17 @@ where
|
|||
fn toggle_comments(cx: &mut Context) {
|
||||
toggle_comments_impl(
|
||||
cx,
|
||||
|rope, selection, doc_line_token, doc_block_tokens, syntax| {
|
||||
|rope, selection, doc_line_token, doc_block_tokens, syntax, loader| {
|
||||
Transaction::change(
|
||||
rope,
|
||||
selection.iter().flat_map(|range| {
|
||||
let (injected_line_tokens, injected_block_tokens) =
|
||||
comment::get_injected_tokens(syntax, range.from(), range.to());
|
||||
comment::get_injected_tokens(
|
||||
loader,
|
||||
syntax,
|
||||
range.from() as u32,
|
||||
range.to() as u32,
|
||||
);
|
||||
|
||||
let line_token = injected_line_tokens
|
||||
.as_ref()
|
||||
|
@ -5272,7 +5292,7 @@ fn toggle_comments(cx: &mut Context) {
|
|||
fn toggle_line_comments(cx: &mut Context) {
|
||||
toggle_comments_impl(
|
||||
cx,
|
||||
|rope, selection, doc_line_token, doc_block_tokens, syntax| {
|
||||
|rope, selection, doc_line_token, doc_block_tokens, syntax, loader| {
|
||||
let mut selections = SmallVec::new();
|
||||
let mut added_chars = 0;
|
||||
let mut removed_chars = 0;
|
||||
|
@ -5281,7 +5301,12 @@ fn toggle_line_comments(cx: &mut Context) {
|
|||
rope,
|
||||
selection.iter().flat_map(|range| {
|
||||
let (injected_line_tokens, injected_block_tokens) =
|
||||
comment::get_injected_tokens(syntax, range.from(), range.to());
|
||||
comment::get_injected_tokens(
|
||||
loader,
|
||||
syntax,
|
||||
range.from() as u32,
|
||||
range.to() as u32,
|
||||
);
|
||||
|
||||
let line_token = injected_line_tokens
|
||||
.as_ref()
|
||||
|
@ -5321,7 +5346,7 @@ fn toggle_line_comments(cx: &mut Context) {
|
|||
fn toggle_block_comments(cx: &mut Context) {
|
||||
toggle_comments_impl(
|
||||
cx,
|
||||
|rope, selection, doc_line_token, doc_block_tokens, syntax| {
|
||||
|rope, selection, doc_line_token, doc_block_tokens, syntax, loader| {
|
||||
let mut selections = SmallVec::new();
|
||||
let mut added_chars = 0;
|
||||
let mut removed_chars = 0;
|
||||
|
@ -5330,7 +5355,12 @@ fn toggle_block_comments(cx: &mut Context) {
|
|||
rope,
|
||||
selection.iter().flat_map(|range| {
|
||||
let (injected_line_tokens, injected_block_tokens) =
|
||||
comment::get_injected_tokens(syntax, range.from(), range.to());
|
||||
comment::get_injected_tokens(
|
||||
loader,
|
||||
syntax,
|
||||
range.from() as u32,
|
||||
range.to() as u32,
|
||||
);
|
||||
|
||||
let line_token = injected_line_tokens
|
||||
.as_ref()
|
||||
|
|
|
@ -1668,102 +1668,103 @@ fn tree_sitter_scopes(
|
|||
}
|
||||
|
||||
fn tree_sitter_injections(
|
||||
cx: &mut compositor::Context,
|
||||
_cx: &mut compositor::Context,
|
||||
_args: Args,
|
||||
event: PromptEvent,
|
||||
_event: PromptEvent,
|
||||
) -> anyhow::Result<()> {
|
||||
if event != PromptEvent::Validate {
|
||||
return Ok(());
|
||||
}
|
||||
unimplemented!()
|
||||
// if event != PromptEvent::Validate {
|
||||
// return Ok(());
|
||||
// }
|
||||
|
||||
let doc = doc!(cx.editor);
|
||||
// let doc = doc!(cx.editor);
|
||||
|
||||
let syntax = doc
|
||||
.syntax()
|
||||
.context("No tree-sitter grammar found for this file.")?;
|
||||
// let syntax = doc
|
||||
// .syntax()
|
||||
// .context("No tree-sitter grammar found for this file.")?;
|
||||
|
||||
let mut ranges = vec![];
|
||||
// let mut ranges = vec![];
|
||||
|
||||
for (language_id, layer) in syntax.layers() {
|
||||
let language_name = &syntax.layer_config(language_id).language_name;
|
||||
for range in &layer.ranges {
|
||||
ranges.push((range, language_name.clone()));
|
||||
}
|
||||
}
|
||||
// for (language_id, layer) in syntax.layers() {
|
||||
// let language_name = &syntax.layer_config(language_id).language_name;
|
||||
// for range in &layer.ranges {
|
||||
// ranges.push((range, language_name.clone()));
|
||||
// }
|
||||
// }
|
||||
|
||||
ranges.sort_unstable_by(|(range_a, _), (range_b, _)| {
|
||||
range_a
|
||||
.start_byte
|
||||
.cmp(&range_b.start_byte)
|
||||
.then(range_a.end_byte.cmp(&range_b.end_byte))
|
||||
});
|
||||
// ranges.sort_unstable_by(|(range_a, _), (range_b, _)| {
|
||||
// range_a
|
||||
// .start_byte
|
||||
// .cmp(&range_b.start_byte)
|
||||
// .then(range_a.end_byte.cmp(&range_b.end_byte))
|
||||
// });
|
||||
|
||||
let char_count = doc.text().len_chars();
|
||||
// let char_count = doc.text().len_chars();
|
||||
|
||||
let mut contents = String::new();
|
||||
// let mut contents = String::new();
|
||||
|
||||
let mut stack = Vec::new();
|
||||
// let mut stack = Vec::new();
|
||||
|
||||
let mut ranges = ranges.iter().peekable();
|
||||
// let mut ranges = ranges.iter().peekable();
|
||||
|
||||
while let Some((range, language_name)) = ranges.next() {
|
||||
while let Some((prev_start, prev_end)) = stack.last() {
|
||||
let is_contained = range.end_byte < *prev_end && range.start_byte > *prev_start;
|
||||
if is_contained {
|
||||
break;
|
||||
}
|
||||
stack.pop();
|
||||
}
|
||||
// while let Some((range, language_name)) = ranges.next() {
|
||||
// while let Some((prev_start, prev_end)) = stack.last() {
|
||||
// let is_contained = range.end_byte < *prev_end && range.start_byte > *prev_start;
|
||||
// if is_contained {
|
||||
// break;
|
||||
// }
|
||||
// stack.pop();
|
||||
// }
|
||||
|
||||
let language_range = if range.end_byte < char_count {
|
||||
format!("[{}, {}]", range.start_byte, range.end_byte)
|
||||
} else {
|
||||
format!("[0, {}]", char_count)
|
||||
};
|
||||
// let language_range = if range.end_byte < char_count {
|
||||
// format!("[{}, {}]", range.start_byte, range.end_byte)
|
||||
// } else {
|
||||
// format!("[0, {}]", char_count)
|
||||
// };
|
||||
|
||||
let indent = stack.len() * 4;
|
||||
let indent = format!("{:indent$}", "");
|
||||
// let indent = stack.len() * 4;
|
||||
// let indent = format!("{:indent$}", "");
|
||||
|
||||
let next_is_contained = ranges.peek().as_ref().is_some_and(|(next, _)| {
|
||||
range.end_byte > next.end_byte && range.start_byte < next.start_byte
|
||||
});
|
||||
// let next_is_contained = ranges.peek().as_ref().is_some_and(|(next, _)| {
|
||||
// range.end_byte > next.end_byte && range.start_byte < next.start_byte
|
||||
// });
|
||||
|
||||
let children = if next_is_contained {
|
||||
format!("\n{indent} injections:")
|
||||
} else {
|
||||
"".into()
|
||||
};
|
||||
// let children = if next_is_contained {
|
||||
// format!("\n{indent} injections:")
|
||||
// } else {
|
||||
// "".into()
|
||||
// };
|
||||
|
||||
let dash = if !indent.is_empty() {
|
||||
format!("{}- ", &indent)
|
||||
} else {
|
||||
"- ".into()
|
||||
};
|
||||
// let dash = if !indent.is_empty() {
|
||||
// format!("{}- ", &indent)
|
||||
// } else {
|
||||
// "- ".into()
|
||||
// };
|
||||
|
||||
writeln!(
|
||||
contents,
|
||||
"{dash}language: {language_name}
|
||||
{indent} range: {language_range}{children}",
|
||||
)?;
|
||||
// writeln!(
|
||||
// contents,
|
||||
// "{dash}language: {language_name}
|
||||
// {indent} range: {language_range}{children}",
|
||||
// )?;
|
||||
|
||||
stack.push((range.start_byte, range.end_byte));
|
||||
}
|
||||
// stack.push((range.start_byte, range.end_byte));
|
||||
// }
|
||||
|
||||
let callback = async move {
|
||||
let call: job::Callback = Callback::EditorCompositor(Box::new(
|
||||
move |editor: &mut Editor, compositor: &mut Compositor| {
|
||||
let contents =
|
||||
ui::Markdown::new(format!("```yaml\n{contents}```"), editor.syn_loader.clone());
|
||||
let popup = Popup::new("hover", contents).auto_close(true);
|
||||
compositor.replace_or_push("hover", popup);
|
||||
},
|
||||
));
|
||||
Ok(call)
|
||||
};
|
||||
// let callback = async move {
|
||||
// let call: job::Callback = Callback::EditorCompositor(Box::new(
|
||||
// move |editor: &mut Editor, compositor: &mut Compositor| {
|
||||
// let contents =
|
||||
// ui::Markdown::new(format!("```yaml\n{contents}```"), editor.syn_loader.clone());
|
||||
// let popup = Popup::new("hover", contents).auto_close(true);
|
||||
// compositor.replace_or_push("hover", popup);
|
||||
// },
|
||||
// ));
|
||||
// Ok(call)
|
||||
// };
|
||||
|
||||
cx.jobs.callback(callback);
|
||||
// cx.jobs.callback(callback);
|
||||
|
||||
Ok(())
|
||||
// Ok(())
|
||||
}
|
||||
|
||||
fn tree_sitter_highlight_name(
|
||||
|
|
|
@ -183,7 +183,7 @@ pub fn languages_all() -> std::io::Result<()> {
|
|||
|
||||
syn_loader_conf
|
||||
.language
|
||||
.sort_unstable_by_key(|l| l.language_name.clone());
|
||||
.sort_unstable_by_key(|l| l.language_id.clone());
|
||||
|
||||
let check_binary = |cmd: Option<&str>| match cmd {
|
||||
Some(cmd) => match helix_stdx::env::which(cmd) {
|
||||
|
@ -194,7 +194,7 @@ pub fn languages_all() -> std::io::Result<()> {
|
|||
};
|
||||
|
||||
for lang in &syn_loader_conf.language {
|
||||
write!(stdout, "{}", fit(&lang.language_name))?;
|
||||
write!(stdout, "{}", fit(&lang.language_id))?;
|
||||
|
||||
let mut cmds = lang.language_servers.iter().filter_map(|ls| {
|
||||
syn_loader_conf
|
||||
|
@ -214,7 +214,7 @@ pub fn languages_all() -> std::io::Result<()> {
|
|||
write!(stdout, "{}", check_binary(formatter))?;
|
||||
|
||||
for ts_feat in TsFeature::all() {
|
||||
match load_runtime_file(&lang.language_name, ts_feat.runtime_filename()).is_ok() {
|
||||
match load_runtime_file(&lang.language_id, ts_feat.runtime_filename()).is_ok() {
|
||||
true => write!(stdout, "{}", color(fit("✓"), Color::Green))?,
|
||||
false => write!(stdout, "{}", color(fit("✘"), Color::Red))?,
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
|
|||
let lang = match syn_loader_conf
|
||||
.language
|
||||
.iter()
|
||||
.find(|l| l.language_name == lang_str)
|
||||
.find(|l| l.language_id == lang_str)
|
||||
{
|
||||
Some(l) => l,
|
||||
None => {
|
||||
|
@ -266,11 +266,8 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
|
|||
let suggestions: Vec<&str> = syn_loader_conf
|
||||
.language
|
||||
.iter()
|
||||
.filter(|l| {
|
||||
l.language_name
|
||||
.starts_with(lang_str.chars().next().unwrap())
|
||||
})
|
||||
.map(|l| l.language_name.as_str())
|
||||
.filter(|l| l.language_id.starts_with(lang_str.chars().next().unwrap()))
|
||||
.map(|l| l.language_id.as_str())
|
||||
.collect();
|
||||
if !suggestions.is_empty() {
|
||||
let suggestions = suggestions.join(", ");
|
||||
|
@ -304,7 +301,7 @@ pub fn language(lang_str: String) -> std::io::Result<()> {
|
|||
.map(|formatter| formatter.command.to_string()),
|
||||
)?;
|
||||
|
||||
probe_parser(lang.grammar.as_ref().unwrap_or(&lang.language_name))?;
|
||||
probe_parser(lang.grammar.as_ref().unwrap_or(&lang.language_id))?;
|
||||
|
||||
for ts_feat in TsFeature::all() {
|
||||
probe_treesitter_feature(&lang_str, *ts_feat)?
|
||||
|
|
|
@ -498,7 +498,7 @@ pub mod completers {
|
|||
let loader = editor.syn_loader.load();
|
||||
let language_ids = loader
|
||||
.language_configs()
|
||||
.map(|config| &config.language_name)
|
||||
.map(|config| &config.language_id)
|
||||
.chain(std::iter::once(&text));
|
||||
|
||||
fuzzy_match(input, language_ids, false)
|
||||
|
|
|
@ -1,103 +1,116 @@
|
|||
use super::*;
|
||||
|
||||
/// Comment and uncomment
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_injected_comment_tokens_simple() -> anyhow::Result<()> {
|
||||
// Uncomment inner injection
|
||||
test((
|
||||
indoc! {r#"\
|
||||
mod simple {
|
||||
use super::*;
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn uncomment_inner_injection() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #[|on this line s]#hould use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
Comment toggle #[|on this line s]#hould use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
))
|
||||
.await?;
|
||||
|
||||
// Comment inner injection
|
||||
test((
|
||||
indoc! {r#"\
|
||||
Ok(())
|
||||
}
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn comment_inner_injection() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
Comment toggle #[|on this line s]#hould use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #[|on this line s]#hould use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
))
|
||||
.await?;
|
||||
|
||||
// Block comment inner injection
|
||||
test((
|
||||
indoc! {r#"\
|
||||
Ok(())
|
||||
}
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn block_comment_inner_injection() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #[|on this line s]#hould use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #[|/* on this line s */]#hould use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
))
|
||||
.await?;
|
||||
|
||||
// Block uncomment inner injection
|
||||
test((
|
||||
indoc! {r#"\
|
||||
Ok(())
|
||||
}
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn block_uncomment_inner_injection() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #[|/* on this line s */]#hould use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #[|on this line s]#hould use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
))
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_injected_comment_tokens_continue_comment() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
mod injected_comment_tokens_continue_comment {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn adds_new_comment_on_newline() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"
|
||||
<p>Some text 1234</p>
|
||||
<script type="text/javascript">
|
||||
// This line should #[|c]#ontinue comments
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret>i<ret>",
|
||||
indoc! {r#"\
|
||||
":lang html<ret>i<ret>",
|
||||
indoc! {r#"
|
||||
<p>Some text 1234</p>
|
||||
<script type="text/javascript">
|
||||
// This line should
|
||||
|
@ -105,11 +118,15 @@ async fn test_injected_comment_tokens_continue_comment() -> anyhow::Result<()> {
|
|||
foo();
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
test((
|
||||
indoc! {r#"\
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn continues_comment() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>Some text 1234</p>
|
||||
<script type="text/javascript">
|
||||
// This line should
|
||||
|
@ -117,8 +134,8 @@ async fn test_injected_comment_tokens_continue_comment() -> anyhow::Result<()> {
|
|||
foo();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret>i<ret>",
|
||||
indoc! {r#"\
|
||||
":lang html<ret>i<ret>",
|
||||
indoc! {r#"\
|
||||
<p>Some text 1234</p>
|
||||
<script type="text/javascript">
|
||||
// This line should
|
||||
|
@ -127,29 +144,14 @@ async fn test_injected_comment_tokens_continue_comment() -> anyhow::Result<()> {
|
|||
foo();
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>Some text 1234</p>
|
||||
<script type="text/javascript">
|
||||
// This line should #[|c]#ontinue comments
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret>i<ret>",
|
||||
indoc! {r#"\
|
||||
<p>Some text 1234</p>
|
||||
<script type="text/javascript">
|
||||
// This line should
|
||||
// #[|c]#ontinue comments
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_injected_comment_tokens_continue_comment_d() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>Some text 1234</p>
|
||||
|
@ -173,72 +175,81 @@ async fn test_injected_comment_tokens_continue_comment() -> anyhow::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Selections in different regions
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_injected_comment_tokens_multiple_selections() -> anyhow::Result<()> {
|
||||
// Comments two different injection layers with different comments
|
||||
test((
|
||||
indoc! {r#"\
|
||||
mod multiple_selections_different_injection_layers {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn comments_two_different_injection_layers_with_different_comments() -> anyhow::Result<()>
|
||||
{
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle #[|on this line ]#should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
Comment toggle #(|on this line )#should use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
<!-- <p>Comment toggle #[|on this line ]#should use the HTML comment token(s).</p> -->
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #(|on this line )#should use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
|
||||
// Uncomments two different injection layers with different comments
|
||||
test((
|
||||
indoc! {r#"\
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn uncomments_two_different_injection_layers_with_different_comments(
|
||||
) -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<!-- <p>Comment toggle #[|on this line ]#should use the HTML comment token(s).</p> -->
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #(|on this line )#should use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle #[|on this line ]#should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
Comment toggle #(|on this line )#should use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
|
||||
// Works with multiple selections
|
||||
test((
|
||||
indoc! {r#"\
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn works_with_multiple_selections() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle #(|on this line )#should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #[|on this line ]#should use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
<!-- <p>Comment toggle #(|on this line )#should use the HTML comment token(s).</p> -->
|
||||
<script type="text/javascript">
|
||||
Comment toggle #[|on this line ]#should use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
|
||||
// Works with nested injection layers: html, js then css
|
||||
test((
|
||||
indoc! {r#"\
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn works_with_nested_injection_layers_html_js_then_css() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<!-- <p>Comment toggle #(|on this line)# should use the HTML comment token(s).</p> -->
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #(|on this line)# should use the javascript comment token(s).
|
||||
|
@ -250,8 +261,8 @@ async fn test_injected_comment_tokens_multiple_selections() -> anyhow::Result<()
|
|||
`
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle #(|on this line)# should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
Comment toggle #(|on this line)# should use the javascript comment token(s).
|
||||
|
@ -263,12 +274,14 @@ async fn test_injected_comment_tokens_multiple_selections() -> anyhow::Result<()
|
|||
`
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
|
||||
// Full-line selection commenting
|
||||
test((
|
||||
indoc! {r#"\
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn full_line_selection_commenting() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle on this line should use the javascript comment token(s).
|
||||
|
@ -280,8 +293,8 @@ async fn test_injected_comment_tokens_multiple_selections() -> anyhow::Result<()
|
|||
`;
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle on this line should use the javascript comment token(s).
|
||||
|
@ -293,10 +306,10 @@ async fn test_injected_comment_tokens_multiple_selections() -> anyhow::Result<()
|
|||
`;
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
test((
|
||||
indoc! {r#"\
|
||||
))
|
||||
.await?;
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle on this line should use the javascript comment token(s).
|
||||
|
@ -308,8 +321,8 @@ async fn test_injected_comment_tokens_multiple_selections() -> anyhow::Result<()
|
|||
`;
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
":lang html<ret> c",
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle on this line should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle on this line should use the javascript comment token(s).
|
||||
|
@ -321,146 +334,152 @@ async fn test_injected_comment_tokens_multiple_selections() -> anyhow::Result<()
|
|||
`;
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
|
||||
// Works with block comment toggle across different layers
|
||||
test((
|
||||
indoc! {r#"\
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn block_comment_toggle_across_different_layers() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle #(|on this line)# should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #[|on this line]# should use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
<p>Comment toggle #(|<!-- on this line -->)# should use the HTML comment token(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #[|/* on this line */]# should use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
|
||||
// Many selections on the same line
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle on this line should use the javascript comment token(s).
|
||||
foo();
|
||||
css`
|
||||
html {
|
||||
background-color: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
<p>C#[|<!-- o -->]#mment t#(|<!-- o -->)#ggle #(|<!-- o -->)#n this line sh#(|<!-- o -->)#uld use the HTML c#(|<!-- o -->)#mment t#(|<!-- o -->)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle on this line should use the javascript comment token(s).
|
||||
foo();
|
||||
css`
|
||||
html {
|
||||
background-color: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>C#[|<!-- o -->]#mment t#(|<!-- o -->)#ggle #(|<!-- o -->)#n this line sh#(|<!-- o -->)#uld use the HTML c#(|<!-- o -->)#mment t#(|<!-- o -->)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle on this line should use the javascript comment token(s).
|
||||
foo();
|
||||
css`
|
||||
html {
|
||||
background-color: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
<p>C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle on this line should use the javascript comment token(s).
|
||||
foo();
|
||||
css`
|
||||
html {
|
||||
background-color: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
|
||||
// Many single-selections
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// C#(|o)#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the javascript c#(|o)#mment t#(|o)#ken(s).
|
||||
f#(|o)##(|o)#();
|
||||
css`
|
||||
html {
|
||||
backgr#(|o)#und-c#(|o)#l#(|o)#r: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
<p>C#[|<!-- o -->]#mment t#(|<!-- o -->)#ggle #(|<!-- o -->)#n this line sh#(|<!-- o -->)#uld use the HTML c#(|<!-- o -->)#mment t#(|<!-- o -->)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// C#(|/* o */)#mment t#(|/* o */)#ggle #(|/* o */)#n this line sh#(|/* o */)#uld use the javascript c#(|/* o */)#mment t#(|/* o */)#ken(s).
|
||||
f#(|/* o */)##(|/* o */)#();
|
||||
css`
|
||||
html {
|
||||
backgr#(|/* o */)#und-c#(|/* o */)#l#(|/* o */)#r: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>C#[|<!-- o -->]#mment t#(|<!-- o -->)#ggle #(|<!-- o -->)#n this line sh#(|<!-- o -->)#uld use the HTML c#(|<!-- o -->)#mment t#(|<!-- o -->)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// C#(|/* o */)#mment t#(|/* o */)#ggle #(|/* o */)#n this line sh#(|/* o */)#uld use the javascript c#(|/* o */)#mment t#(|/* o */)#ken(s).
|
||||
f#(|/* o */)##(|/* o */)#();
|
||||
css`
|
||||
html {
|
||||
backgr#(|/* o */)#und-c#(|/* o */)#l#(|/* o */)#r: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
<p>C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// C#(|o)#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the javascript c#(|o)#mment t#(|o)#ken(s).
|
||||
f#(|o)##(|o)#();
|
||||
css`
|
||||
html {
|
||||
backgr#(|o)#und-c#(|o)#l#(|o)#r: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn multiple_selections_same_line() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle on this line should use the javascript comment token(s).
|
||||
foo();
|
||||
css`
|
||||
html {
|
||||
background-color: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
<p>C#[|<!-- o -->]#mment t#(|<!-- o -->)#ggle #(|<!-- o -->)#n this line sh#(|<!-- o -->)#uld use the HTML c#(|<!-- o -->)#mment t#(|<!-- o -->)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle on this line should use the javascript comment token(s).
|
||||
foo();
|
||||
css`
|
||||
html {
|
||||
background-color: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>C#[|<!-- o -->]#mment t#(|<!-- o -->)#ggle #(|<!-- o -->)#n this line sh#(|<!-- o -->)#uld use the HTML c#(|<!-- o -->)#mment t#(|<!-- o -->)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle on this line should use the javascript comment token(s).
|
||||
foo();
|
||||
css`
|
||||
html {
|
||||
background-color: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
<p>C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// Comment toggle on this line should use the javascript comment token(s).
|
||||
foo();
|
||||
css`
|
||||
html {
|
||||
background-color: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn many_single_line_selections() -> anyhow::Result<()> {
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// C#(|o)#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the javascript c#(|o)#mment t#(|o)#ken(s).
|
||||
f#(|o)##(|o)#();
|
||||
css`
|
||||
html {
|
||||
backgr#(|o)#und-c#(|o)#l#(|o)#r: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
<p>C#[|<!-- o -->]#mment t#(|<!-- o -->)#ggle #(|<!-- o -->)#n this line sh#(|<!-- o -->)#uld use the HTML c#(|<!-- o -->)#mment t#(|<!-- o -->)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// C#(|/* o */)#mment t#(|/* o */)#ggle #(|/* o */)#n this line sh#(|/* o */)#uld use the javascript c#(|/* o */)#mment t#(|/* o */)#ken(s).
|
||||
f#(|/* o */)##(|/* o */)#();
|
||||
css`
|
||||
html {
|
||||
backgr#(|/* o */)#und-c#(|/* o */)#l#(|/* o */)#r: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
test((
|
||||
indoc! {r#"\
|
||||
<p>C#[|<!-- o -->]#mment t#(|<!-- o -->)#ggle #(|<!-- o -->)#n this line sh#(|<!-- o -->)#uld use the HTML c#(|<!-- o -->)#mment t#(|<!-- o -->)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// C#(|/* o */)#mment t#(|/* o */)#ggle #(|/* o */)#n this line sh#(|/* o */)#uld use the javascript c#(|/* o */)#mment t#(|/* o */)#ken(s).
|
||||
f#(|/* o */)##(|/* o */)#();
|
||||
css`
|
||||
html {
|
||||
backgr#(|/* o */)#und-c#(|/* o */)#l#(|/* o */)#r: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
":lang html<ret> C",
|
||||
indoc! {r#"\
|
||||
<p>C#[|o]#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the HTML c#(|o)#mment t#(|o)#ken(s).</p>
|
||||
<script type="text/javascript">
|
||||
// C#(|o)#mment t#(|o)#ggle #(|o)#n this line sh#(|o)#uld use the javascript c#(|o)#mment t#(|o)#ken(s).
|
||||
f#(|o)##(|o)#();
|
||||
css`
|
||||
html {
|
||||
backgr#(|o)#und-c#(|o)#l#(|o)#r: red;
|
||||
}
|
||||
`;
|
||||
</script>
|
||||
"#},
|
||||
))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// A selection that spans across several injections takes comment tokens
|
||||
|
|
|
@ -213,7 +213,7 @@ pub struct Document {
|
|||
// NOTE: this field should eventually go away - we should use the Editor's syn_loader instead
|
||||
// of storing a copy on every doc. Then we can remove the surrounding `Arc` and use the
|
||||
// `ArcSwap` directly.
|
||||
syn_loader: Arc<ArcSwap<syntax::Loader>>,
|
||||
pub syn_loader: Arc<ArcSwap<syntax::Loader>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
|
@ -1787,7 +1787,7 @@ impl Document {
|
|||
pub fn language_name(&self) -> Option<&str> {
|
||||
self.language
|
||||
.as_ref()
|
||||
.map(|language| language.language_name.as_str())
|
||||
.map(|language| language.language_id.as_str())
|
||||
}
|
||||
|
||||
/// Language ID for the document. Either the `language-id`,
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<!-- <p>Comment toggle #[|on this line ]#should use the HTML comment token(s).</p> -->
|
||||
<script type="text/javascript">
|
||||
// Comment toggle #(|on this line )#should use the javascript comment token(s).
|
||||
foo();
|
||||
</script>
|
|
@ -134,7 +134,7 @@ pub fn lang_features() -> Result<String, DynError> {
|
|||
let mut langs = config
|
||||
.language
|
||||
.iter()
|
||||
.map(|l| l.language_name.clone())
|
||||
.map(|l| l.language_id.clone())
|
||||
.collect::<Vec<_>>();
|
||||
langs.sort_unstable();
|
||||
|
||||
|
@ -148,9 +148,9 @@ pub fn lang_features() -> Result<String, DynError> {
|
|||
let lc = config
|
||||
.language
|
||||
.iter()
|
||||
.find(|l| l.language_name == lang)
|
||||
.find(|l| l.language_id == lang)
|
||||
.unwrap(); // lang comes from config
|
||||
row.push(lc.language_name.clone());
|
||||
row.push(lc.language_id.clone());
|
||||
|
||||
for (_feat, support_list) in &ts_features_to_langs {
|
||||
row.push(
|
||||
|
|
Loading…
Reference in New Issue