Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add refactorex (Elixir refactoring) #8368

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

synic
Copy link

@synic synic commented Dec 29, 2024

Describe your changes

Add RefactorEx refactoring LSP for Elixir

RefactorEx is an LSP server that allows for refactoring Elixir code. It adds the ability to rename symbols via vim.lsp.buf.rename() and various code actions.

Checklist before requesting a review

  • I have successfully tested installation of the package.
  • I have successfully tested the package after installation.

[RefactorEx](https://github.com/gp-pereira/refactorex) is an LSP server
that allows for refactoring Elixir code. It adds the ability to rename
symbols via `vim.lsp.buf.rename()` and various code actions.

Tested with the following code:

```lua
require("lspconfig.configs").refactorex = {
	default_config = {
		cmd = { vim.fn.stdpath("data") .. "/mason/bin/refactorex", "--stdio" },
		filetypes = { "elixir" },
		root_dir = function(fname)
			return require("lspconfig").util.root_pattern("mix.exs")(fname)
		end,
		settings = {},
		capabilities = {
			textDocumentSync = {
				openClose = true,
				change = 1,
				save = { includeText = true },
			},
			codeActionProvider = {
				resolveProvider = true,
			},
			renameProvider = {
				prepareProvider = true,
			},
		},
	},
}

require("lspconfig").refactorex.setup({})
```

Originally I had the build section like this:

```yaml
source:
  # renovate:datasource=github-tags
  id: pkg:github/gp-pereira/[email protected]
  build:
    run: |
      mix deps.get
      mix compile
```

However, it would never run `mix compile`, that step was always just skipped.
Not sure why.
@williambotman williambotman requested a review from a team December 29, 2024 10:53
synic added a commit to synic/refactorex that referenced this pull request Dec 29, 2024
I think I figured out how it's supposed to work without adding
additional scripts or worrying about passed arguments.

The mason-registry submission is here: mason-org/mason-registry#8368

Once refactorex is installed with mason, it can be configured using the
following code:

```lua
require("lspconfig.configs").refactorex = {
  default_config = {
    cmd = { vim.fn.stdpath("data") .. "/mason/bin/refactorex", "--stdio" },
    filetypes = { "elixir" },
    root_dir = function(fname)
      return require("lspconfig").util.root_pattern("mix.exs")(fname)
    end,
    settings = {},
    capabilities = {
      textDocumentSync = {
        openClose = true,
        change = 1,
        save = { includeText = true },
      },
      codeActionProvider = {
        resolveProvider = true,
      },
      renameProvider = {
        prepareProvider = true,
      },
    },
  },
}

require("lspconfig").refactorex.setup({})
```

As you can see, the `cmd` has the `--stdio` argument. Mason's job is
mainly just to install the language server, not to actually say what
will be done with it.

For maximum ease, once it is accepted in Mason, we will need to also
submit it to https://github.com/williamboman/mason-lspconfig.nvim,
similar to how nextls has done it here:
https://github.com/williamboman/mason-lspconfig.nvim/blob/main/lua/mason-lspconfig/server_configurations/nextls/init.lua

```lua
return function()
  return {
    cmd = { "nextls", "--stdio" },
  }
end
```

So, mason is just to install the language server, mason-lspconfig is
what provides the easy-to-use lsp configuration. Until it's accepted in
`mason-lspconfig`, your friends can use the snippet above to get it
working (once it's accepted to mason itself).

Until it's accepted in mason, they can just use this plugin:
https://github.com/synic/refactorex.nvim - it just downloads the
refactorex source code to a local directory and runs it from there.
Seems to work just fine.
@synic synic changed the title feat: add refactorex feat: add refactorex (Elixir refactoring) Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant