Class: LanguageServer::Protocol::Interface::CodeAction

Inherits:
Object
  • Object
show all
Defined in:
lib/language_server/protocol/interface/code_action.rb

Overview

A code action represents a change that can be performed in code, e.g. to fix a problem or to refactor code.

A CodeAction must set either ‘edit` and/or a `command`. If both are supplied, the `edit` is applied first, then the `command` is executed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, kind: nil, diagnostics: nil, is_preferred: nil, edit: nil, command: nil) ⇒ CodeAction

Returns a new instance of CodeAction.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/language_server/protocol/interface/code_action.rb', line 11

def initialize(title:, kind: nil, diagnostics: nil, is_preferred: nil, edit: nil, command: nil)
  @attributes = {}

  @attributes[:title] = title
  @attributes[:kind] = kind if kind
  @attributes[:diagnostics] = diagnostics if diagnostics
  @attributes[:isPreferred] = is_preferred if is_preferred
  @attributes[:edit] = edit if edit
  @attributes[:command] = command if command

  @attributes.freeze
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



80
81
82
# File 'lib/language_server/protocol/interface/code_action.rb', line 80

def attributes
  @attributes
end

Instance Method Details

#commandCommand

A command this code action executes. If a code action provides an edit and a command, first the edit is executed and then the command.

Returns:



76
77
78
# File 'lib/language_server/protocol/interface/code_action.rb', line 76

def command
  attributes.fetch(:command)
end

#diagnosticsDiagnostic[]

The diagnostics that this code action resolves.

Returns:



46
47
48
# File 'lib/language_server/protocol/interface/code_action.rb', line 46

def diagnostics
  attributes.fetch(:diagnostics)
end

#editWorkspaceEdit

The workspace edit this code action performs.

Returns:



66
67
68
# File 'lib/language_server/protocol/interface/code_action.rb', line 66

def edit
  attributes.fetch(:edit)
end

#is_preferredboolean

Marks this as a preferred action. Preferred actions are used by the ‘auto fix` command and can be targeted by keybindings.

A quick fix should be marked preferred if it properly addresses the underlying error. A refactoring should be marked preferred if it is the most reasonable choice of actions to take.

Returns:

  • (boolean)


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

def is_preferred
  attributes.fetch(:isPreferred)
end

#kindstring

The kind of the code action.

Used to filter code actions.

Returns:

  • (string)


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

def kind
  attributes.fetch(:kind)
end

#titlestring

A short, human-readable, title for this code action.

Returns:

  • (string)


28
29
30
# File 'lib/language_server/protocol/interface/code_action.rb', line 28

def title
  attributes.fetch(:title)
end

#to_hashObject



82
83
84
# File 'lib/language_server/protocol/interface/code_action.rb', line 82

def to_hash
  attributes
end

#to_json(*args) ⇒ Object



86
87
88
# File 'lib/language_server/protocol/interface/code_action.rb', line 86

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