Trying to Make Ruby's Parser Available as a Gem.
Kanayago(金屋子) is supported Ruby 3.4 or Ruby head.
gem install kanayago
First, clone this repository.
git clone https://github.com/S-H-GAMELINKS/kanayago.gitMove kanayago directory, and run bundle install.
cd kanayago && bundle installFinally, build Kanayago gem and install it.
bundle exec rake build
gem install pkg/kanayago-0.6.1.gemrequire 'kanayago/kanayago'
result = Kanayago.parse('117 + 117')
# => #<Kanayago::ParseResult:0x00007f522199c5a8>
p result.ast
# => #<Kanayago::ScopeNode:0x00007f522199c5a8>
p result.ast.body
# => #<Kanayago::OperatorCallNode:0x00007f5221b06358>
p result.ast.body.recv
p result.ast.body.recv.val
# => #<Kanayago::IntegerNode:0x00007f5221b06330>
# => 117
# Check for syntax errors
result = Kanayago.parse('def foo')
p result.valid?
# => false
p result.error
# => #<SyntaxError: syntax error, unexpected end-of-input>Kanayago provides LSP server support for real-time syntax checking in your editor:
# Start LSP server
$ kanayago --lspThis starts an LSP server that communicates via stdin/stdout. You can integrate it with LSP-compliant editors like VSCode, Vim, Emacs, etc.
Install the official VSCode extension from the marketplace:
- Open VSCode and search for "VSCode Kanayago" in the Extensions view
- Click Install
Configuration:
{
"kanayago.serverPath": "kanayago",
"kanayago.trace.server": "off"
}Now VSCode will show syntax errors in real-time as you type Ruby code.
Install the official coc.nvim extension:
:CocInstall coc-kanayagoConfiguration:
Add the following to your coc-settings.json (:CocConfig in Vim):
{
"coc-kanayago.enable": true,
"coc-kanayago.command": "kanayago"
}Diagnostic Navigation:
The extension supports standard coc.nvim diagnostic keybindings:
- Next diagnostic:
<space>dn - Previous diagnostic:
<space>dp - Show diagnostic info:
<space>di
See coc-kanayago for more details.
Alternatively, you can configure the LSP server manually in your coc-settings.json:
{
"languageserver": {
"kanayago": {
"command": "kanayago",
"args": ["--lsp"],
"filetypes": ["ruby"],
"rootPatterns": ["Gemfile", ".git"]
}
}
}Now Vim/Neovim with coc.nvim will show syntax errors in real-time as you edit Ruby files.
If you're using Emacs with lsp-mode, add the following configuration to your init.el:
(require 'lsp-mode)
;; Register Kanayago LSP server
(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection '("kanayago" "--lsp"))
:major-modes '(ruby-mode enh-ruby-mode)
:server-id 'kanayago-lsp
:priority 10))
;; Enable lsp-mode for Ruby files
(add-hook 'ruby-mode-hook #'lsp-deferred)Kanayago will automatically check your Ruby code for syntax errors and display diagnostics in real-time.
Add the following configuration to your ~/.config/helix/languages.toml:
[[language]]
name = "ruby"
language-servers = ["kanayago"]
[language-server.kanayago]
command = "kanayago"
args = ["--lsp"]If you already have a Ruby language configuration, you can add "kanayago" to your existing language-servers array:
[[language]]
name = "ruby"
language-servers = ["kanayago", "solargraph"] # Use alongside other LSPs
[language-server.kanayago]
command = "kanayago"
args = ["--lsp"]Now Helix will show syntax errors in real-time as you edit Ruby files.
Install the official Zed extension from the marketplace:
- Open Zed and go to Extensions (
cmd/ctrl + shift + x) - Search for "Kanayago"
- Click Install
Manual Installation:
If you prefer to install manually or for development purposes:
git clone https://github.com/S-H-GAMELINKS/zed-kanayago.git
cd zed-kanayagoThen follow the Zed extension development guide for installation.
Requirements:
- Kanayago must be installed and available in your PATH
- Zed will automatically start the LSP server when opening Ruby files
See zed-kanayago for more details.
Kanayago provides a CLI for syntax checking:
# Check Ruby code directly
$ kanayago check 'p 117'
Syntax valid
# Check Ruby code with syntax error
$ kanayago check 'def foo'
Syntax invalid
# Check a Ruby file
$ kanayago check --file test.rb
Syntax valid
# Or use the short option
$ kanayago check -f test.rb
Syntax validThe CLI exits with code 0 for valid syntax and code 1 for invalid syntax or errors.
After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
# Run unit tests (excludes integration tests)
bundle exec rake test
# Run integration tests (requires repository setup)
bundle exec rake integration:setup # Clone test repositories (Rails, Discourse, Mastodon, GitLab)
bundle exec rake integration:test # Run integration tests
# Clean up cloned repositories
bundle exec rake integration:clean
# Update cloned repositories to latest
bundle exec rake integration:updateThe integration tests verify that Kanayago can successfully parse real-world Rails codebases including Rails itself, Discourse, Mastodon, and GitLab. These tests help ensure compatibility with production Ruby code patterns.
Bug reports and pull requests are welcome on GitHub at https://github.com/S-H-GAMELINKS/kanayago.
The gem is available as open source under the terms of the MIT License.

