Add inclusive range scope overrides. Don't auto-close quotes at the ends of line comments (#20206)

Closes #9195
Closes #19787

Release Notes:

- Fixed an issue where single quotation marks were spuriously
auto-closed when typing in line comments
This commit is contained in:
Max Brunsfeld 2024-11-04 15:36:39 -08:00 committed by GitHub
parent 369de400be
commit 258cf6c746
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 120 additions and 61 deletions

View file

@ -1520,18 +1520,24 @@ impl<'a> SyntaxLayer<'a> {
let config = self.language.grammar.as_ref()?.override_config.as_ref()?;
let mut query_cursor = QueryCursorHandle::new();
query_cursor.set_byte_range(offset..offset);
query_cursor.set_byte_range(offset.saturating_sub(1)..offset.saturating_add(1));
let mut smallest_match: Option<(u32, Range<usize>)> = None;
for mat in query_cursor.matches(&config.query, self.node(), text) {
for capture in mat.captures {
if !config.values.contains_key(&capture.index) {
let Some(override_entry) = config.values.get(&capture.index) else {
continue;
}
};
let range = capture.node.byte_range();
if offset <= range.start || offset >= range.end {
continue;
if override_entry.range_is_inclusive {
if offset < range.start || offset > range.end {
continue;
}
} else {
if offset <= range.start || offset >= range.end {
continue;
}
}
if let Some((_, smallest_range)) = &smallest_match {