Class: RubyLsp::Request

Inherits:
Message show all
Defined in:
lib/ruby_lsp/utils.rb

Instance Attribute Summary

Attributes inherited from Message

#method, #params

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, method:, params:) ⇒ Request

: (id: (Integer | String), method: String, params: Object) -> void



181
182
183
184
# File 'lib/ruby_lsp/utils.rb', line 181

def initialize(id:, method:, params:)
  @id = id
  super(method: method, params: params)
end

Class Method Details

.register_watched_files(id, pattern, kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE, registration_id: nil) ⇒ Object

: (Integer id, (Interface::RelativePattern | String) pattern, ?kind: Integer, ?registration_id: String?) -> Request



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/ruby_lsp/utils.rb', line 154

def register_watched_files(
  id,
  pattern,
  kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE,
  registration_id: nil
)
  new(
    id: id,
    method: "client/registerCapability",
    params: Interface::RegistrationParams.new(
      registrations: [
        Interface::Registration.new(
          id: registration_id || SecureRandom.uuid,
          method: "workspace/didChangeWatchedFiles",
          register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
            watchers: [
              Interface::FileSystemWatcher.new(glob_pattern: pattern, kind: kind),
            ],
          ),
        ),
      ],
    ),
  )
end

Instance Method Details

#to_hashObject

: -> Hash[Symbol, untyped]



188
189
190
191
192
193
194
195
196
197
# File 'lib/ruby_lsp/utils.rb', line 188

def to_hash
  hash = { id: @id, method: @method }

  if @params
    hash[:params] = @params #: as untyped
      .to_hash
  end

  hash
end