Can I get Ruby code navigation to work with VSCode and Ruby 2.2.2? I've installed the latest VSCode (1.51.1), but I'm trying to edit code in a project that's still on Ruby 2.2.2. I'm able to get code completion and docs working for built-in classes like String, but I can't get it working for code in the project.
To diagnose the problem, I type Ctrl+Shift+P and choose Developer: Show Logs..., followed by Extension Host. Then when I hover over a project method, I see this repeated several times in the output window:
[2020-11-30 15:08:33.198] [exthost] [error] [castwide.solargraph] provider FAILED
[2020-11-30 15:08:33.198] [exthost] [error] undefined
I've installed three VSCode extensions:
Ruby 0.27.0 by Peng Lv
Ruby Solargraph 0.12.0 by Castwide
VSCode Ruby 0.27.0 by Stafford Brunk
I tried installing newer versions of Solargraph, but their dependencies didn't work on Ruby 2.2.2.
As an experiment, I tried creating a minimal project to navigate through. I see the error above when I open myproject.rb and hover over the call to get_other_name() on line 5.
myproject.rb
require 'sinatra'
require_relative 'helper'
get '/' do
'Hello, ' + get_other_name()
end
def get_name()
return 'Bob'
end
helper.rb
def get_other_name()
return 'Alice'
end
Gemfile
source 'https://rubygems.org'
ruby '2.2.2'
# To install all these gems, run "gem install bundler", then "bundle install".
gem 'thin', '1.7.2'
gem 'sinatra', '2.0.1'
group :devtools, optional: true do
gem 'rubocop', '~> 0.52'
gem 'solargraph', '0.12.2'
end
.vscode/settings.json
{
"solargraph.useBundler": true
}
I'm running on Ubuntu 20.04, and I used rvm to install Ruby 2.2.2. I also tried turning off bundler in the solargraph settings and setting the command path to solargraph, but I get the same error.
Related
I want to create a Gemfile.lock by typing 'bundle install' but my local machine can't find the gem net/http. I've tried typing 'bundle update net/http' & 'bundle --full-index' & 'gem install bundler' but I keep getting this error when I try 'bundle install' again:
Could not find gem 'net/http' in rubygems repository https://rubygems.org/ or installed locally. The source does not contain any versions of 'net/http'
my Gemfile resembles the following:
source "https://rubygems.org"
gem 'open-uri'
gem 'nokogiri'
gem 'net/http'
gem 'pry'
Other solutions to this problem suggest removing the line for gem net/http because net/http is part of the default library for Ruby...however when I do this everything loads fine, and I can create a Gemfile.lock upon typing 'bundle install' but when I run my code I get the following error:
Traceback (most recent call last):
run.rb:4:in `': uninitialized constant Net (NameError)
Did you mean? Set
The line of code this refers to is
response = Net::HTTP.get(url)
I'm running Ruby version 2.6.1
The name of the gem is net-http. It is one of the first hits when you google for "net/http".
However, in Ruby 2.6.1, net/http is still part of the standard library, not a gem. Net/http was only removed from the standard library in Ruby 3.0.
There are two different kinds of standard gems:
Default gems: These gems are part of Ruby and you can always require them directly. You cannot remove them. They are maintained by Ruby core.
Bundled gems: The behavior of bundled gems is similar to normal gems, but they get automatically installed when you install Ruby. They can be uninstalled and they are maintained outside of Ruby core.
Your problem is the wrong name gem ('net-http' instead of 'net/http', you can run gem search ^net to find out remote gems start by 'net').
If the gem is 'default', no need to declare it in Gemfile.
You can check standard default gems on: https://stdgems.org/
I have created a gem file similar to below, I'm trying this in windows 7 environment
source :rubygems
group :test do
gem 'cucumber', '1.2.1'
gem 'rspec-expectations', '2.11.2'
end
This is executed in cmd "C:\mysite\ruby test.rb"
System throw following error msg,
test.rb:1:in '<main>' : undefined method 'source' for main:Object (NoMethodError)
I have changed the first line as
source 'http://rubygems.org/'
But still I getting same error. Really appreciate if anyone can give instructions, I'm very new to cucumber & ruby
First install bundler with
gem install bundler
Then go into your project directory. The gem file must be named Gemfile. Then you can just do
bundle install
Also, you should use HTTPS:
source 'https://rubygems.org/'
it seems that you have put "source 'http://rubygems.org/' " line in
'test.rb', which is not allowed, you must have the file Gemfile and
put this code in Gemfile
source 'https://rubygems.org/
group :test do
gem 'cucumber', '1.2.1'
gem 'rspec-expectations', '2.11.2'
end
and do bundle install
I installed Aptana, and i want to try Coffeescript. When I try to "Compile and display JS" it won´t work - console shows:
....xyz.sh: line 3: coffee: command not found
....xyz.sh: line 3: pre: command not found
I don´t get it - how do i get it to run?
Thank you!
Edit:
Since yesterday I managed to get compass/sass running in Aptana (yeah!) - so i realized that my question might be wrong: Do i have to tell Aptana (Windows?) where to find the compiler?
Edit 2:
Realized: The problem is - how can this gem be installed (in Aptana if possible):
via https://github.com/netzpirat/guard-coffeescript
I get an error when installing the guard gem:
ERROR: Error installing guard:
The 'ffi' native gem requires installed build tools.
After trying some stuff here is a litte tutorial to setup compass and coffeescript for a project in Aptana:
(Info: I know very little about coding or ruby, so please be patient :) )
Create project ( i choose basic web template)
Terminal:
$ gem install compass
$ compass create myProject --using blueprint
check:
http://compass-style.org/reference/blueprint/
You also have to setup some other stuff:
I found this page and followed it through..
https://github.com/netzpirat/guard-coffeescript
Install bundle:
$ gem install bundle
$ bundle init //to create the gemfile
Install guard:
You need to install Ruby Devkit before - check this links:
http://rubyinstaller.org/downloads/
https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
If you did so
$ gem install guard
$ gem install guard-coffeescript
I also installed a JS-Engine as recommended here:
https://github.com/netzpirat/guard-coffeescript#javascript-runtimes
$ gem install therubyrhino
For Coffeescript:
$ gem install coffee-script
$ gem install coffee-script-source
Then you have to edit the gemfile, mine looked like this:
# A sample Gemfile
source "https://rubygems.org"
# gem "rails"
group :development do
gem 'guard'
end
group :development do
gem 'guard-coffeescript'
end
group :development do
gem 'therubyrhino'
end
run bundle
$ bundle
create guardfile
$ guard init
edit the guardfile
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'coffeescript', :input => 'myProject/coffeescript', :output => 'myProject/javascript'
you can start the guard with
$ guard start
This worked for me! If you see any mistakes please let me know!
Code inspection in the IntelliJ IDEA editor reports a LoadError "no such file to load" on the code
require 'state_machine'
The gem is installed locally. From the command line:
~$ echo $RUBYOPT
rubygems
~$ irb
irb(main):001:0> require 'state_machine'
=> true
So Ruby and Rubygems are playing nicely together. The IDEA Ruby plugin's project settings even lists the gem, so why can't the editor see it?
Ruby version 1.8.7, IntelliJ IDEA 10.5.4.
This gem must be specified in the Gemfile, refer to help.
I'm running ruby 1.9.2 on Windows and am trying to port code that worked in Ruby 1.8. The code uses Open4.popen4 which previously worked fine. With 1.9.2 I have done the following:
Installed POpen4 via gem install POpen4
Required POpen4 via require 'popen4'
Attempted to use POpen4 like:
Open4.popen4("cmd") {|io_in,io_out,io_er| ... }
When I do, I get the error:
no such file to load -- win32/open3
If I try and install win32-open3 (gem install win32-open3) I get the error:
win32-open3 requires Ruby version < 1.9.0
Does anyone know how I get around this problem?
Haven't used it, but this might work: https://github.com/matschaffer/win32-open3-19
Adding
gem "win32-open3-19", :platforms => :mingw, :git => "github.com/matschaffer/win32-open3-19.git"
to my Gemfile didn't exactly work.
Here are the steps that solved this for me:
Add this to the Gemfile -> gem 'win32-open3-19', :platforms => :mingw
Run bundle to install win32-open3-19
That was it. For me the git location was unncessary and didn't work.