diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 0e4be2058c..7d675aa5af 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5758,10 +5758,22 @@ impl Editor { let cursor_position = newest_selection.head(); let (cursor_buffer, cursor_buffer_position) = buffer.text_anchor_for_position(cursor_position, cx)?; - let (tail_buffer, _) = buffer.text_anchor_for_position(newest_selection.tail(), cx)?; + let (tail_buffer, tail_buffer_position) = + buffer.text_anchor_for_position(newest_selection.tail(), cx)?; if cursor_buffer != tail_buffer { return None; } + + let snapshot = cursor_buffer.read(cx).snapshot(); + let (start_word_range, _) = snapshot.surrounding_word(cursor_buffer_position); + let (end_word_range, _) = snapshot.surrounding_word(tail_buffer_position); + if start_word_range != end_word_range { + self.document_highlights_task.take(); + self.clear_background_highlights::(cx); + self.clear_background_highlights::(cx); + return None; + } + let debounce = EditorSettings::get_global(cx).lsp_highlight_debounce; self.document_highlights_task = Some(cx.spawn(async move |this, cx| { cx.background_executor()