Sha256: e80cb5c92325b46fd870470170be44cda64746f248f3cbf4346b72c4745e7b52

Contents?: true

Size: 1.68 KB

Versions: 25

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

module PlatformosCheck
  module LanguageServer
    class CorrectionExecuteCommandProvider < ExecuteCommandProvider
      include URIHelper

      command "correction"

      attr_reader :storage, :bridge, :diagnostics_manager

      def initialize(storage, bridge, diagnostics_manager)
        @storage = storage
        @bridge = bridge
        @diagnostics_manager = diagnostics_manager
      end

      # The arguments passed to this method are the ones forwarded
      # from the selected CodeAction by the client.
      #
      # @param diagnostic_hashes [Array] - of diagnostics
      def execute(diagnostic_hashes)
        # attempt to apply the document changes
        workspace_edit = diagnostics_manager.workspace_edit(diagnostic_hashes)
        result = bridge.send_request('workspace/applyEdit', {
                                       label: 'PlatformOS Check correction',
                                       edit: workspace_edit
                                     })

        # Bail if unable to apply changes
        return unless result[:applied]

        # Clean up internal representation of fixed diagnostics
        diagnostics_update = diagnostics_manager.delete_applied(diagnostic_hashes)

        # Send updated diagnostics to client
        diagnostics_update
          .map do |relative_path, diagnostics|
            bridge.send_notification('textDocument/publishDiagnostics', {
                                       uri: file_uri(storage.path(relative_path)),
                                       diagnostics: diagnostics.map(&:to_h)
                                     })
            storage.path(relative_path)
          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/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.13 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.12 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.11 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.10 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.9 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.8 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.7 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.6 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.5 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.4 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.3 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.2 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.1 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.4.0 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.3.3 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.3.1 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.3.0 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.2.2 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb
platformos-check-0.2.1 lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb