Class: LanguageServer::Protocol::Interface::CodeActionContext

Inherits:
Object
  • Object
show all
Defined in:
lib/language_server/protocol/interface/code_action_context.rb,
sig/language_server/protocol/interface/code_action_context.rbs

Overview

Contains additional diagnostic information about the context in which a CodeActionProvider.provideCodeActions code action is run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diagnostics:, only: nil, trigger_kind: nil) ⇒ CodeActionContext

Returns a new instance of CodeActionContext.

Parameters:

  • diagnostics: (Array[untyped])
  • only: (Array[untyped]) (defaults to: nil)
  • trigger_kind: (Object) (defaults to: nil)


9
10
11
12
13
14
15
16
17
# File 'lib/language_server/protocol/interface/code_action_context.rb', line 9

def initialize(diagnostics:, only: nil, trigger_kind: nil)
  @attributes = {}

  @attributes[:diagnostics] = diagnostics
  @attributes[:only] = only if only
  @attributes[:triggerKind] = trigger_kind if trigger_kind

  @attributes.freeze
end

Instance Attribute Details

#attributesHash[Symbol, untyped] (readonly)

Returns the value of attribute attributes.

Returns:

  • (Hash[Symbol, untyped])


52
53
54
# File 'lib/language_server/protocol/interface/code_action_context.rb', line 52

def attributes
  @attributes
end

Instance Method Details

#diagnosticsDiagnostic[]

An array of diagnostics known on the client side overlapping the range provided to the textDocument/codeAction request. They are provided so that the server knows which errors are currently presented to the user for the given range. There is no guarantee that these accurately reflect the error state of the resource. The primary parameter to compute code actions is the provided range.

Returns:



27
28
29
# File 'lib/language_server/protocol/interface/code_action_context.rb', line 27

def diagnostics
  attributes.fetch(:diagnostics)
end

#onlyCodeActionKind[]

Requested kind of actions to return.

Actions not of this kind are filtered out by the client before being shown. So servers can omit computing them.

Returns:

  • (CodeActionKind[])


38
39
40
# File 'lib/language_server/protocol/interface/code_action_context.rb', line 38

def only
  attributes.fetch(:only)
end

#to_hashHash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


54
55
56
# File 'lib/language_server/protocol/interface/code_action_context.rb', line 54

def to_hash
  attributes
end

#to_json(*args) ⇒ String

Parameters:

  • (Object)

Returns:

  • (String)


58
59
60
# File 'lib/language_server/protocol/interface/code_action_context.rb', line 58

def to_json(*args)
  to_hash.to_json(*args)
end

#trigger_kindCodeActionTriggerKind

The reason why code actions were requested.

Returns:

  • (CodeActionTriggerKind)

Since:

  • 3.17.0



48
49
50
# File 'lib/language_server/protocol/interface/code_action_context.rb', line 48

def trigger_kind
  attributes.fetch(:triggerKind)
end