editor: Fix adding extraneous closing tags within TSX (#38534)

This commit is contained in:
Smit Barmase
2025-09-20 04:40:22 +05:30
committed by GitHub
parent 8df616e28b
commit be77682a3f
13 changed files with 218 additions and 84 deletions
+14 -14
View File
@@ -17,10 +17,10 @@ use gpui::{App, AppContext as _, Context, Entity, EntityId, EventEmitter, Task};
use itertools::Itertools;
use language::{
AutoindentMode, Buffer, BufferChunks, BufferRow, BufferSnapshot, Capability, CharClassifier,
CharKind, Chunk, CursorShape, DiagnosticEntry, DiskState, File, IndentGuideSettings,
IndentSize, Language, LanguageScope, OffsetRangeExt, OffsetUtf16, Outline, OutlineItem, Point,
PointUtf16, Selection, TextDimension, TextObject, ToOffset as _, ToPoint as _, TransactionId,
TreeSitterOptions, Unclipped,
CharKind, CharScopeContext, Chunk, CursorShape, DiagnosticEntry, DiskState, File,
IndentGuideSettings, IndentSize, Language, LanguageScope, OffsetRangeExt, OffsetUtf16, Outline,
OutlineItem, Point, PointUtf16, Selection, TextDimension, TextObject, ToOffset as _,
ToPoint as _, TransactionId, TreeSitterOptions, Unclipped,
language_settings::{LanguageSettings, language_settings},
};
@@ -4204,11 +4204,15 @@ impl MultiBufferSnapshot {
self.diffs.values().any(|diff| !diff.is_empty())
}
pub fn is_inside_word<T: ToOffset>(&self, position: T, for_completion: bool) -> bool {
pub fn is_inside_word<T: ToOffset>(
&self,
position: T,
scope_context: Option<CharScopeContext>,
) -> bool {
let position = position.to_offset(self);
let classifier = self
.char_classifier_at(position)
.for_completion(for_completion);
.scope_context(scope_context);
let next_char_kind = self.chars_at(position).next().map(|c| classifier.kind(c));
let prev_char_kind = self
.reversed_chars_at(position)
@@ -4220,16 +4224,14 @@ impl MultiBufferSnapshot {
pub fn surrounding_word<T: ToOffset>(
&self,
start: T,
for_completion: bool,
scope_context: Option<CharScopeContext>,
) -> (Range<usize>, Option<CharKind>) {
let mut start = start.to_offset(self);
let mut end = start;
let mut next_chars = self.chars_at(start).peekable();
let mut prev_chars = self.reversed_chars_at(start).peekable();
let classifier = self
.char_classifier_at(start)
.for_completion(for_completion);
let classifier = self.char_classifier_at(start).scope_context(scope_context);
let word_kind = cmp::max(
prev_chars.peek().copied().map(|c| classifier.kind(c)),
@@ -4258,12 +4260,10 @@ impl MultiBufferSnapshot {
pub fn char_kind_before<T: ToOffset>(
&self,
start: T,
for_completion: bool,
scope_context: Option<CharScopeContext>,
) -> Option<CharKind> {
let start = start.to_offset(self);
let classifier = self
.char_classifier_at(start)
.for_completion(for_completion);
let classifier = self.char_classifier_at(start).scope_context(scope_context);
self.reversed_chars_at(start)
.next()
.map(|ch| classifier.kind(ch))