fables-tales / rubyfmt

Ruby Autoformatter!
MIT License
1.08k stars 50 forks source link

ruby-lsp integration for rubyfmt #446

Open pjg opened 1 year ago

pjg commented 1 year ago

I've been looking for a way to integrate rubyfmt with my ruby-lsp vim (via coc.nvim), but was unable to do so.

Rubocop integration in coc-settings.json works perfectly as ruby-lsp provides integration with it by default:

  "languageserver": {
    "ruby-lsp": {
      "command": "ruby-lsp",
      "initializationOptions": {
        "formatter": "auto" // will use rubocop (if installed) or falls back to syntax_tree
      },
      "filetypes": ["ruby"]
    }
  },

I think something like ruby-lsp-rubyfmt would be necessary to integrate with ruby-lsp in vim. I don't think such project exists. Also my hope is that I can configure multiple formatters with different priorities, so that I can run rubyfmt first, and then/afterwards rubocop (or standardrb).

Also I'm coming to a realisation that rubyfmt will probably never support/read rubocop's (or standard's) config (https://github.com/fables-tales/rubyfmt/issues/445).

Edit: I've found similar request in vscode-ruby-lsp repo: https://github.com/Shopify/ruby-lsp/issues/1740

pjg commented 10 months ago

FWIW I was able to use conform.nvim to run rubyfmt, and then an AutoCmd to run rubocop via LSP on rubyfmt's results. Reference: https://github.com/pjg/dotfiles/commit/2d6c577cba8ea0cd1f7e931489354b2e3097d1c0

jscharf commented 10 months ago

I think something like ruby-lsp-rubyfmt would be necessary to integrate with ruby-lsp in vim. I don't think such project exists.

Hey @pjg! I stumbled across this issue recently and wanted to let you know that I've created a such a project, for bridging these technologies together. https://github.com/jscharf/ruby-lsp-rubyfmt

If you have any feedback for me or if you have time to test it out to make sure it works for you, I would really appreciate it.

I initially wanted to do this around December 2022 and asked in the Ruby LSP project here https://github.com/Shopify/ruby-lsp/issues/409