Compare commits

...

5 Commits

Author SHA1 Message Date
Yuki Kobayashi 8c5dd7f0c3
Merge 52696de6de into 395a71bf53 2025-07-24 07:35:57 +00:00
kiara 395a71bf53
languages: nix formatter (#14046) 2025-07-23 12:51:17 -04:00
Ian Hobson 1e4bf6704a
Update Koto grammar and queries, add formatter (#14049) 2025-07-23 12:47:47 -04:00
aster 52696de6de feat: auto-pair triple quotes 2025-06-16 13:55:03 +09:00
aster d1ad8a2fe9 feat: handle triple quotes in auto-pairs correctly 2025-06-06 17:50:10 +09:00
4 changed files with 39 additions and 16 deletions

View File

@ -335,17 +335,37 @@ fn handle_close(doc: &Rope, selection: &Selection, pair: &Pair) -> Transaction {
/// handle cases where open and close is the same, or in triples ("""docstring""") /// handle cases where open and close is the same, or in triples ("""docstring""")
fn handle_same(doc: &Rope, selection: &Selection, pair: &Pair) -> Transaction { fn handle_same(doc: &Rope, selection: &Selection, pair: &Pair) -> Transaction {
let mut end_ranges = SmallVec::with_capacity(selection.len()); let mut end_ranges = SmallVec::with_capacity(selection.len());
let mut offs = 0; let mut offs = 0;
let transaction = Transaction::change_by_selection(doc, selection, |start_range| { let transaction = Transaction::change_by_selection(doc, selection, |start_range| {
let cursor = start_range.cursor(doc.slice(..)); let cursor = start_range.cursor(doc.slice(..));
let mut len_inserted = 0; let mut len_inserted = 0;
let has_at_least_two_before = cursor >= 2
&& doc.get_char(cursor - 1) == Some(pair.open)
&& doc.get_char(cursor - 2) == Some(pair.open);
let has_at_least_three_before =
has_at_least_two_before && cursor >= 3 && doc.get_char(cursor - 3) == Some(pair.open);
let next_char = doc.get_char(cursor); let next_char = doc.get_char(cursor);
let change = if next_char == Some(pair.open) { // (from, to, replacement)
// return transaction that moves past close let change = if next_char == Some(pair.close) {
(cursor, cursor, None) // no-op // moves past close
(cursor, cursor, None) // no-op - don't insert char
} else if has_at_least_three_before {
// don't auto pair more than triple quotes
(cursor, cursor, Some(Tendril::from_iter([pair.close]))) // only insert one char (normal operation)
} else if has_at_least_two_before {
// exactly two before: auto-pair 3 quotes
// `''|` -> `'''|'''`
(
cursor,
cursor,
Some(Tendril::from_iter([
// first is the default keystroke, the rest 3 are auto-pair
pair.close, pair.close, pair.close, pair.close,
])),
)
} else { } else {
let mut pair_str = Tendril::new(); let mut pair_str = Tendril::new();
pair_str.push(pair.open); pair_str.push(pair.open);

View File

@ -1022,6 +1022,7 @@ shebangs = []
comment-token = "#" comment-token = "#"
language-servers = [ "nil", "nixd" ] language-servers = [ "nil", "nixd" ]
indent = { tab-width = 2, unit = " " } indent = { tab-width = 2, unit = " " }
formatter = { command = "nixfmt" }
[[grammar]] [[grammar]]
name = "nix" name = "nix"
@ -4243,10 +4244,11 @@ comment-token = "#"
block-comment-tokens = ["#-", "-#"] block-comment-tokens = ["#-", "-#"]
indent = { tab-width = 2, unit = " " } indent = { tab-width = 2, unit = " " }
language-servers = ["koto-ls"] language-servers = ["koto-ls"]
formatter = {command = "koto", args = ["--format"]}
[[grammar]] [[grammar]]
name = "koto" name = "koto"
source = { git = "https://github.com/koto-lang/tree-sitter-koto", rev = "b420f7922d0d74905fd0d771e5b83be9ee8a8a9a" } source = { git = "https://github.com/koto-lang/tree-sitter-koto", rev = "2ffc77c14f0ac1674384ff629bfc207b9c57ed89" }
[[language]] [[language]]
name = "gpr" name = "gpr"

View File

@ -5,11 +5,13 @@
"*" "*"
"/" "/"
"%" "%"
"^"
"+=" "+="
"-=" "-="
"*=" "*="
"/=" "/="
"%=" "%="
"^="
"==" "=="
"!=" "!="
"<" "<"
@ -99,12 +101,18 @@
(export (export
(identifier) @namespace) (identifier) @namespace)
(call (chain
function: (identifier) @function.method) start: (identifier) @function)
(chain (chain
lookup: (identifier) @variable.other.member) lookup: (identifier) @variable.other.member)
(call
function: (identifier)) @function
(call_arg
(identifier) @variable.other.member)
[ [
(true) (true)
(false) (false)
@ -139,13 +147,10 @@
(self) @variable.builtin (self) @variable.builtin
(variable (type
type: (identifier) @type) _ @type)
(arg (arg
(_ (identifier) @variable.parameter)) (_ (identifier) @variable.parameter))
(ellipsis) @variable.parameter (ellipsis) @variable.parameter
(function
output_type: (identifier) @type)

View File

@ -11,10 +11,6 @@
(call_args (call_args
((call_arg) @parameter.inside . ","? @parameter.around) @parameter.around) ((call_arg) @parameter.inside . ","? @parameter.around) @parameter.around)
(chain
call: (tuple
((element) @parameter.inside . ","? @parameter.around) @parameter.around))
(map (map
((entry_inline) @entry.inside . ","? @entry.around) @entry.around) ((entry_inline) @entry.inside . ","? @entry.around) @entry.around)