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

Specifically handle the case where bin/rails is not found #284

Merged
merged 3 commits into from
Mar 8, 2024

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Mar 8, 2024

When the file is not found, it is likely that the LSP is not being run in the root of a Rails project. Having a more specific error message will help the user understand what is going on.

@st0012 st0012 added the bugfix This PR fixes an existing bug label Mar 8, 2024
@st0012 st0012 requested a review from a team as a code owner March 8, 2024 09:14
@st0012 st0012 requested review from egiurleo and KaanOzkan March 8, 2024 09:14
@st0012 st0012 force-pushed the improve-error-message branch from b39b61d to 529f22e Compare March 8, 2024 09:16
@andyw8
Copy link
Contributor

andyw8 commented Mar 8, 2024

I was working on this approach in ruby-lsp, so that if the app doesn't have bin/rails then we don't install the addon: Shopify/ruby-lsp#1467.

Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

In regards to installing the addon or not, at the root of it is the question "is there value in having this addon even if it's not a Rails app?".

I think the answer might be yes because of the code lens support for Active Support style tests. But I'm not 100% sure to be honest. Thoughts?

lib/ruby_lsp/ruby_lsp_rails/runner_client.rb Outdated Show resolved Hide resolved
@@ -12,7 +12,15 @@ class << self

sig { returns(RunnerClient) }
def create_client
new
if File.exist?("bin/rails")
Copy link
Member

Choose a reason for hiding this comment

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

This will fail in workspace that are symlinks, since the addons don't yet have access to the workspace URI announced by the editor. There's nothing to do now, but I wanted to document this.

We need to create some sort of State object in the Ruby LSP that addons get initialized with, containing all of the initialization options, the message queue, etc.

@st0012
Copy link
Member Author

st0012 commented Mar 8, 2024

I think the answer might be yes because of the code lens support for Active Support style tests. But I'm not 100% sure to be honest. Thoughts?

In addition to those, once we implemented something like go-to-definition to DSL symbols, like

before_save :foo # cmd+click :foo jumps to foo method

Then it'll be useful in Rails engine development too.
And if we decided to support customising test code lens' executable name (e.g. bin/test instead of bin/rails test), it can directly benefit rails/rails and Rails engine devs too.

@andyw8
Copy link
Contributor

andyw8 commented Mar 8, 2024

In regards to installing the addon or not, at the root of it is the question "is there value in having this addon even if it's not a Rails app?".

I think the answer might be yes because of the code lens support for Active Support style tests. But I'm not 100% sure to be honest. Thoughts?

One confusing aspect is that you'd always end up ruby-lsp-rails in .ruby-lsp/Gemfile even for a plain Rails app that doesn't use Active Support tests.

Perhaps we can treat rails/rails as a special case and install ruby-lsp-rails, and for other repos have some option in the upcoming .ruby-lsp.yml to opt in?

@vinistock
Copy link
Member

Perhaps we can treat rails/rails as a special case and install ruby-lsp-rails, and for other repos have some option in the upcoming .ruby-lsp.yml to opt in?

I feel like it might be early to make that decision. IMO, we can go with this PR and make a decision once we have more context.

.rubocop.yml Outdated
@@ -35,6 +35,3 @@ Sorbet/StrictSigil:
Exclude:
- "**/*.rake"
- "test/**/*.rb"

Copy link
Contributor

Choose a reason for hiding this comment

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

Being removed in #285

@andyw8
Copy link
Contributor

andyw8 commented Mar 8, 2024

Interesting, got a failure CI because on Ubuntu the error looks like:

Ruby LSP Rails booting server\nRuby LSP Rails failed to initialize server: bin/rails: 1: foo: not found
but on other platforms:
Ruby LSP Rails booting server\nRuby LSP Rails failed to initialize server: bin/rails: line 1: foo: not found

@andyw8 andyw8 force-pushed the improve-error-message branch 2 times, most recently from 98b1de8 to b2419cc Compare March 8, 2024 18:47
st0012 and others added 3 commits March 8, 2024 13:48
When the file is not found, it is likely that the LSP is not being run in
the root of a Rails project. Having a more specific error message will
help the user understand what is going on.
@andyw8 andyw8 force-pushed the improve-error-message branch from b2419cc to a4b498a Compare March 8, 2024 18:48
@andyw8 andyw8 merged commit 5d9f3c4 into main Mar 8, 2024
54 checks passed
@andyw8 andyw8 deleted the improve-error-message branch March 8, 2024 18:59
@andyw8 andyw8 mentioned this pull request Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants