ha100 / thor.nvim

A plugin to help me with frequent refactorings of Swift code.
MIT License
1 stars 0 forks source link

thor.nvim

Swift refactorings hammer

Table of Contents

✨ Features

📦 Installation

Requirements

treesitter - to extract code via AST
sourcery - to automatically update swift type initializer after type properties have changed

Setup Using Lazy

return {
    dir = "https://github.com/ha100/thor.nvim",
    ft = "swift",
    lazy = true,
    dependencies = {
        "nvim-treesitter/nvim-treesitter"
    },
    config = function()
        require("thor").setup({
            anotate = true,
            templates = {
                {
                    file = "Package.swift",
                    from = "dependencies",
                    to = "deps",
                    type = "[Package.Dependency]"
                },
                {
                    file = "Package.swift",
                    from = "targets",
                    to = "targets",
                    type = "[Target]"
                }
            }
        })
    end,
    keys = {
        vim.keymap.set("v", "<leader>ref", ":Thor extract2file<cr>", { desc = "Extract code to file" }),
        vim.keymap.set("v", "<leader>rev", ":Thor extract2variable<cr>", { desc = "Extract code to variable" }),
        vim.keymap.set("v", "<leader>rtp", ":Thor togglePublic<cr>", { desc = "Toggle private/public visibility" }),
        vim.keymap.set("n", "<leader>rpi", ":Thor update_init<cr>", { desc = "recreate public init for current file" })
    },
}

🛠️ Lint

PRs are checked with the following software:

To run the linter locally:

$ make lint

To install tools run:

$ make install-dev