Module: Holistic::Ruby::Parser

Defined in:
lib/holistic/ruby/parser/live_editing/process_file_changed.rb,
lib/holistic/ruby/parser/constant_resolution.rb,
lib/holistic/ruby/parser/program_visitor.rb,
lib/holistic/ruby/parser/nesting_syntax.rb,
lib/holistic/ruby/parser.rb

Defined Under Namespace

Classes: ConstantResolution, NestingSyntax, PerformanceMetrics, ProgramVisitor

Constant Summary collapse

HasValidSyntax =
->(content) do
  ::SyntaxTree.parse(content)

  true
rescue ::SyntaxTree::Parser::ParseError
  false
end
ParseFile =
->(application:, file_path:, content:) do
  program = ::SyntaxTree.parse(content)

  constant_resolution = ConstantResolution.new(scope_repository: application.scopes)

  file = ::Holistic::Document::File::Store.call(database: application.database, file_path:)

  visitor = ProgramVisitor.new(application:, constant_resolution:, file:)

  visitor.visit(program)
rescue ::SyntaxTree::Parser::ParseError
  ::Holistic.logger.info("syntax error on file #{file_path}")
end
ParseDirectory =
->(application:, directory_path:) do
  performance_metrics = PerformanceMetrics.new

  ::Dir.glob("#{directory_path}/**/*.rb").map do |file_path|
    performance_metrics.start_file_read!
    content = ::File.read(file_path)
    performance_metrics.end_file_read!

    performance_metrics.start_parse!
    ParseFile.call(application:, file_path:, content:)
    performance_metrics.end_parse!
  end

  performance_metrics
end