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 |
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 |
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
- Rails:
Quickly navigate to definitions anywhere in a project.
- Command:
Go to Symbol in Workspace...
- Keybind:
cmd + t
Enable and configure Rubocop to highlight issues by adding .rubocop.yml to the root of a project.
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
See all occurrences of a method/variable/symbol in the current editor.
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
Change the name of a method/variable/symbol.
- Command:
Rename Symbol
- Keybind:
f2
1. Install the Elastic Ruby Language Server
extension and Docker if needed.
2. Configure elasticRubyServer.projectPaths
. Important: A project must be a sub-directory of one of these paths to be readable by the langue server.
- Configure in VSCode's JSON settings (
cmd + shift + p
and search forPreferences: Open Settings (JSON)
). - Don't use your home directory as a project path or docker will use a large amount of CPU %.
"elasticRubyServer.projectPaths": [
"/Users/<name>/projects",
"/Users/<name>/a_folder/more_projects"
]
3. Install dependencies needed for the extension to interact with docker:
> cd ~/.vscode/extensions/blinknlights.elastic-ruby-client-0.5.1/
> npm install
5. Reload VSCode
6. Navigate to any .rb
file to activate the extension. The extension will automatically download the language server's docker image and start indexing a workspace. Indexing may take a few minutes for large projects.
elasticRubyServer.port
. The default is8341
.
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.
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.
-
Check that the container is running. The image name is
blinknlights/elastic_ruby_server
which is ran with the nameelastic-ruby-server
. You could check withdocker ps
or in the Docker app:
Got this after doing the npm install for your extension:
found 2 moderate severity vulnerabilities
run npm audit fix
to fix them, or npm audit
for details