Sha256: 8a3769b86fba5ad2d32b6df85233f1690ac7f09dc2f8e2953dde7bf3b87c517e

Contents?: true

Size: 1.04 KB

Versions: 25

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module PlatformosCheck
  module LanguageServer
    class CodeActionEngine
      include PositionHelper

      def initialize(storage, diagnostics_manager)
        @storage = storage
        @providers = CodeActionProvider.all.map { |c| c.new(storage, diagnostics_manager) }
      end

      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
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
platformos-check-0.4.14 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.13 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.12 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.11 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.10 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.9 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.8 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.7 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.6 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.5 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.4 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.3 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.2 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.1 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.4.0 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.3.3 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.3.1 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.3.0 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.2.2 lib/platformos_check/language_server/code_action_engine.rb
platformos-check-0.2.1 lib/platformos_check/language_server/code_action_engine.rb