class TypeProf::LSP::Message::Workspace::ExecuteCommand

Constants

METHOD

Public Instance Methods

run() click to toggle source
# File typeprof-0.21.2/lib/typeprof/lsp.rb, line 496
def run
  case @params[:command]
  when "typeprof.enableSignature"
    @server.signature_enabled = true
    @server.send_request("workspace/codeLens/refresh")
  when "typeprof.disableSignature"
    @server.signature_enabled = false
    @server.send_request("workspace/codeLens/refresh")
  when "typeprof.createPrototypeRBS"
    class_kind, class_name, sig_str = @params[:arguments]
    code_range =
      CodeRange.new(
        CodeLocation.new(1, 0),
        CodeLocation.new(1, 0),
      )
    text = []
    text << "#{ class_kind } #{ class_name.join("::") }\n"
    text << "  #{ sig_str }\n"
    text << "end\n\n"
    text = text.join
    @server.send_request(
      "workspace/applyEdit",
      edit: {
        changes: {
          @server.root_uri + "/typeprof.rbs" => [
            {
              range: code_range.to_lsp,
              newText: text,
            }
          ],
        },
      },
    ) do |res|
      code_range =
        CodeRange.new(
          CodeLocation.new(1, 0),
          CodeLocation.new(3, 3), # 3 = "end".size
        )
      @server.send_request(
        "window/showDocument",
        uri: @server.root_uri + "/typeprof.rbs",
        takeFocus: true,
        selection: code_range.to_lsp,
      )
    end
    respond(nil)
  else
    respond_error(
      code: ErrorCodes::InvalidRequest,
      message: "Unknown command: #{ @params[:command] }",
    )
  end
end