Skip to content
This repository was archived by the owner on Mar 31, 2023. It is now read-only.

doompling/elastic_ruby_server

Repository files navigation

Elastic Ruby Server

A Ruby language server with persistent storage backed by Elasticsearch. The goal of this language server is to provide reasonably accurate static analysis while staying performant for large projects.  

Features
Definitions Jump to definitions for methods, variables, etc.
Definition Search Search definitions in all files. Currently Disabled while WIP.
Diagnostics Indicates issues generated with Rubocop
Formatting Supports formatting only modified lines
Highlights Highlight all occurrences in a document
References Show where a method/variable/symbol is being used
Rename Update all references to a method/variable/symbol

 

Installation

1. Install the Elastic Ruby Language Server extension from the VSCode Marketplace.

2. Install Docker if needed.

3. Install the dependencies needed for the extension to interact with Docker:

> cd ~/.vscode/extensions/blinknlights.elastic-ruby-client-1.0.0/
> npm install

3. Set paths the server can read. A file must be in a sub-directory of one of these paths to be accessable by the server. Configure in VSCode's settings:

"elasticRubyServer.projectPaths": [
  "/Users/<name>/projects",
  "/Users/<name>/a_folder/more_projects"
]
  • Note: don't use your home directory as a path or docker will use a large amount of CPU %.
  • Tip: add a path that includes your gems so you can use the language server when running bundle open <gem name>. For example using rbenv: "/Users/<username>/.rbenv/versions"

5. Enable formatting on save. Only modified lines are formatted. Configure in VSCode's settings:

"editor.formatOnSave": true,
"editor.formatOnSaveMode": "modifications",
"[ruby]": {
  "editor.defaultFormatter": "Blinknlights.elastic-ruby-client"
},

6. Activate the extension by reloading VSCode and navigating to any .rb file.

  • The server's Docker image will automatically download and run before indexing the workspace.
  • The status bar icon turns red while the server is busy. The tooltip displays progress: image image

 

Configuration

  • elasticRubyServer.projectPaths. See Installation.
  • elasticRubyServer.port. Default: 8341

 

Features

Definitions

Peek or go to the definition of a method/variable/symbol

  • Command: Go to Definition
  • Keybinds:
    • f12
    • cmd + click

 

  • Supported framework definitions:
    • Rails:
      • belongs_to
      • has_one
      • has_many
      • has_and_belongs_to_many
    • RSpec:
      • let!
      • let

go_to_def

 

Definition Search

Quickly navigate to definitions anywhere in a project.

  • Command: Go to Symbol in Workspace...
  • Keybind: cmd + t

workspace-symbols

 

Diagnostics

Enable and configure Rubocop to highlight issues by adding .rubocop.yml to the root of a project.

diagnostics

 

Formatting

Formats modified lines using a light Rubocop configuration. Duplicate changes are ignored so formatting will not be applied when undoing the automatic formatting then re-saving.

  • Trigger: on save
  • Command: Format Selection
  • Keybind: cmd+k cmd+f

formatting

 

Highlights

See all occurrences of a method/variable/symbol in the current editor.

highlight

 

References

See all the locations where a method/variable/symbol is being used. Only locations in the the file being edited are shown currently.

  • Command: Go to References
  • Keybind: shift + f12

references

 

Rename

Change the name of a method/variable/symbol.

  • Command: Rename Symbol
  • Keybind: f2

rename

 

Custom Commands

Run commands with cmd + shift + p.

  • Reindex Workspace deletes all current data for the project and starts reindexing all files.
  • Stop Server to shutdown the Docker container.

 

How does it work?

The server runs inside a docker container and has its own instance of Elasticsearch. Clients connect through TCP allowing multiple clients to connect to a single instance of the server.

Ruby files are converted to an AST with Parser which is serialized by the language server and indexed into Elasticsearch. Data is persisted in a named Docker volume.

Definitions are searched by storing a scope which is built for a given location using rules mimicking Ruby's variable scope. When searching with Go To the correct definitions are chosen largely based on this scope. Multiple definitions will be shown if more than one match the search criteria.

 

Troubleshooting

  • Check that the container is running. The image name is blinknlights/elastic_ruby_server which is ran with the name elastic-ruby-server. You could check with docker ps or in the Docker app:

    Screen Shot 2021-07-01 at 8 41 06 PM

 

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •