Class: LanguageServer::Protocol::Interface::CodeAction
- Inherits:
-
Object
- Object
- LanguageServer::Protocol::Interface::CodeAction
- 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
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#command ⇒ Command | nil
A command this code action executes.
-
#data ⇒ LSPAny | nil
A data entry field that is preserved on a code action between a
textDocument/codeActionand acodeAction/resolverequest. -
#diagnostics ⇒ Diagnostic[] | nil
The diagnostics that this code action resolves.
-
#disabled ⇒ { reason:string } | nil
Marks that the code action cannot currently be applied.
-
#edit ⇒ WorkspaceEdit | nil
The workspace edit this code action performs.
-
#initialize(title:, kind: nil, diagnostics: nil, is_preferred: nil, disabled: nil, edit: nil, command: nil, data: nil) ⇒ CodeAction
constructor
A new instance of CodeAction.
-
#is_preferred ⇒ boolean | nil
Marks this as a preferred action.
-
#kind ⇒ CodeActionKind | nil
The kind of the code action.
-
#title ⇒ string
A short, human-readable, title for this code action.
- #to_hash ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(title:, kind: nil, diagnostics: nil, is_preferred: nil, disabled: nil, edit: nil, command: nil, data: nil) ⇒ CodeAction
Returns a new instance of CodeAction.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/language_server/protocol/interface/code_action.rb', line 11 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 |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
117 118 119 |
# File 'lib/language_server/protocol/interface/code_action.rb', line 117 def attributes @attributes end |
Instance Method Details
#command ⇒ Command | nil
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.
102 103 104 |
# File 'lib/language_server/protocol/interface/code_action.rb', line 102 def command attributes.fetch(:command) end |
#data ⇒ LSPAny | nil
A data entry field that is preserved on a code action between a textDocument/codeAction and a codeAction/resolve request.
113 114 115 |
# File 'lib/language_server/protocol/interface/code_action.rb', line 113 def data attributes.fetch(:data) end |
#diagnostics ⇒ Diagnostic[] | nil
The diagnostics that this code action resolves.
48 49 50 |
# File 'lib/language_server/protocol/interface/code_action.rb', line 48 def diagnostics attributes.fetch(:diagnostics) end |
#disabled ⇒ { reason:string } | nil
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](https://code.visualstudio.com/docs/editor/editingevolved#_code-action)
code action .
- Disabled actions are shown as faded out in the code action when the user requests a more specific type
of code action, such as refactorings.
- If the user has a [keybinding](https://code.visualstudio.com/docs/editor/refactoring#_keybindings-for-code-actions)
that auto applies a code action and only disabled code actions are returned, the client should show the user an
error with `reason` in the editor.
84 85 86 |
# File 'lib/language_server/protocol/interface/code_action.rb', line 84 def disabled attributes.fetch(:disabled) end |
#edit ⇒ WorkspaceEdit | nil
The workspace edit this code action performs.
92 93 94 |
# File 'lib/language_server/protocol/interface/code_action.rb', line 92 def edit attributes.fetch(:edit) end |
#is_preferred ⇒ boolean | nil
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.
62 63 64 |
# File 'lib/language_server/protocol/interface/code_action.rb', line 62 def is_preferred attributes.fetch(:isPreferred) end |
#kind ⇒ CodeActionKind | nil
The kind of the code action.
Used to filter code actions.
40 41 42 |
# File 'lib/language_server/protocol/interface/code_action.rb', line 40 def kind attributes.fetch(:kind) end |
#title ⇒ string
A short, human-readable, title for this code action.
30 31 32 |
# File 'lib/language_server/protocol/interface/code_action.rb', line 30 def title attributes.fetch(:title) end |
#to_hash ⇒ Object
119 120 121 |
# File 'lib/language_server/protocol/interface/code_action.rb', line 119 def to_hash attributes end |
#to_json(*args) ⇒ Object
123 124 125 |
# File 'lib/language_server/protocol/interface/code_action.rb', line 123 def to_json(*args) to_hash.to_json(*args) end |