Class: RubynCode::Tools::IdeDiagnostics

Inherits:
Base
  • Object
show all
Defined in:
lib/rubyn_code/tools/ide_diagnostics.rb

Overview

Retrieves VS Code diagnostics (errors/warnings from the Problems panel) via the IDE RPC bridge. Only available when running in IDE mode.

Constant Summary collapse

TOOL_NAME =
'ide_diagnostics'
DESCRIPTION =
'Get VS Code diagnostics (errors, warnings) for a file or the whole workspace. Only available in IDE mode.'
PARAMETERS =
{
  file: {
    type: 'string',
    description: 'File path to get diagnostics for. Omit to get all workspace diagnostics.'
  }
}.freeze
RISK_LEVEL =
:read

Constants inherited from Base

Base::REQUIRES_CONFIRMATION

Instance Attribute Summary

Attributes inherited from Base

#project_root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

description, parameters, requires_confirmation?, risk_level, #safe_path, to_schema, tool_name, #truncate

Constructor Details

#initialize(project_root:, ide_client: nil) ⇒ IdeDiagnostics

Returns a new instance of IdeDiagnostics.



18
19
20
21
# File 'lib/rubyn_code/tools/ide_diagnostics.rb', line 18

def initialize(project_root:, ide_client: nil)
  super(project_root: project_root)
  @ide_client = ide_client
end

Class Method Details

.summarize(output, _args) ⇒ Object



45
46
47
48
# File 'lib/rubyn_code/tools/ide_diagnostics.rb', line 45

def self.summarize(output, _args)
  count = output.lines.count
  "#{count} diagnostic(s)"
end

Instance Method Details

#execute(**params) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rubyn_code/tools/ide_diagnostics.rb', line 23

def execute(**params)
  unless @ide_client
    return 'IDE diagnostics are only available when running inside VS Code.'
  end

  rpc_params = {}
  rpc_params[:file] = params[:file] if params[:file]

  result = @ide_client.request('ide/getDiagnostics', rpc_params, timeout: 10)
  diagnostics = result['diagnostics'] || []

  return 'No diagnostics found.' if diagnostics.empty?

  lines = diagnostics.map do |d|
    severity = d['severity']&.upcase || 'INFO'
    source = d['source'] ? " (#{d['source']})" : ''
    "#{severity}: #{d['file']}:#{d['line']}#{d['message']}#{source}"
  end

  lines.join("\n")
end