class Solargraph::Diagnostics::TypeCheck


parameters, and invalid param tags.
TypeCheck reports methods with undefined return types, untagged

def diagnose source, api_map

Returns:
  • (Array) -
def diagnose source, api_map
  # return [] unless args.include?('always') || api_map.workspaced?(source.filename)

  severity = Diagnostics::Severities::ERROR
  level = (args.reverse.find { |a| ['normal', 'typed', 'strict', 'strong'].include?(a) }) || :normal
  checker = Solargraph::TypeChecker.new(source.filename, api_map: api_map, level: level.to_sym)
  checker.problems
    .sort { |a, b| a.location.range.start.line <=> b.location.range.start.line }
    .map do |problem|
      {
        range: extract_first_line(problem.location, source),
        severity: severity,
        source: 'Typecheck',
        message: problem.message
      }
    end
end

def extract_first_line location, source

Returns:
  • (Hash) -

Parameters:
  • source (Source) --
  • location (Location) --
def extract_first_line location, source
  return location.range.to_hash if location.range.start.line == location.range.ending.line
  {
    start: {
      line: location.range.start.line,
      character: location.range.start.character
    },
    end: {
      line: location.range.start.line,
      character: last_character(location.range.start, source)
    }
  }
end

def last_character position, source

Returns:
  • (Integer) -

Parameters:
  • source (Solargraph::Source) --
  • position (Solargraph::Position) --
def last_character position, source
  cursor = Position.to_offset(source.code, position)
  source.code.index(/[\r\n]/, cursor) || source.code.length
end