diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index 094d187df2..da176ebeee 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -3110,6 +3110,8 @@ impl ContextEditor { context_editor_view: &View, cx: &mut ViewContext, ) -> Option<(String, bool)> { + const CODE_FENCE_DELIMITER: &'static str = "```"; + let context_editor = context_editor_view.read(cx).editor.read(cx); if context_editor.selections.newest::(cx).is_empty() { @@ -3120,10 +3122,17 @@ impl ContextEditor { let offset = snapshot.point_to_offset(head); let surrounding_code_block_range = find_surrounding_code_block(snapshot, offset)?; - let text = snapshot + let mut text = snapshot .text_for_range(surrounding_code_block_range) .collect::(); + // If there is no newline trailing the closing three-backticks, then + // tree-sitter-md extends the range of the content node to include + // the backticks. + if text.ends_with(CODE_FENCE_DELIMITER) { + text.drain((text.len() - CODE_FENCE_DELIMITER.len())..); + } + (!text.is_empty()).then_some((text, true)) } else { let anchor = context_editor.selections.newest_anchor();