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

Add RuboCop built-in launguage server for linting Ruby code #4090

Merged
merged 1 commit into from
Aug 21, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
* Add AWK language server support.
* Add support for ~scala-ts-mode~.
* Drop support for emacs 26.3
* Add [https://github.com/rubocop/rubocop][RuboCop built-in language server]] for linting and formatting Ruby code.
** Release 8.0.0
* Add ~lsp-clients-angular-node-get-prefix-command~ to get the Angular server from another location which is still has ~/lib/node_modules~ in it.
* Set ~lsp-clients-angular-language-server-command~ after the first connection to speed up subsequent connections.
Expand Down
66 changes: 66 additions & 0 deletions clients/lsp-rubocop.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
;;; lsp-rubocop.el --- lsp-mode for RuboCop -*- lexical-binding: t; -*-

;; Copyright (C) 2023 Koichi Ito

;; Author: Koichi Ito <[email protected]>
;; Keywords: lsp, ruby, languages

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; LSP client for RuboCop which is a Ruby static code analyzer (a.k.a. linter)
;; and code formatter.

;;; Code:

(require 'lsp-mode)

(defgroup lsp-rubocop nil
"LSP support for RuboCop, using the RuboCop built-in language server."
:group 'lsp-mode
:link '(url-link "https://github.com/rubocop/rubocop")
:package-version '(lsp-mode . "8.0.1"))

(defcustom lsp-rubocop-use-bundler nil
"Run RuboCop using Bundler."
:type 'boolean
:safe #'booleanp
:group 'lsp-rubocop
:package-version '(lsp-mode . "8.0.1"))

(defcustom lsp-rubocop-server-path nil
"Path of the RuboCop built-in language server executable.
If specified, `lsp-rubocop-use-bundler' is ignored."
:type 'file
:group 'lsp-rubocop
:package-version '(lsp-mode . "8.0.1"))

(defun lsp-rubocop--build-command ()
"Build a command to start the RuboCop built-in language server."
(append
(if (and lsp-rubocop-use-bundler (not lsp-rubocop-server-path)) '("bundle" "exec"))
(list (or lsp-rubocop-server-path "rubocop") "--lsp")))

(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection #'lsp-rubocop--build-command)
:activation-fn (lsp-activate-on "ruby")
:priority -1
:server-id 'rubocop-ls))

(lsp-consistency-check lsp-rubocop)

(provide 'lsp-rubocop)
;;; lsp-rubocop.el ends here
9 changes: 9 additions & 0 deletions docs/lsp-clients.json
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,15 @@
"installation": "npm i -g remark-language-server",
"debugger": "Not available"
},
{
"name": "robocop",
"full-name": "Ruby (RuboCop)",
"server-name": "rubocop",
"server-url": "https://github.com/rubocop/rubocop",
"installation-url": "https://docs.rubocop.org/rubocop/installation.html",
"installation": "gem install rubocop",
"debugger": "Not available"
},
{
"name": "robot",
"full-name": "robot framework",
Expand Down
4 changes: 2 additions & 2 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ As defined by the Language Server Protocol 3.16."
lsp-lua lsp-markdown lsp-marksman lsp-mint lsp-nginx lsp-nim lsp-nix lsp-magik
lsp-metals lsp-mssql lsp-ocaml lsp-openscad lsp-pascal lsp-perl lsp-perlnavigator
lsp-pls lsp-php lsp-pwsh lsp-pyls lsp-pylsp lsp-pyright lsp-python-ms lsp-purescript
lsp-r lsp-racket lsp-remark lsp-ruff-lsp lsp-rf lsp-rust lsp-semgrep lsp-shader lsp-solargraph
lsp-sorbet lsp-sourcekit lsp-sonarlint lsp-tailwindcss lsp-tex lsp-terraform
lsp-r lsp-racket lsp-remark lsp-ruff-lsp lsp-rf lsp-rubocop lsp-rust lsp-semgrep lsp-shader
lsp-solargraph lsp-sorbet lsp-sourcekit lsp-sonarlint lsp-tailwindcss lsp-tex lsp-terraform
lsp-toml lsp-ttcn3 lsp-typeprof lsp-v lsp-vala lsp-verilog lsp-vetur lsp-volar
lsp-vhdl lsp-vimscript lsp-xml lsp-yaml lsp-ruby-lsp lsp-ruby-syntax-tree
lsp-sqls lsp-svelte lsp-steep lsp-tilt lsp-zig)
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ nav:
- R: page/lsp-r.md
- Racket (jeapostrophe): page/lsp-racket-langserver.md
- Racket (Theia): page/lsp-racket-language-server.md
- Ruby (RuboCop): page/lsp-rubocop.md
- Ruby (ruby-lsp): page/lsp-ruby-lsp.md
- Ruby (Solargraph): page/lsp-solargraph.md
- Ruby (Sorbet): page/lsp-sorbet.md
Expand Down
Loading