Skip to content

Commit

Permalink
Set custom program name for the built-in LSP server
Browse files Browse the repository at this point in the history
This PR sets custom program name for the built-in LSP server.

Before:

```console
$ ps aux | grep rubocop
user  17414  0.0  0.2  5557716 144376  ??  Ss  4:48PM  0:02.13 /Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/bin/rubocop --lsp
```

After:

```console
$ ps aux | grep 'rubocop'
user  17414  0.0  0.2  5557716 144376  ??  Ss  4:48PM  0:02.13 rubocop --lsp /Users/user/src/github.com/rubocop/rubocop
```

When searching for the LSP server process, it is helpful to display the path to the project root instead of the Ruby command path.
This approach is already being implemented in server mode:
https://github.com/rubocop/rubocop/blob/v1.63.2/lib/rubocop/server/core.rb#L31
  • Loading branch information
koic authored and bbatsov committed Apr 19, 2024
1 parent dd47fa8 commit 74037d9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
@@ -0,0 +1 @@
* [#12855](https://github.com/rubocop/rubocop/pull/12855): Set custom program name for the built-in LSP server. ([@koic][])
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/usage/lsp.adoc
Expand Up @@ -254,8 +254,8 @@ Run `rubocop --lsp` command from LSP client.
When the language server is started, the command displays the language server's PID:

```console
$ ps aux | grep rubocop
user 17414 0.0 0.2 5557716 144376 ?? Ss 4:48PM 0:02.13 /Users/user/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/bin/rubocop --lsp
$ ps aux | grep 'rubocop --lsp'
user 17414 0.0 0.2 5557716 144376 ?? Ss 4:48PM 0:02.13 rubocop --lsp /Users/user/src/github.com/rubocop/rubocop
```

NOTE: `rubocop --lsp` is for starting LSP client, so users don't manually execute it.
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/lsp/server.rb
Expand Up @@ -21,6 +21,8 @@ module LSP
# @api private
class Server
def initialize(config_store)
$PROGRAM_NAME = "rubocop --lsp #{ConfigFinder.project_root}"

RuboCop::LSP.enable

@reader = LanguageServer::Protocol::Transport::Io::Reader.new($stdin)
Expand Down

0 comments on commit 74037d9

Please sign in to comment.