Solargraph: Solargraph plugin architecture.

Created on 16 Apr 2020  路  7Comments  路  Source: castwide/solargraph

I really want to have solargraph to support standardrb , I cloned the repository and copy the rubocop reporter and start learning how it works.

But I came accross an idea, what if, the standardrb, doesn't need to be built-in. And it can be a new gem, lets call solargraph-standardrb-reporter and solargraph can auto-discover it. So that we can include it in our .solargraph.yml.

on #235 & #230. You mentioned about plugin architeture you have in mind. is that the architecture you have in mind? if not, what kind of plugin architecture?

If it already implemented, does it have documentation already?

Most helpful comment

Thank you very much for the effort of 0.39 and 0.39.1.

Now I'm able to use solargraph with standardrb.
https://github.com/bekicot/solargraph-standardrb

Tested on neovim with coc plugin

All 7 comments

Thanks for taking the initiative on this. I haven't documented plugins yet, but today I merged preliminary support into the v0.39 branch.

Let's say your gem looks something like this (modified from the example at https://solargraph.org/guides/code-examples):

# solargraph-standardrb.rb

require 'solargraph'

class StandardrbReporter < Solargraph::Diagnostics::Base
  def diagnose source, api_map
    # Return an array of hash objects that conform to the LSP's Diagnostic
    # specification
    []
  end
end

Solargraph::Diagnostics.register 'standardrb', StandardrbReporter

In your project's .solargraph.yml, you can enable the reporter like this:

plugins:
- solargraph-standardrb
reporters:
- standardrb

The language server simply calls require for each plugin.

Plugin capabilities are liable to change over time, but I expect this architecture for extending diagnostics to remain stable.

I hope to release v0.39.0 by the end of the month.

Plugin support is released in version 0.39.0, along with the first plugin, solargraph-reek.

There's a brief explanation of plugins at https://solargraph.org/guides/plugins.

Thank you very much.
Anyway, is there any plan to add fixer api?
so that we can use standardrb --fix on solargraph

Yes. Currently the textDocument/formatting capability depends on RuboCop, but I plan to extend the API so plugins can register their own formatters.

Thank you very much for the effort of 0.39 and 0.39.1.

Now I'm able to use solargraph with standardrb.
https://github.com/bekicot/solargraph-standardrb

Tested on neovim with coc plugin

@castwide Do you mind to share your plan on extending API to register formatters? I'm not smart enough to do the full design, but if there is small task I can do to make the development faster, I will do.

@bekicot Thank you for your support. I'm not sure how formatters will work through plugins, but I hope we can make them extensible in a similar way to diagnostics. I'll keep working on it, and I'm definitely open to contributions and suggestions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tylerlu94 picture tylerlu94  路  5Comments

castwide picture castwide  路  4Comments

dgutov picture dgutov  路  5Comments

taylorthurlow picture taylorthurlow  路  4Comments

castwide picture castwide  路  3Comments