Closed18

Ruby LSP Add-ons ドキュメント見ながら

Koji NAKAMURAKoji NAKAMURA

Gemを作らなくてもそのプロジェクト内で ruby_lsp/**/addon.rb というパスにマッチすればAdd-onとして読み込んでくれる。例えば lib/ruby_lsp/my_addon/addon.rb とか

Koji NAKAMURAKoji NAKAMURA
def create_hover_listener(response_builder, node_context, index, dispatcher)
`create_hover_listener': wrong number of arguments (given 3, expected 4) (ArgumentError)
Koji NAKAMURAKoji NAKAMURA
    class Hover
      include Requests::Support::Common

      def initialize(response_builder, dispatcher)
        super(dispatcher)
`initialize': wrong number of arguments (given 1, expected 0) (ArgumentError)
Koji NAKAMURAKoji NAKAMURA
@index.register_enhancement(MyIndexingEnhancement.new(@index))

@indexなど定義していないのでnilエラー

Koji NAKAMURAKoji NAKAMURA

global_stateから取得するのが正しい

global_state.index.register_enhancement(MyIndexingEnhancement.new(global_state.index))
Koji NAKAMURAKoji NAKAMURA
uninitialized constant MyIndexingEnhancement::Entry

Entryなんて無いよっていう

Koji NAKAMURAKoji NAKAMURA
new_entry = RubyIndexer::Entry::Method.new(
      "new_method", # The name of the method that gets created via meta-programming
      file_path,    # The file_path where the DSL call was found. This should always just be the file_path received
      location,     # The Prism node location where the DSL call was found
      location,     # The Prism node location for the DSL name location. May or not be the same
      nil,          # The documentation for this DSL call. This should always be `nil` to ensure lazy fetching of docs
      @index.configuration.encoding, # The negotiated encoding. This should always be `indexing.configuration.encoding`
      signatures,   # All signatures for this method (every way it can be invoked)
      RubyIndexer::Entry::Visibility::PUBLIC, # The method's visibility
      owner,        # The method's owner. This is almost always going to be the same owner received
    )
 wrong number of arguments (given 9, expected 8)
Koji NAKAMURAKoji NAKAMURA

#linearized_ancestors_of がエラー吐くけど、動くは動くのでヨシとする

Koji NAKAMURAKoji NAKAMURA
  • ある特定のシンボルからジャンプしたかったら hover から index を探して response_builder 経由でレスポンスする
  • メタプロで生成されたメソッドからジャンプしたかったら RubyIndexer::Enhancement を継承して解析時に index を追加する
このスクラップは5日前にクローズされました