Skip to content

Conversation

@vitallium
Copy link
Contributor

@vitallium vitallium commented Jul 24, 2024

Hello, this pull request adds support for specifying and using the "binary" settings for Rubocop and Solargraph LSPs. AFAIK, Ruby LSP does not require the bundler context but that could be added later easily.

In Ruby world, like in Node.js world, almost all
projects rely on project specific packages (gems) and their versions. Solargraph and Rubocop gems are usually installed as project dependencies. Attempting to use global installation of them fail in most cases due to incompatible or missing dependencies (gems).

To avoid that, Ruby engineers have the bundler
gem that provides the exec command. This command executes the given command in the context of the bundle.

This pull request adds support for pulling the binary settings to use them in starting both LSPs. For instance, to start the Solargraph gem in the context of the bundler, the end user must configure the binary settings in the folder-specific settings file like so:

{
  "lsp": {
    "solargraph": {
      "binary": {
        "path": "/Users/vslobodin/Development/festivatica/bin/rubocop"
      }
    }
  }
}

The path key must be an absolute path to the binstub of the solargraph gem. The same applies to the "rubocop" gem. Side note but it would be awesome to use Zed specific environment variables to make this a bit easier. For instance, we could use the ZED_WORKTREE_ROOT environment variable:

{
  "lsp": {
    "solargraph": {
      "binary": {
        "path": "${ZED_WORKTREE_ROOT}/bin/rubocop"
      }
    }
  }
}

But this is out of the scope of this pull request. The code is a bit messy and repeatable in some places, I am happy to improve it here or later.

References:

This pull request is based on these two pull requests:

Closes #5109.

Release Notes:

  • N/A

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jul 24, 2024
@vitallium vitallium marked this pull request as ready for review July 24, 2024 18:55
@vitallium vitallium force-pushed the vs/ruby-support-binary-settings branch from 6017c6b to 1919b36 Compare July 24, 2024 19:09
@vitallium
Copy link
Contributor Author

Added documentation about using folder-specific settings and binary settings.

@maxdeviant maxdeviant self-assigned this Jul 24, 2024
@vitallium vitallium force-pushed the vs/ruby-support-binary-settings branch from 1919b36 to 5fb2ac0 Compare July 26, 2024 20:20
@vitallium
Copy link
Contributor Author

Rebased against the main branch.

@vitallium vitallium force-pushed the vs/ruby-support-binary-settings branch 3 times, most recently from 5fccd3d to a18d9ed Compare August 4, 2024 13:07
@vitallium
Copy link
Contributor Author

Okay, I think this pull request is ready for review.

In Ruby world, like in Node.js world, almost all
projects rely on project specific packages (gems) and
their versions. Solargraph and Rubocop gems are usually
installed as project dependencies. Attempting to use
global installation of them fail in most cases due
to incompatible or missing dependencies (gems).

To avoid that, Ruby engineers have the "bundler"
gem that provides the "exec" command. This command
executes the given command in the context of the bundle.

This pull request adds support for pulling the "binary"
settings to use them in starting both LSPs. For instance,
to start the Solargraph gem in the context of the bundler,
the end user must configure the binary settings in the folder-specific
settings file like so:

```json
{
  "lsp": {
    "solargraph": {
      "binary": {
        "path": "/Users/vslobodin/Development/festivatica/bin/rubocop"
      }
    }
  }
}
```

The "path" key must be an absolute path to the `binstub` of
the `solargraph` gem. The same applies to the "rubocop" gem.
Side note but it would be awesome to use Zed specific environment
variables to make this a bit easier. For instance, we could use
the `ZED_WORKTREE_ROOT` environment variable:

```json
{
  "lsp": {
    "solargraph": {
      "binary": {
        "path": "${ZED_WORKTREE_ROOT}/bin/rubocop"
      }
    }
  }
}
```

But this is out of the scope of this pull request. The code is a bit
messy and repeatable in some places, I am happy to improve it here or
later.

References:
- https://bundler.io/v2.4/man/bundle-exec.1.html
- https://solargraph.org/guides/troubleshooting
- https://bundler.io/v2.5/man/bundle-binstubs.1.html
@vitallium vitallium force-pushed the vs/ruby-support-binary-settings branch from a18d9ed to 87913ed Compare August 6, 2024 10:10
Copy link
Member

@maxdeviant maxdeviant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@maxdeviant maxdeviant merged commit 1c3f303 into zed-industries:main Aug 6, 2024
@vitallium vitallium mentioned this pull request Aug 6, 2024
@vitallium
Copy link
Contributor Author

Thanks!

Thank you for making the Ruby extension better than it was! I use that as an opportunity to learn something new.

@vitallium vitallium deleted the vs/ruby-support-binary-settings branch August 6, 2024 13:27
maxdeviant added a commit that referenced this pull request Aug 6, 2024
ruby: Bump extension version to v0.1.0 Why not v0.0.9? I think the Ruby
extension is mature, and it's time to release the first minor version.
But I am totally OK with changing it to 0.0.9.

Included changes:

- #15778
- #15762
- #15110
- #15297

Release Notes:

- N/A

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
notpeter pushed a commit to zed-extensions/ruby that referenced this pull request Oct 11, 2024
…zed#15110)

Hello, this pull request adds support for specifying and using the
"binary" settings for Rubocop and Solargraph LSPs. AFAIK, Ruby LSP does
not require the bundler context but that could be added later easily.

In Ruby world, like in Node.js world, almost all
projects rely on project specific packages (gems) and their versions.
Solargraph and Rubocop gems are usually installed as project
dependencies. Attempting to use global installation of them fail in most
cases due to incompatible or missing dependencies (gems).

To avoid that, Ruby engineers have the `bundler`
gem that provides the `exec` command. This command executes the given
command in the context of the bundle.

This pull request adds support for pulling the `binary` settings to use
them in starting both LSPs. For instance, to start the Solargraph gem in
the context of the bundler, the end user must configure the binary
settings in the folder-specific settings file like so:

```json
{
  "lsp": {
    "solargraph": {
      "binary": {
        "path": "/Users/vslobodin/Development/festivatica/bin/rubocop"
      }
    }
  }
}
```

The `path` key must be an absolute path to the `binstub` of the
`solargraph` gem. The same applies to the "rubocop" gem. Side note but
it would be awesome to use Zed specific environment variables to make
this a bit easier. For instance, we could use the `ZED_WORKTREE_ROOT`
environment variable:

```json
{
  "lsp": {
    "solargraph": {
      "binary": {
        "path": "${ZED_WORKTREE_ROOT}/bin/rubocop"
      }
    }
  }
}
```

But this is out of the scope of this pull request. The code is a bit
messy and repeatable in some places, I am happy to improve it here or
later.

References:
- https://bundler.io/v2.4/man/bundle-exec.1.html
- https://solargraph.org/guides/troubleshooting
- https://bundler.io/v2.5/man/bundle-binstubs.1.html

This pull request is based on these two pull requests:

- zed-industries/zed#14655
- zed-industries/zed#15001

Closes zed-industries/zed#5109.

Release Notes:

- N/A

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
notpeter pushed a commit to zed-extensions/ruby that referenced this pull request Oct 11, 2024
Bump extension version to v0.1.0 Why not v0.0.9? I think the Ruby
extension is mature, and it's time to release the first minor version.
But I am totally OK with changing it to 0.0.9.

Included changes:

- zed-industries/zed#15778
- zed-industries/zed#15762
- zed-industries/zed#15110
- zed-industries/zed#15297

Release Notes:

- N/A

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When starting SolarGraph, try to respect project-specific installation

2 participants