百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

solargraph-rails

> 编程语言
开源

Solargraph 插件,用于提高对 Rails 特定代码的认识

339 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

Solargraph 插件,用于提高对 Rails 特定代码的认识

Solargraph::Rails - Help solargraph with Rails

Models

Consider pair of typical Rails models like this:

bash
rails g model Author lastname:string firstnames:string
rails g model Book title:string isbn:string author:belongs_to
ruby
class Author < ApplicationRecord
  has_many :books

  def sortable_name
    "#{lastname}, #{firstnames}"
  end
end

class Book < ApplicationRecord
  belongs_to :author

  def label
    [author.sortable_name, title, isbn].join("\n")
  end
end

The various Ruby intellisense tools are ok at knowing that there are Book and Author constants, and some (including Solargraph) are aware that objects like Book.new have a .label method. But what about those "magical" dynamic methods that ActiveRecord creates like .title, or .author?

Since these attributes are only created at runtime, a simple static analysis of the Book class 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 understands db/schema.rb and any comments from the annotate_models gem for models, and also supplies key annotations and Rails-specific context on top of what Solargraph pulls via YARD and RBS. As a result, you have access to database attributes:

... and ActiveRecord finders:

... and associations:

... and routes file syntax:

and more!

Installation

Install solargraph and 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.

Import Rails RBS types

Use gem_rbs_collection to install RBS types for Rails:

bash
rbs collection init
rbs collection install

Add solargraph-rails to your .solargraph.yml

(if you don't have a .solargraph.yml in your project root, you can run solargraph config to add one)

plugins:
  - solargraph-rails

Build YARD docs

In the project root, run yard gems.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/iftheshoefritz/solargraph_rails.

  1. create fork and clone the repo

  2. install gem deps bundle install

  3. install dummy rails app deps:

bash
cd spec/rails7 && bundle install && rbs collection init && rbs collection install && cd ../../
cd spec/rails8 && bundle install && rbs collection init && rbs collection install && cd ../../
  1. now tests should pass locally and you can try different changes

  2. submit PR

See DEVELOPMENT.md for more information

License

The gem is available as open source under the terms of the MIT License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言