Sha256: 5cd8e64de4bf007e6fc096e7e38f819f6ba7f19101ee5277521d38ca64c870f5

Contents?: true

Size: 1.14 KB

Versions: 13

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module ThemeCheck
  module LanguageServer
    class SourceFixAllCodeActionProvider < CodeActionProvider
      kind "source.fixAll"

      def code_actions(relative_path, _)
        diagnostics = diagnostics_manager
          .diagnostics(relative_path)
          .filter(&:correctable?)
          .reject do |diagnostic|
            # We cannot quickfix if the buffer was modified. This means
            # our diagnostics and InMemoryStorage are out of sync.
            diagnostic.file_version != storage.version(diagnostic.relative_path)
          end
          .map(&:to_h)
        diagnostics_to_code_action(diagnostics)
      end

      private

      def diagnostics_to_code_action(diagnostics)
        return [] if diagnostics.empty?
        [
          {
            title: "Fix all Theme Check auto-fixable problems",
            kind: kind,
            diagnostics: diagnostics,
            command: {
              title: 'fixAll.file',
              command: LanguageServer::CorrectionExecuteCommandProvider.command,
              arguments: diagnostics,
            },
          },
        ]
      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_providers/source_fix_all_code_action_provider.rb
theme-check-1.14.0 lib/theme_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb
theme-check-1.13.0 lib/theme_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb
theme-check-1.12.1 lib/theme_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb
theme-check-1.12.0 lib/theme_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb
theme-check-1.11.0 lib/theme_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb
theme-check-1.10.3 lib/theme_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb
theme-check-1.10.2 lib/theme_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb
theme-check-1.10.1 lib/theme_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb
theme-check-1.10.0 lib/theme_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb
theme-check-1.9.2 lib/theme_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb
theme-check-1.9.1 lib/theme_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb
theme-check-1.9.0 lib/theme_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb