Ruby languageserver extension for coc.nvim, using solargraph
Published Package Summary
coc-solargraph
Ruby language server extension using solargraph for coc.nvim.
Note: remember use fnameescape() for solargraph uri (solargraph:/) to open
it by vim command.
Note: solargraph scheme returns html, but vim doesn't handle html, so it's converted to markdown.
Install
Install solargraph by:
gem install solargraph
In your vim/neovim, run command:
:CocInstall coc-solargraph
Features
Coc.nvim support all features of solargraph
Transport Options
Extension version 1.0.0 introduces the solargraph.transport setting with the following options:
socket: Run a TCP server. This is the default option.stdio: Run a STDIO server.external: Connect to an external server instead of starting a new one.
Most users should use the default socket option or switch to stdio in case of network issues.
The external option is intended for cases where the project is hosted in a different environment from the editor,
such as a docker container or a remote server. Users can opt to run a socket server in the remote environment and connect
to it via TCP. The extension waits for the socket's connect event before handing the connection to the language client.
If the connection fails, Coc prompts you to try again. Example configuration:
"solargraph.transport": "external",
"solargraph.externalServer": {
"host": "localhost",
"port": 7658
}
The port can also be provided as a string when the configuration is generated or supplied by another tool:
"solargraph.externalServer": {
"host": "localhost",
"port": "7658"
}
Documenting Your Code
Using YARD for inline documentation is highly recommended. Solargraph will use YARD comments to provide the best code completion and API reference it can.
In addition to the standard YARD tags, Solargraph defines a @type tag for documenting variable types. It works with both
local and instance variables. Example:
# @type [String]
my_variable = some_method_call
my_variable. # <= Hitting crtl-space here will suggest String instance methods
Gem Support
Solargraph is capable of providing code completion and documentation for gems. When your code uses require to include a gem, its classes and methods become available in completion and intellisense.
You can make sure your gems are available with the commands Build new gem documentation or Rebuild all gem documentation in the :CocCommand list.
Solargraph and Bundler
If your project uses Bundler, the most comprehensive way to use your bundled gems is to bundle Solargraph.
In the Gemfile:
gem 'solargraph', group: :development
Run bundle install and use bundle exec yard gems to generate the documentation. This process documents cached or vendored gems, or even gems that are installed from a local path.
In order to access intellisense for bundled gems, you'll need to start the language server with Bundler by setting the solargraph.useBundler option to true.
Diagnostics (Linting)
To enable diagnostics, set the solargraph.diagnostics configuration to true.
Solargraph uses RuboCop for diagnostics by default. If your project has a .solargraph.yml file, you can configure the diagnostics in its reporters section. Example:
reporters:
- rubocop
See Solargraph Tips for more information about the .solargraph.yml file.
Use a .rubocop.yml file in your project's root folder to customize the linting rules.
Restarting Solargraph
Some changes you make to a project, such as updating the Gemfile, might require you to restart the Solargraph server. Run the following command to restart only the Solargraph language server:
:CocCommand solargraph.restart
The restart command disposes of the current language client and starts a new one using the current configuration.
The server can request the same lifecycle operation by sending the $/solargraph/restart notification; this
notification triggers a silent client restart without showing a duplicate user message.
Documentation pages opened through commands such as solargraph.search and solargraph.environment continue to
use Coc's existing solargraph text document content provider. Cached documentation remains associated with that
provider when the language client is restarted.
Updating the Core Documentation
The Solargraph gem ships with documentation for Ruby 2.2.2. As of gem version 0.15.0, there's an option to download additional documentation for other Ruby versions from the command line.
$ solargraph list-cores # List the installed documentation versions
$ solargraph available-cores # List the versions available for download
$ solargraph download-core # Install the best match for your Ruby version
$ solargraph clear-cores # Clear the documentation cache
License
MIT
- Ruby languageserver extension for coc.nvim, using solargraph
- onLanguage:ruby
- onCommand:solargraph.search
- onCommand:solargraph.restart
- onCommand:solargraph.config
- onCommand:solargraph.downloadCore
Want to build, test, or contribute to coc.nvim extensions? Explore our official SDK and testing toolkits.
Open Developer GuideVersion History
Published with coc-solargraph@1.3.0 as history.md.
Change log
1.3.0
- Add the
solargraph.restartcommand to restart only the Solargraph language server. - Handle the
$/solargraph/restartserver notification and restart the language client without showing a duplicate message. - Wait for external TCP connections to reach the
connectstate before starting the language client, accept numeric string ports, and offer a retry action when a connection fails. - Keep Solargraph documentation pages backed by Coc's existing text document content provider across language-server restarts.
- Make
solargraph.commandPathandsolargraph.bundlerPathresource-scoped so they can be configured per workspace or resource.
Contributed Commands
All contributes.commands entries from the published package manifest for coc-solargraph@1.3.0.
| Command (:CocCommand) | Description |
|---|---|
| solargraph.search | Search Ruby Documentation |
| solargraph.restart | Restart Solargraph |
| solargraph.config | Create a Solargraph config file |
| solargraph.checkGemVersion | Check Solargraph gem version |
| solargraph.downloadCore | Download current Ruby documentation |
| solargraph.buildGemDocs | Build new gem documentation |
| solargraph.rebuildAllGemDocs | Rebuild all gem documentation |
| solargraph.environment | Get environment info |
Configuration Schema
All contributes.configuration entries from the published package manifest, including each raw property schema for coc-settings.json.
Raw JSON Schema
{
"type": [
"boolean"
],
"default": true,
"description": "Enable hover"
}Raw JSON Schema
{
"type": [
"null",
"string"
],
"default": null,
"description": "Shell used to launch solargraph server"
}Raw JSON Schema
{
"type": [
"boolean"
],
"default": true,
"description": "Enable symbol renaming"
}Raw JSON Schema
{
"type": "boolean",
"default": true,
"description": "Enable folding ranges"
}Raw JSON Schema
{
"type": [
"boolean"
],
"default": true,
"description": "Enable symbols"
}Raw JSON Schema
{
"enum": [
"warn",
"info",
"debug"
],
"type": "string",
"default": "warn",
"description": "Level of debug info to log. `warn` is least and `debug` is most."
}Raw JSON Schema
{
"enum": [
"socket",
"stdio",
"external"
],
"type": "string",
"default": "socket",
"description": "The type of transport to use."
}Raw JSON Schema
{
"type": [
"boolean"
],
"default": false,
"description": "Enable automatic formatting while typing (WARNING: experimental)"
}Raw JSON Schema
{
"type": [
"boolean"
],
"default": true,
"description": "Enable completion"
}Raw JSON Schema
{
"type": [
"boolean"
],
"default": false,
"description": "Enable document formatting"
}Raw JSON Schema
{
"type": [
"boolean"
],
"default": true,
"description": "Enable finding references"
}Raw JSON Schema
{
"type": "boolean",
"default": false,
"description": "Use `bundle exec` to run solargraph. (If this is true, the solargraph.commandPath setting is ignored.)"
}Raw JSON Schema
{
"type": "string",
"scope": "resource",
"default": "bundle",
"description": "Path to the bundle executable, defaults to 'bundle'"
}Raw JSON Schema
{
"type": "string",
"scope": "resource",
"default": "solargraph",
"description": "Path to the solargraph command. Set this to an absolute path to select from multiple installed Ruby versions."
}Raw JSON Schema
{
"type": [
"boolean"
],
"default": true,
"description": "Enable definitions (go to, etc.)"
}Raw JSON Schema
{
"type": [
"boolean"
],
"default": false,
"description": "Enable diagnostics"
}Raw JSON Schema
{
"enum": [
"off",
"messages",
"verbose"
],
"type": "string",
"default": "off"
}Raw JSON Schema
{
"type": "object",
"default": {
"host": "localhost",
"port": 7658
},
"properties": {
"host": {
"type": "string",
"default": "localhost"
},
"port": {
"type": "integer",
"default": 7658
}
},
"description": "The host and port to use for external transports. (Ignored for stdio and socket transports.)"
}Raw JSON Schema
{
"type": "boolean",
"default": true,
"description": "Prompt for download solargraph gem when not found."
}Raw JSON Schema
{
"type": "boolean",
"default": true,
"description": "Automatically check if a new version of the Solargraph gem is available."
}