├── .gitignore ├── Gemfile ├── Gemfile.lock ├── LICENSE.txt ├── README.md ├── Rakefile ├── bin ├── console └── setup ├── exe └── solargraph-rails-init ├── lib └── solargraph │ └── rails │ ├── init.rb │ └── init │ └── version.rb └── solargraph-rails-init.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | # Specify your gem's dependencies in solargraph-rails-init.gemspec 6 | gemspec 7 | 8 | gem "rake", "~> 13.0" 9 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | solargraph-rails-init (0.2.2) 5 | 6 | GEM 7 | remote: https://rubygems.org/ 8 | specs: 9 | rake (13.0.3) 10 | 11 | PLATFORMS 12 | ruby 13 | x86_64-darwin-20 14 | 15 | DEPENDENCIES 16 | rake (~> 13.0) 17 | solargraph-rails-init! 18 | 19 | BUNDLED WITH 20 | 2.2.11 21 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Carl Mercier 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # solargraph-rails-init 2 | 3 | A simple script that configures Solargraph to work with Rails. It acts as a shortcut to the following commands: 4 | 5 | ```bash 6 | gem install solargraph 7 | gem install solargraph-rails --pre # if --solargraph-rails-gem is specified 8 | solargraph download-core 9 | yard gems 10 | solargraph bundle 11 | curl -s https://gist.githubusercontent.com/cmer/024991c85c4de01dab17632b2dc7f064/raw > .solargraph.yml 12 | curl -s https://gist.githubusercontent.com/castwide/28b349566a223dfb439a337aea29713e/raw > config/definitions.rb 13 | ``` 14 | 15 | 16 | ## Installation & Usage 17 | 18 | Run the following commands in your Rails app root directory: 19 | 20 | ```bash 21 | gem install solargraph-rails-init 22 | solargraph-rails-init 23 | 24 | # See also: 25 | solargraph-rails-init --help 26 | solargraph-rails-init --solargraph-rails-gem # also add/initialize the optional solargraph-rails gem 27 | ``` 28 | 29 | Run `solargraph-rails-init` again if you install new gems or change your Ruby version. 30 | 31 | ## Inspiration 32 | 33 | This was inspired by [Setting up Solargraph for VSCode](https://www.youtube.com/watch?v=mkLDPpDSWng). 34 | 35 | 36 | ## Contributing 37 | 38 | Bug reports and pull requests are welcome on GitHub at https://github.com/cmer/solargraph-rails-init. 39 | 40 | 41 | ## License 42 | 43 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). 44 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_tasks" 4 | task default: %i[] 5 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require "bundler/setup" 5 | require "solargraph/rails/init" 6 | 7 | # You can add fixtures and/or initialization code here to make experimenting 8 | # with your gem easier. You can also use a different console, if you like. 9 | 10 | # (If you use this, don't forget to add pry to your Gemfile!) 11 | # require "pry" 12 | # Pry.start 13 | 14 | require "irb" 15 | IRB.start(__FILE__) 16 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /exe/solargraph-rails-init: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'optparse' 4 | require 'yaml' 5 | 6 | SOLARGRAPH_YML = ".solargraph.yml" 7 | DEFINITIONS_RB = "config/definitions.rb" 8 | 9 | def run 10 | parse_options 11 | 12 | unless is_rails? 13 | puts "Must run from a Rails app folder. Aborting." 14 | exit 1 15 | end 16 | 17 | exec_cmd "gem install solargraph", title: "Installing Solargraph gem..." 18 | exec_cmd "solargraph download-core", title: "Installing documentation. This might take a while..." 19 | exec_cmd "yard gems" 20 | exec_cmd "solargraph bundle" 21 | 22 | unless File.exist?(SOLARGRAPH_YML) 23 | exec_cmd "curl -s https://gist.githubusercontent.com/cmer/024991c85c4de01dab17632b2dc7f064/raw > #{SOLARGRAPH_YML}", title: "Copying .solargraph.yml..." 24 | else 25 | puts "Skipped copying .solargraph.yml. Already exists." 26 | end 27 | 28 | unless File.exist?(DEFINITIONS_RB) 29 | exec_cmd "curl -s https://gist.githubusercontent.com/castwide/28b349566a223dfb439a337aea29713e/raw > #{DEFINITIONS_RB}", title: "Copying definitions.rb..." 30 | else 31 | puts "Skipped copying .definitions.rb. Already exists." 32 | end 33 | 34 | install_sgr if install_sgr? 35 | 36 | puts "Done!" 37 | end 38 | 39 | def is_rails? 40 | File.exist?(File.join(Dir.pwd, './bin/rails')) 41 | end 42 | 43 | def exec_cmd(cmd, title: nil) 44 | puts title if title 45 | out = `#{cmd}` 46 | if $? != 0 47 | puts out 48 | puts "\nAn error as occured. Aborting.\n" 49 | exit 1 50 | end 51 | end 52 | 53 | def install_sgr? 54 | @options[:sgr] 55 | end 56 | 57 | def install_sgr 58 | exec_cmd "gem install solargraph-rails --pre", title: "Installing `solargraph-rails` gem..." 59 | exec_cmd "bundle add annotate", title: "Adding `annotate` gem to Gemfile..." 60 | exec_cmd "rails g annotate:install", title: "Initializing `annotate` gem..." 61 | exec_cmd "rake annotate_models", title: "Annotating models..." 62 | 63 | puts "Adding `solargraph-rails` plugin to #{SOLARGRAPH_YML}..." 64 | h = YAML.load_file(SOLARGRAPH_YML) 65 | h['plugins'] ||= [] 66 | h['plugins'] << 'solargraph-rails' unless h['plugins'].include?('solargraph-rails') 67 | 68 | File.open(SOLARGRAPH_YML, "w") do |file| 69 | file.write h .to_yaml 70 | end 71 | end 72 | 73 | def parse_options 74 | @options = {} 75 | optparse = OptionParser.new do |opts| 76 | # Set a banner, displayed at the top of the help screen. 77 | opts.banner = "Usage: solargraph-rails-init [options]" 78 | 79 | @options[:sgr] = false 80 | opts.on('-g', '--solargraph-rails-gem', 'Install and configure the solargraph-rails gem') do 81 | @options[:sgr] = true 82 | end 83 | 84 | # This displays the help screen, all programs are assumed to have this option. 85 | opts.on('-h', '--help', 'Display this screen') do 86 | puts opts 87 | exit 88 | end 89 | end 90 | 91 | optparse.parse! 92 | end 93 | 94 | run 95 | -------------------------------------------------------------------------------- /lib/solargraph/rails/init.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative "init/version" 4 | 5 | module Solargraph 6 | module Rails 7 | module Init 8 | class Error < StandardError; end 9 | # Your code goes here... 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/solargraph/rails/init/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Solargraph 4 | module Rails 5 | module Init 6 | VERSION = "0.2.2" 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /solargraph-rails-init.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative "lib/solargraph/rails/init/version" 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = "solargraph-rails-init" 7 | spec.version = Solargraph::Rails::Init::VERSION 8 | spec.authors = ["Carl Mercier"] 9 | spec.email = ["foss@carlmercier.com"] 10 | 11 | spec.summary = "A simple script that configures Solargraph to work with Rails." 12 | spec.description = "A simple script that configures Solargraph to work with Rails." 13 | spec.homepage = "https://github.com/cmer/solargraph-rails-init" 14 | spec.license = "MIT" 15 | spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0") 16 | 17 | spec.metadata["homepage_uri"] = spec.homepage 18 | spec.metadata["source_code_uri"] = "https://github.com/cmer/solargraph-rails-init" 19 | 20 | 21 | # Specify which files should be added to the gem when it is released. 22 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git. 23 | spec.files = Dir.chdir(File.expand_path(__dir__)) do 24 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } 25 | end 26 | spec.bindir = "exe" 27 | spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } 28 | spec.require_paths = ["lib"] 29 | end 30 | --------------------------------------------------------------------------------