diff --git a/CHANGELOG.md b/CHANGELOG.md index afe8d72..afca9e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ ## Changes +### v1.0.0 + +https://github.com/alisnic/solargraph-arc was merged, with the following features: +- fixes autocompletion for multi-level classes defined in 1 line `class Foo::Bar::Baz`. See https://github.com/castwide/solargraph/issues/506 +- autocomplete database columns by parsing db/schema.rb +- autocomplete of model relations +- parsing of `delegate` calls +- completions for methods generated by Devise +- better support for running solargraph outside bundle +- better completion inside controllers. `request`, `response`, `params`, etc. +- autocomplete inside routes.rb +- autocomplete inside migrations +- completions for methods generated by ActiveStorage +- better ActiveRecord completions + ### v1.0.0.pre.1 https://github.com/alisnic/solargraph-arc was merged, with the following features: diff --git a/README.md b/README.md index 78f2f31..90ec16b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ # Solargraph::Rails - Help solargraph with Rails -## Work in progress - here be dragons -There are significant rough edges to this gem still. - ## Models Given a typical Rails model like this: @@ -27,50 +24,33 @@ class MyBook < ApplicationRecord end ``` -The various Ruby intellisense tools are ok at knowing that there is a `MyBook` constant, and some (including Solargraph) are even aware that objects like `MyBook.new` have a method `.my_method`. But what about those magical dynamic attributes that ActiveRecord creates when Rails starts up? You can see these listed at the top of the file under `# == Schema Information`, the comments helpfully added by the Annotate gem. +The various Ruby intellisense tools are ok at knowing that there is a `MyBook` constant, and some (including Solargraph) are aware that objects like `MyBook.new` have a method `.my_method`. But what about those magical dynamic attributes that ActiveRecord creates when Rails starts up? You can see these listed at the top of the file under `# == Schema Information`, the comments helpfully added by the Annotate gem. Since these attributes are only created at runtime, static analysis alone can't identify them. Your editor has no idea that these attributes exist, but they're amongst the most common things that you will work with in any Rails app. -That's where this plugin for Solargraph comes in: it parses the schema comments left by Annotate and uses those to give Solargraph some extra hints. - -With this you get autocompletion on ActiveRecord attributes: - - ![Autocompletion of dynamic attributes like created_at](assets/solar_rails_autocomplete.gif) - -... and go to definition commands take you to the schema comment for that column: - +That's where this plugin for Solargraph comes in: it parses the database schema and YARD docs of various gems to give Solargraph some extra hints. For instance database attributes: - ![Go to definition of dynamic attributes like created_at](assets/solar_rails_goto.gif) + ![Go to attribute schema definition](assets/sg_rails_1_0_go_to_attribute_definition.gif) -... and peek commands show you documentation about the attribute: + ... or ActiveRecord finders: - ![Peek at documentation of attributes like created_at, author, etc.](assets/peek.png) + ![ActiveRecord method support](assets/sg_rails_1_0_activerecord_support.gif) -### Reload workspace after migrations -Solargraph won't know about attributes that you add during a session. Restart your LSP workspace to get the new attributes. + ... or associations: -For my setup with Emacs, that means running `M-x lsp-workspace-restart`, YMMV in other editors. + ![Association support](assets/sg_rails_1_0_association_completion.gif) -## Associations (experimental) -There is simplistic support for `belongs_to` and `has_many` macros: + ... or routes file: - ![Experimental autocomplete and go to definition of associations](assets/solar_rails_associations.gif) + ![Routes file support](assets/sg_rails_1_0_routes_support.gif) -## Known issues -This project is being used to write production code by the maintainer, but it is still WIP. Check out the issues tab and contribute if you are interested. - -Association support is slightly less functional in Rails 7. +and more! ## Installation -### Install `solargraph` and `solargraph-rails` locally - -Typically gems like these are not installed via the Gemfile, because most projects have more than one contributor and other contributors might have different setups for their editors in mind. Instead you need to use `gem install`. +### Install `solargraph` and `solargraph-rails` -`gem install solargraph-rails` - -#### Alternative: using bundler -If you do want to use bundler, add `gem 'solargraph-rails'` +If you add them to your Gemfile, you'll have to tell your IDE plugin to use bundler to load the right version of solargraph. ### Add `solargraph-rails` to your `.solargraph.yml` @@ -81,28 +61,29 @@ plugins: - solargraph-rails ``` -### Add annotate -Add schema comments your model files using [Annotate](https://github.com/ctran/annotate_models/). At the moment Solargraph::Rails assumes your schema comments are at the top of the source file. - -## Development +### Build YARD docs +In the project root, run `yard gems`. -Fork the project, start hacking, put up a PR :). - -When you make changes, you probably need to shut down solargraph and restart it (maybe that requires you to shut down your whole editor?). You can speed up the feedback loop by running +## Contributing +Bug reports and pull requests are welcome on GitHub at https://github.com/iftheshoefritz/solargraph_rails. -`api_map = Solargraph::ApiMap.load(Rails.root.to_s)` +1. create fork and clone the repo -in the console of the Rails project where solargraph-rails is installed. This may require restarting the rails console each time, and possibly killing Spring. +2. install gem deps `bundle install` -Once you have an instance of `Solargraph::ApiMap`, you can interrogate it with Solargraph code like: +3. install dummy rails app deps and build the yard cache: -`pins = api_map.get_methods('MyBook')` +``` +$ cd spec/rails5 +$ bundle install && yard gems +$ cd ../../ +``` -More examples here: https://solargraph.org/guides/code-examples +(and the same for rails 6 and rails 7) -## Contributing +4. now tests should pass locally and you can try different changes -Bug reports and pull requests are welcome on GitHub at https://github.com/iftheshoefritz/solargraph_rails. +5. sumbit PR ## License diff --git a/assets/sg_rails_1_0_activerecord_support.gif b/assets/sg_rails_1_0_activerecord_support.gif new file mode 100644 index 0000000..1dff546 Binary files /dev/null and b/assets/sg_rails_1_0_activerecord_support.gif differ diff --git a/assets/sg_rails_1_0_association_completion.gif b/assets/sg_rails_1_0_association_completion.gif new file mode 100644 index 0000000..8b42ff8 Binary files /dev/null and b/assets/sg_rails_1_0_association_completion.gif differ diff --git a/assets/sg_rails_1_0_go_to_attribute_definition.gif b/assets/sg_rails_1_0_go_to_attribute_definition.gif new file mode 100644 index 0000000..1c1b683 Binary files /dev/null and b/assets/sg_rails_1_0_go_to_attribute_definition.gif differ diff --git a/assets/sg_rails_1_0_routes_support.gif b/assets/sg_rails_1_0_routes_support.gif new file mode 100644 index 0000000..e1b2060 Binary files /dev/null and b/assets/sg_rails_1_0_routes_support.gif differ diff --git a/lib/solargraph/rails/version.rb b/lib/solargraph/rails/version.rb index a562db0..ba2efc4 100644 --- a/lib/solargraph/rails/version.rb +++ b/lib/solargraph/rails/version.rb @@ -1,5 +1,5 @@ module Solargraph module Rails - VERSION = '1.0.0.pre.1' + VERSION = '1.0.0' end end