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

Execute rubocop via rubocop's server #246

Merged
merged 1 commit into from
Dec 11, 2023
Merged

Conversation

pjg
Copy link
Contributor

@pjg pjg commented Dec 11, 2023

This ensures a much quicker execution on 2nd and any subsequent run. Otherwise there's always a 1-3 seconds delay before formatting is being applied (as rubocop is not that quick).

From rubocop's documentation:

--server If a server process has not been started yet, start the server process and execute inspection with server.

(documentation)

I've tested it locally with custom defined formatter and it resulted in a much quicker execution on subsequent runs. Best if someone else also tested this to confirm my observations.

An even better approach would be to use the LSP server, but I'm not sure how to achieve that (specifying the --lsp option wipes the buffer on each conform run for me).

This ensures a much quicker execution on 2nd and any subsequent run. Otherwise there's always a 1-3 seconds delay before formatting is being applied (as rubocop is not that quick).

From rubocop's documentation:

```
--server If a server process has not been started yet, start the server process and execute inspection with server.
```
@stevearc
Copy link
Owner

LGTM. If you want to use the --lsp, then you wouldn't use conform at all. You would just follow the instructions at https://docs.rubocop.org/rubocop/usage/lsp.html#neovim-nvim-lspconfig

@stevearc stevearc merged commit 0ec6edd into stevearc:master Dec 11, 2023
8 checks passed
@pjg
Copy link
Contributor Author

pjg commented Dec 11, 2023

Thanks! As far as rubocop's usage via LSP is concerned, my use case is slightly more complicated as I'm using conform to run both rubyftm and rubocop, one after the other. And rubyfmt currently only on certain file patterns. Ideally I should use just one nvim plugin for the job, which would allow me to run formatters/linters sequentially (which conform.nvim does). In other words, I believe conform should also allow me to run rubocop via LSP as one of the options to run it.

When using two tools, both attaching to BufWritePre, I'm not sure I will be able to maintain correct order of execution, something which is crucial to me. I'll experiment with it, though.

@pjg
Copy link
Contributor Author

pjg commented Dec 13, 2023

After some trials and tribulations I was able to make it all work the way I want. First, rubyfmt is being executed by conform.nvim, and after it finishes (sync execution), the result is processed/formatted by rubocop via LSP.

References:

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.

None yet

2 participants