Class: PlatformosCheck::LanguageServer::CodeActionEngine
- Inherits:
-
Object
- Object
- PlatformosCheck::LanguageServer::CodeActionEngine
- Includes:
- PositionHelper
- Defined in:
- lib/platformos_check/language_server/code_action_engine.rb
Instance Method Summary collapse
- #code_actions(absolute_path, start_position, end_position, only_kinds = []) ⇒ Object
-
#initialize(storage, diagnostics_manager) ⇒ CodeActionEngine
constructor
A new instance of CodeActionEngine.
Methods included from PositionHelper
#bounded, #from_index_to_row_column, #from_row_column_to_index
Constructor Details
#initialize(storage, diagnostics_manager) ⇒ CodeActionEngine
Returns a new instance of CodeActionEngine.
8 9 10 11 |
# File 'lib/platformos_check/language_server/code_action_engine.rb', line 8 def initialize(storage, diagnostics_manager) @storage = storage @providers = CodeActionProvider.all.map { |c| c.new(storage, diagnostics_manager) } end |
Instance Method Details
#code_actions(absolute_path, start_position, end_position, only_kinds = []) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/platformos_check/language_server/code_action_engine.rb', line 13 def code_actions(absolute_path, start_position, end_position, only_kinds = []) relative_path = @storage.relative_path(absolute_path) buffer = @storage.read(relative_path) start_index = from_row_column_to_index(buffer, start_position[0], start_position[1]) end_index = from_row_column_to_index(buffer, end_position[0], end_position[1]) range = (start_index...end_index) @providers .filter do |provider| only_kinds.empty? || only_kinds.include?(provider.kind) || only_kinds.include?(provider.base_kind) end .flat_map do |provider| provider.code_actions(relative_path, range) end end |