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

Check if solargraph is already installed and in $PATH in project dir #9811

Closed
1 task done
odedharth opened this issue Mar 26, 2024 · 14 comments · Fixed by #10835
Closed
1 task done

Check if solargraph is already installed and in $PATH in project dir #9811

odedharth opened this issue Mar 26, 2024 · 14 comments · Fixed by #10835
Assignees
Labels
defect [core label] language server An umbrella label for all language servers language An umbrella label for all programming languages syntax behaviors ruby Ruby programming language support

Comments

@odedharth
Copy link

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

Autocomplete works for certain files like JS for example, but doesn't work at all for Ruby files.
See here: https://www.loom.com/share/5dc993f5cba24413b43b350c0d0a6d19

Environment

Zed: v0.127.5 (Zed)
OS: macOS 14.4.1
Memory: 64 GiB
Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No response

@odedharth odedharth added admin read Pending admin review defect [core label] triage Maintainer needs to classify the issue labels Mar 26, 2024
@JosephTLyons JosephTLyons added ruby Ruby programming language support language An umbrella label for all programming languages syntax behaviors language server An umbrella label for all language servers and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Mar 26, 2024
@JosephTLyons
Copy link
Contributor

Hey @odedharth, I think our implementation of Ruby currently expects you to install solargraph manually. I'm not sure what situation we ran into that caused us to make that decision, but here are the docs on it:

https://zed.dev/docs/ruby

Let me know if you get it up and running.

Just to mention it, @mrnugget has a PR open that switches us over to ruby-lsp:

@JosephTLyons JosephTLyons added the needs info / awaiting response Issue that needs more information from the user label Mar 26, 2024
@odedharth
Copy link
Author

Hey @JosephTLyons,

Yes, the issue is that I already have solargraph installed. It used to work in the past and seems to have gotten broken in one of the last versions.

@mrnugget
Copy link
Member

@odedharth can you paste the language server logs (debug: open language server logs) right after it starts up? The only recent change I can think of is this #9170 which should provide more completions.

On latest Zed stable version it works for me. In the case of DateTime I had to first require 'date':

screenshot-2024-03-27-09.16.31.mp4

@odedharth
Copy link
Author

@mrnugget sure, that's what I'm seeing there after startup:

Screenshot at Mar 27 10-46-52

And when I require 'date', it still doesn't do anything.

@mrnugget
Copy link
Member

Can you select solargraph where it says copilot in your screenshot?

@odedharth
Copy link
Author

@mrnugget, it's not showing as an option (even though the gem is installed)
Screenshot at Mar 27 18-22-10

@mrnugget
Copy link
Member

Huh! Interesting! That means it didn't even start yet.

Can you paste the logs from ~/Library/Logs/Zed/Zed.log right after you open a Ruby file?

@odedharth
Copy link
Author

@mrnugget sure, here is the log file:

Zed.log

@mrnugget
Copy link
Member

It looks like solargraph is installed with a different version than the one you're using in your projects:

2024-03-13T17:04:02+02:00 [ERROR] server stderr: Some("rbenv: version `3.1.3' is not installed (set by /Users/odedharth/Documents/Apps/Rails/MDAcne/.ruby-version)\n")
...
2024-03-13T17:04:08+02:00 [ERROR] server stderr: Some("rbenv: version `2.6.10' is not installed (set by /Users/odedharth/Documents/Apps/Rails/MDHair/.ruby-version)\n")

Can you even run solargraph manually? What happens if you do this:

env -i HOME="$HOME" $SHELL -i -l -c 'cd /Users/odedharth/Documents/Apps/Rails/MDHair && solargraph'

@odedharth
Copy link
Author

odedharth commented Mar 28, 2024

@mrnugget

this is what happens:

➜  MDHair git:(master) env -i HOME="$HOME" $SHELL -i -l -c 'cd /Users/odedharth/Documents/Apps/Rails/MDHair && solargraph'
zsh:1: command not found: solargraph

it's strange that it was looking for rbenv, since I've switched to chruby.
I've deleted rbenv, but it still doesn't work. It seems that it's looking for a gem in ruby 3.2.3 when the project is using ruby 2.6.10

Please see the new log file:
Zed.log

@odedharth
Copy link
Author

I've installed Solargraph manually with Ruby 3.2.3, and it fixed it. I'm wondering why was Zed looking for the 3.2.3 ruby version?

@mrnugget
Copy link
Member

It depends on how you've setup your Ruby versions. What Zed does by default is to load the env of a user in the homedirectory. So if you have rbenv/chruby set to use version X.Y in your home dir, but to Z.X in your project dir, then Zed won't pick that up. We can change it and look up solargraph dynamically.

@mrnugget mrnugget changed the title Autocomplete not working for Ruby Check if solargraph is already installed and in $PATH in project dir Mar 28, 2024
@mrnugget mrnugget self-assigned this Mar 28, 2024
@rhatherall
Copy link

This appears to be the biggest blocker for me adopting Zed over Neovim (well, maybe a good integrated test runner also?!).

I have posted in the discussion about using StandardRB to format code. I now believe my issues are related to this issue.

I use asdf to manage my Rubies and other tools. I have Bundler configured to install Gems into a .bundle directory within each project, and I typically install binstubs for frequently used tools like StandardRB/RuboCop. I have configured my environment path to allow safely referencing binstubs without the bin/ prefix. I have used this setup with Vim and NeoVim for years without issues. Zed does not appear to use Gems local to the project (from the bundle). If I install the Gems globally with gem install, the tools like solargraph, standardrb, etc. start working but they have to be the exact version defined in my project's Gemfile.lock otherwise it will fail with an error. Now, I can get it working for a single project this way but it's completely impractical if you have more than one Ruby project (which I as most will).

Anyway, I was going to file an issue about this but I feel it is the issue described here but a little wider. Should I file it separately?

mrnugget added a commit that referenced this issue Apr 22, 2024
This fixes #9811 by checking for the `solargraph` binary in the `$PATH`
as its setup in the project shell.

It also adds support for configuring the path to `solargraph` manually:

```json
{
  "lsp": {
    "solargraph": {
      "binary": {
        "path": "/Users/thorstenball/bin/solargraph",
        "arguments": ["stdio"]
      }
    }
  }
}
```
@mrnugget
Copy link
Member

thanks @rhatherall for the comment. Your description of the setup finally gave me confidence that this is the right solution. I went ahead and opened #10835, which should fix this for you.

mrnugget added a commit that referenced this issue Apr 22, 2024
This fixes #9811 by checking for the `solargraph` binary in the `$PATH`
as it's setup in the project shell.

It also adds support for configuring the path to `solargraph` manually:

```json
{
  "lsp": {
    "solargraph": {
      "binary": {
        "path": "/Users/thorstenball/bin/solargraph",
        "arguments": ["stdio"]
      }
    }
  }
}
```

## Example

Given the following setup:

- `ruby@3.3.0` used globally, no `solargraph` installed globally
- `ruby@3.2.2` used in a project, `solargraph` installed as binstub in
`$project/bin/solargraph`, `.envrc` to configure `direnv` to add
`$project/bin` to `$PATH

Which looks like this in practice:

```shell
# GLOBAL
~ $ ruby --version
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
~ $ which solargraph
solargraph not found

# IN PROJECT
~ $ cd work/projs/rails-proj
direnv: loading ~/work/projs/rails-proj/.envrc
direnv: export ~PATH
~/work/projs/rails-proj $ ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin23]
~/work/projs/rails-proj $ which solargraph
/Users/thorstenball/work/projs/rails-proj/bin/solargraph
```

The expectation is that Zed, when opening `~/work/projs/rails-proj`,
picks up the local `solargraph`.

But with **Zed Stable** that doesn't work, as we can see in the logs:

```
2024-04-22T10:21:37+02:00 [INFO] starting language server. binary path: "solargraph", working directory: "/Users/thorstenball/work/projs/rails-proj", args: ["stdio"]
2024-04-22T10:21:37+02:00 [ERROR] failed to start language server "solargraph": No such file or directory (os error 2)
```

With the change in this PR, it uses `rails/proj/bin/solargraph`:

```
[2024-04-22T10:33:06+02:00 INFO  language] found user-installed language server for Ruby. path: "/Users/thorstenball/work/projs/rails-proj/bin/solargraph", arguments: ["stdio"]
[2024-04-22T10:33:06+02:00 INFO  lsp] starting language server. binary path: "/Users/thorstenball/work/projs/rails-proj/bin/solargraph", working directory: "/Users/thorstenball/work/projs/rails-proj", args: ["stdio"]
```

**NOTE**: depending on whether `mise` (or `rbenv`, `asdf`, `chruby`,
...) or `direnv` come first in the shell-rc file, it picks one or the
other, depending on what puts itself first in `$PATH`.

## Release Notes

Release Notes:

- Added support for finding the Ruby language server `solargraph` in the
user's `$PATH` as it is when `cd`ing into a project's directory.
([#9811](#9811))
- Added support for configuring the `path` and `arguments` for
`solargraph` language server manually. Example from settings: `{"lsp":
{"solargraph": {"binary":
{"path":"/Users/thorstenball/bin/solargraph","arguments": ["stdio"]}}}}`
([#9811](#9811))
@notpeter notpeter removed the needs info / awaiting response Issue that needs more information from the user label Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect [core label] language server An umbrella label for all language servers language An umbrella label for all programming languages syntax behaviors ruby Ruby programming language support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants