Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Compile parsers
run: |
nvim --headless -c "TSInstallSync ruby python lua javascript julia yaml sql r" -c "q"
nvim --headless -c "TSInstallSync ruby python lua javascript julia yaml sql r rust" -c "q"
- name: Tests
env:
ci: "1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ Builtin actions are all higher-order functions so they can easily have options o
| `cycle_case()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | ✅ | ✅ |
| `cycle_quotes()` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | ✅ |
| `toggle_multiline()` | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | |
| `toggle_operator()` | | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | ✅ |
| `toggle_operator()` | | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | ✅ |
| `toggle_int_readability()` | | ✅ | ✅ | | ✅ | ✅ | ✅ | ✅ | | | |
| `toggle_block()` | | ✅ | | | | | | | | | |
| if/else <-> ternery | | ✅ | | | ✅ | | | | | | |
Expand Down
100 changes: 82 additions & 18 deletions lua/ts-node-action/filetypes/rust.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,90 @@
local actions = require("ts-node-action.actions")

local operators = {
-- assignment
["+="] = "-=",
["-="] = "+=",
["%="] = "/=",
["/="] = "%=",
-- bitwise assignment
["&="] = "|=",
["|="] = "^=",
["^="] = "&=",
-- comparison
["!="] = "==",
["=="] = "!=",
[">"] = "<",
["<"] = ">",
[">="] = "<=",
["<="] = ">=",
-- shift
["<<"] = ">>",
[">>"] = "<<",
-- shift assignment
[">>="] = "<<=",
["<<="] = ">>=",
-- arithmetic
["+"] = "-",
["-"] = "+",
["*"] = "/",
["/"] = "*",
-- bitwise
["|"] = "&",
["&"] = "|",
-- logical
["||"] = "&&",
["&&"] = "||",
}

local padding = {
["{"] = "%s ",
["}"] = {
" %s",
["{"] = "%s",
[","] = "%s",
[";"] = "%s",
["prev_nil"] = "%s",
},
["let"] = "%s ",
["as"] = " %s ",
["in"] = { " %s ", ["prev_nil"] = "%s ", },
["="] = " %s ",
[":"] = "%s ",
[";"] = "%s ",
[","] = "%s ",
}
local padding_use_list = {
["{"] = "%s",
["}"] = "%s",
[","] = "%s ",
[":"] = "%s ",
["{"] = "%s ",
["=>"] = " %s ",
["="] = " %s ",
["}"] = " %s",
["+"] = " %s ",
["-"] = " %s ",
["*"] = " %s ",
["/"] = " %s ",
}

local uncollapsible = {
["string_literal"] = true,
["let_declaration"] = true,
["reference_type"] = true,
["reference_expression"] = true,
["type_case_expression"] = true,
["macro_invocation"] = true,
["macro"] = true,
["for_expression"] = true,
["range_expression"] = true,
["line_comment"] = true,
}

return {
["field_declaration_list"] = actions.toggle_multiline(padding),
["parameters"] = actions.toggle_multiline(padding),
["enum_variant_list"] = actions.toggle_multiline(padding),
["block"] = actions.toggle_multiline(padding),
["array_expression"] = actions.toggle_multiline(padding),
["tuple_expression"] = actions.toggle_multiline(padding),
["tuple_pattern"] = actions.toggle_multiline(padding),
["boolean_literal"] = actions.toggle_boolean(),
["integer_literal"] = actions.toggle_int_readability(),
["boolean_literal"] = actions.toggle_boolean(),
["integer_literal"] = actions.toggle_int_readability(),
["binary_expression"] = actions.toggle_operator(operators),
["compound_assignment_expr"] = actions.toggle_operator(operators),
["use_list"] = actions.toggle_multiline(padding_use_list, uncollapsible),
["block"] = actions.toggle_multiline(padding, uncollapsible),
["parameters"] = actions.toggle_multiline(padding, uncollapsible),
["arguments"] = actions.toggle_multiline(padding, uncollapsible),
["array_expression"] = actions.toggle_multiline(padding, uncollapsible),
["tuple_expression"] = actions.toggle_multiline(padding, uncollapsible),
["tuple_pattern"] = actions.toggle_multiline(padding, uncollapsible),
["enum_variant_list"] = actions.toggle_multiline(padding, uncollapsible),
["field_initializer_list"] = actions.toggle_multiline(padding, uncollapsible),
["field_declaration_list"] = actions.toggle_multiline(padding, uncollapsible),
}
Loading