Class: PlatformosCheck::LanguageServer::CorrectionExecuteCommandProvider

Inherits:
ExecuteCommandProvider show all
Includes:
URIHelper
Defined in:
lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from URIHelper

#file_path, #file_uri

Methods inherited from ExecuteCommandProvider

all, command, #command, inherited

Constructor Details

#initialize(storage, bridge, diagnostics_manager) ⇒ CorrectionExecuteCommandProvider

Returns a new instance of CorrectionExecuteCommandProvider.



12
13
14
15
16
# File 'lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb', line 12

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

Instance Attribute Details

#bridgeObject (readonly)

Returns the value of attribute bridge.



10
11
12
# File 'lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb', line 10

def bridge
  @bridge
end

#diagnostics_managerObject (readonly)

Returns the value of attribute diagnostics_manager.



10
11
12
# File 'lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb', line 10

def diagnostics_manager
  @diagnostics_manager
end

#storageObject (readonly)

Returns the value of attribute storage.



10
11
12
# File 'lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb', line 10

def storage
  @storage
end

Instance Method Details

#execute(diagnostic_hashes) ⇒ Object

The arguments passed to this method are the ones forwarded from the selected CodeAction by the client.

Parameters:

  • diagnostic_hashes (Array)
    • of diagnostics



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb', line 22

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