class LanguageServer::Protocol::Interface::CodeAction

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.

Attributes

attributes[R]

Public Class Methods

new(title:, kind: nil, diagnostics: nil, is_preferred: nil, disabled: nil, edit: nil, command: nil, data: nil) click to toggle source
# File lib/language_server/protocol/interface/code_action.rb, line 12
def initialize(title:, kind: nil, diagnostics: nil, is_preferred: nil, disabled: nil, edit: nil, command: nil, data: nil)
  @attributes = {}

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

  @attributes.freeze
end

Public Instance Methods

command() click to toggle source

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.

@return [Command]

# File lib/language_server/protocol/interface/code_action.rb, line 102
def command
  attributes.fetch(:command)
end
data() click to toggle source

A data entry field that is preserved on a code action between a `textDocument/codeAction` and a `codeAction/resolve` request.

@return [any]

# File lib/language_server/protocol/interface/code_action.rb, line 111
def data
  attributes.fetch(:data)
end
diagnostics() click to toggle source

The diagnostics that this code action resolves.

@return [Diagnostic

# File lib/language_server/protocol/interface/code_action.rb, line 49
def diagnostics
  attributes.fetch(:diagnostics)
end
disabled() click to toggle source

Marks that the code action cannot currently be applied.

Clients should follow the following guidelines regarding disabled code actions:

  • Disabled code actions are not shown in automatic lightbulbs code

action menus.

  • Disabled actions are shown as faded out in the code action menu when

the user request a more specific type of code action, such as refactorings.

  • If the user has a keybinding that auto applies a code action and only

a disabled code actions are returned, the client should show the user an error message with `reason` in the editor.

@return [{ reason: string; }]

# File lib/language_server/protocol/interface/code_action.rb, line 84
def disabled
  attributes.fetch(:disabled)
end
edit() click to toggle source

The workspace edit this code action performs.

@return [WorkspaceEdit]

# File lib/language_server/protocol/interface/code_action.rb, line 92
def edit
  attributes.fetch(:edit)
end
is_preferred() click to toggle source

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.

@return [boolean]

# File lib/language_server/protocol/interface/code_action.rb, line 62
def is_preferred
  attributes.fetch(:isPreferred)
end
kind() click to toggle source

The kind of the code action.

Used to filter code actions.

@return [string]

# File lib/language_server/protocol/interface/code_action.rb, line 41
def kind
  attributes.fetch(:kind)
end
title() click to toggle source

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

@return [string]

# File lib/language_server/protocol/interface/code_action.rb, line 31
def title
  attributes.fetch(:title)
end
to_hash() click to toggle source
# File lib/language_server/protocol/interface/code_action.rb, line 117
def to_hash
  attributes
end
to_json(*args) click to toggle source
# File lib/language_server/protocol/interface/code_action.rb, line 121
def to_json(*args)
  to_hash.to_json(*args)
end