castwide / solargraph

A Ruby language server.
https://solargraph.org
MIT License
1.89k stars 157 forks source link

Solargraph plugin architecture. #307

Open bekicot opened 4 years ago

bekicot commented 4 years ago

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?

castwide commented 4 years ago

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.

castwide commented 4 years ago

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.

bekicot commented 4 years ago

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

castwide commented 4 years ago

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

bekicot commented 4 years ago

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

bekicot commented 4 years ago

@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.

castwide commented 4 years ago

@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.

andy4thehuynh commented 1 year ago

Has anyone had success integrating standardrb with Solargraph and a Neovim Language Server Protocol? I get the executable in return when I do gem which solargraph-standardrb and gem which standard but my LSP tells me "Error in diagnostics: Diagnostics reporter standardrb does not exist".

I setup Solargraph in my Neovim config config.solargraph.setup({}) and add a .solargraph.yml file in my project with

plugins:
- solargraph-standardrb
reporters:
- standardrb

No dice. Anyone got better luck?

dansdantas commented 1 year ago

Has anyone had success integrating standardrb with Solargraph and a Neovim Language Server Protocol? I get the executable in return when I do gem which solargraph-standardrb and gem which standard but my LSP tells me "Error in diagnostics: Diagnostics reporter standardrb does not exist".

I setup Solargraph in my Neovim config config.solargraph.setup({}) and add a .solargraph.yml file in my project with

plugins:
- solargraph-standardrb
reporters:
- standardrb

No dice. Anyone got better luck?

I did. Not sure how you are installing servers and linters, but on my case i'm using mason.nvim. I had to change config to append mason on PATH instead of prepending. That actually let the library to use solargraph and plugins that i installed on the project.


require("mason").setup({
    PATH = 'append',
    ui = {
        check_outdated_packages_on_open = false,
    },
})