Skip to content

Commit

Permalink
Update README and increment version
Browse files Browse the repository at this point in the history
  • Loading branch information
iftheshoefritz committed Oct 15, 2022
1 parent 1b322dd commit c557178
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 47 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
73 changes: 27 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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`

Expand All @@ -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

Expand Down
Binary file added assets/sg_rails_1_0_activerecord_support.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sg_rails_1_0_association_completion.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sg_rails_1_0_routes_support.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/solargraph/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Solargraph
module Rails
VERSION = '1.0.0.pre.1'
VERSION = '1.0.0'
end
end

0 comments on commit c557178

Please sign in to comment.