Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use helix_view::{
};

use anyhow::{anyhow, bail, ensure, Context as _};
use arc_swap::access::DynAccess;
use insert::*;
use movement::Movement;

Expand Down Expand Up @@ -4152,7 +4153,9 @@ pub mod insert {
let (view, doc) = current_ref!(cx.editor);
let text = doc.text();
let selection = doc.selection(view.id);
let auto_pairs = doc.auto_pairs(cx.editor);

let loader: &helix_core::syntax::Loader = &cx.editor.syn_loader.load();
let auto_pairs = doc.auto_pairs(cx.editor, loader, view);

let transaction = auto_pairs
.as_ref()
Expand Down Expand Up @@ -4320,11 +4323,12 @@ pub mod insert {
),
};

let loader: &helix_core::syntax::Loader = &cx.editor.syn_loader.load();
// If we are between pairs (such as brackets), we want to
// insert an additional line which is indented one level
// more and place the cursor there
let on_auto_pair = doc
.auto_pairs(cx.editor)
.auto_pairs(cx.editor, loader, view)
.and_then(|pairs| pairs.get(prev))
.is_some_and(|pair| pair.open == prev && pair.close == curr);

Expand Down Expand Up @@ -4412,7 +4416,9 @@ pub mod insert {
let text = doc.text().slice(..);
let tab_width = doc.tab_width();
let indent_width = doc.indent_width();
let auto_pairs = doc.auto_pairs(cx.editor);

let loader: &helix_core::syntax::Loader = &cx.editor.syn_loader.load();
let auto_pairs = doc.auto_pairs(cx.editor, loader, view);

let transaction =
Transaction::delete_by_selection(doc.text(), doc.selection(view.id), |range| {
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,7 @@ fn tree_sitter_layers(
bail!("Syntax information is not available");
};

let loader = cx.editor.syn_loader.load();
let loader: &helix_core::syntax::Loader = &cx.editor.syn_loader.load();
let text = doc.text().slice(..);
let cursor = doc.selection(view.id).primary().cursor(text);
let byte = text.char_to_byte(cursor) as u32;
Expand Down
22 changes: 17 additions & 5 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,12 @@ impl Document {
/// language config with auto pairs configured, returns that;
/// otherwise, falls back to the global auto pairs config. If the global
/// config is false, then ignore language settings.
pub fn auto_pairs<'a>(&'a self, editor: &'a Editor) -> Option<&'a AutoPairs> {
pub fn auto_pairs<'a>(
&'a self,
editor: &'a Editor,
loader: &'a syntax::Loader,
view: &View,
) -> Option<&'a AutoPairs> {
let global_config = (editor.auto_pairs).as_ref();

// NOTE: If the user specifies the global auto pairs config as false, then
Expand All @@ -2182,10 +2187,17 @@ impl Document {
}
}

match &self.language {
Some(lang) => lang.as_ref().auto_pairs.as_ref().or(global_config),
None => global_config,
}
self.syntax
.as_ref()
.and_then(|syntax| {
let selection = self.selection(view.id).primary();
let (start, end) = selection.into_byte_range(self.text().slice(..));
let layer = syntax.layer_for_byte_range(start as u32, end as u32);

let lang_config = loader.language(syntax.layer(layer).language).config();
lang_config.auto_pairs.as_ref()
})
.or(global_config)
}

pub fn snippet_ctx(&self) -> SnippetRenderCtx {
Expand Down
Loading