mirror of https://github.com/helix-editor/helix
snippets: Discard placeholder text for the `$0` tabstop
parent
032dadaf37
commit
cb0f201d0e
|
@ -252,4 +252,21 @@ mod tests {
|
||||||
snippet.map(edit.changes());
|
snippet.map(edit.changes());
|
||||||
assert!(!snippet.is_valid(&Selection::point(4)))
|
assert!(!snippet.is_valid(&Selection::point(4)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tabstop_zero_with_placeholder() {
|
||||||
|
// The `$0` tabstop should not have placeholder text. When we receive a snippet like this
|
||||||
|
// (from older versions of clangd for example) we should discard the placeholder text.
|
||||||
|
let snippet = Snippet::parse("sizeof(${0:expression-or-type})").unwrap();
|
||||||
|
let mut doc = Rope::from("\n");
|
||||||
|
let (transaction, _, snippet) = snippet.render(
|
||||||
|
&doc,
|
||||||
|
&Selection::point(0),
|
||||||
|
|_| (0, 0),
|
||||||
|
&mut SnippetRenderCtx::test_ctx(),
|
||||||
|
);
|
||||||
|
assert!(transaction.apply(&mut doc));
|
||||||
|
assert_eq!(doc, "sizeof()\n");
|
||||||
|
assert!(ActiveSnippet::new(snippet).is_none());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,9 +178,16 @@ impl Snippet {
|
||||||
&mut self,
|
&mut self,
|
||||||
idx: usize,
|
idx: usize,
|
||||||
parent: Option<TabstopIdx>,
|
parent: Option<TabstopIdx>,
|
||||||
default: Vec<parser::SnippetElement>,
|
mut default: Vec<parser::SnippetElement>,
|
||||||
) -> TabstopIdx {
|
) -> TabstopIdx {
|
||||||
let idx = TabstopIdx::elaborate(idx);
|
let idx = TabstopIdx::elaborate(idx);
|
||||||
|
if idx == LAST_TABSTOP_IDX && !default.is_empty() {
|
||||||
|
// Older versions of clangd for example may send a snippet like `${0:placeholder}`
|
||||||
|
// which is considered by VSCode to be a misuse of the `$0` tabstop.
|
||||||
|
log::warn!("Discarding placeholder text for the `$0` tabstop ({default:?}). \
|
||||||
|
The `$0` tabstop signifies the final cursor position and should not include placeholder text.");
|
||||||
|
default.clear();
|
||||||
|
}
|
||||||
let default = self.elaborate(default, Some(idx));
|
let default = self.elaborate(default, Some(idx));
|
||||||
self.tabstops.push(Tabstop {
|
self.tabstops.push(Tabstop {
|
||||||
idx,
|
idx,
|
||||||
|
|
Loading…
Reference in New Issue