Sha256: c53d0f4f4b9f42cd8b45daceb3661738fdadbb932ba4b10d4f42b773d5231be3

Contents?: true

Size: 1.03 KB

Versions: 13

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module ThemeCheck
  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

13 entries across 13 versions & 1 rubygems

Version Path
theme-check-1.15.0 lib/theme_check/language_server/code_action_engine.rb
theme-check-1.14.0 lib/theme_check/language_server/code_action_engine.rb
theme-check-1.13.0 lib/theme_check/language_server/code_action_engine.rb
theme-check-1.12.1 lib/theme_check/language_server/code_action_engine.rb
theme-check-1.12.0 lib/theme_check/language_server/code_action_engine.rb
theme-check-1.11.0 lib/theme_check/language_server/code_action_engine.rb
theme-check-1.10.3 lib/theme_check/language_server/code_action_engine.rb
theme-check-1.10.2 lib/theme_check/language_server/code_action_engine.rb
theme-check-1.10.1 lib/theme_check/language_server/code_action_engine.rb
theme-check-1.10.0 lib/theme_check/language_server/code_action_engine.rb
theme-check-1.9.2 lib/theme_check/language_server/code_action_engine.rb
theme-check-1.9.1 lib/theme_check/language_server/code_action_engine.rb
theme-check-1.9.0 lib/theme_check/language_server/code_action_engine.rb