Skip to content

Commit 4df5ddf

Browse files
vinistockAndy Waite
andauthored
Document custom bundle process (#2615)
* Document custom bundle process * Apply suggestions from code review Co-authored-by: Andy Waite <andy.waite@shopify.com> * Rename custom to composed bundle --------- Co-authored-by: Andy Waite <andy.waite@shopify.com>
1 parent f5f4446 commit 4df5ddf

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

jekyll/composed-bundle.markdown

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
layout: default
3+
title: Composed Ruby LSP bundle
4+
nav_order: 40
5+
parent: Ruby LSP
6+
---
7+
8+
# Composed Ruby LSP bundle
9+
10+
In language ecosystems other than Ruby, it is not super common to have to add editor tooling as part of your project
11+
dependencies. Usually, a language server is an executable that gets downloaded and then run independently from your
12+
projects.
13+
14+
In the Ruby ecosystem, there are a few blockers to fully adopting this approach:
15+
16+
1. Not writing the language server in Ruby would make it challenging to integrate seamlessly with existing tools used by
17+
the community that are already written in Ruby, like test frameworks, linters, formatters and so on
18+
2. Discovering project dependencies automatically allows the language server to detect which files on disk must be read
19+
and indexed, so that we can extract declarations from gems without requiring any configuration from the user. This means
20+
that we need to integrate directly with Bundler
21+
3. Bundler only allows requiring gems that are set up as part of the `$LOAD_PATH`. If the Ruby LSP executable was running
22+
independently from a global installation, then the Ruby process would only be able to require the Ruby LSP's own
23+
dependencies, but it would not be able to require any gems used by the project being worked on. Not being able to require
24+
the project's dependencies limits integrations that the language server can automatically make with linters, formatters,
25+
test frameworks and so on
26+
27+
To overcome these limitations, while at the same time not requiring users to add `ruby-lsp` as a dependency of their projects,
28+
the Ruby LSP uses a composed bundle strategy. The flow of execution is as follows:
29+
30+
1. The executable is run as `ruby-lsp` without `bundle exec` to indicate that the composed bundle must first be configured
31+
2. The executable sets up a composed bundle under `your_project/.ruby-lsp`. The generated Gemfile includes the `ruby-lsp` gem
32+
and everything in the project's Gemfile as well. It may also include `debug` and `ruby-lsp-rails`
33+
3. After the composed bundle is fully set up, then the original `ruby-lsp` Ruby process is fully replaced by
34+
`BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle exec ruby-lsp`, thus launching the real language server with access to the project's
35+
dependencies, but without requiring adding the gem to the project's own Gemfile
36+
37+
In addition to performing this setup, the composed bundle logic will also `bundle install` and attempt to auto-update
38+
the `ruby-lsp` language server gem to ensure fast distribution of bug fixes and new features.
39+
40+
{: .note }
41+
Setting up the composed bundle requires several integrations with Bundler and there are many edge cases to consider,
42+
like how to handle configurations or installing private dependencies. If you encounter a problem with the composed
43+
bundle setup, please let us know by [reporting an issue](https://github.com/Shopify/ruby-lsp/issues/new).

jekyll/index.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Want to discuss Ruby developer experience? Consider joining the public
2222
- [Usage](#usage)
2323
- [With VS Code](#with-vs-code)
2424
- [With other editors](#with-other-editors)
25+
- [Composed Ruby LSP bundle](#composed-ruby-lsp-bundle)
2526
- [Add-ons](#add-ons)
2627
- [General features](#general-features)
2728
- [Hover](#hover)
@@ -80,6 +81,11 @@ gem install ruby-lsp
8081
and the language server can be launched running `ruby-lsp` (without bundle exec in order to properly hook into your
8182
project's dependencies).
8283

84+
### Composed Ruby LSP bundle
85+
86+
The Ruby LSP executable generates a composed bundle with the goal of not requiring users to add the `ruby-lsp` gem to
87+
their Gemfiles, and at the same time being able to hook into project dependencies. [Learn more](composed-bundle).
88+
8389
## Add-ons
8490

8591
The Ruby LSP provides an add-on system that allows other gems to enhance the base functionality with more editor

0 commit comments

Comments
 (0)