Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions lib/rdoc/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def initialize(rdoc, port)
@store = rdoc.store
@port = port

# Silence stats output — the server prints its own timing.
@rdoc.stats.verbosity = 0
@generator = create_generator
@template_dir = File.expand_path(@generator.template_dir)
@page_cache = {}
Expand Down Expand Up @@ -102,6 +104,12 @@ def start

private

def measure
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield
((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round(1)
end

def create_generator
gen = RDoc::Generator::Aliki.new(@store, @options)
gen.file_output = false
Expand Down Expand Up @@ -138,7 +146,14 @@ def handle_client(client)
return write_response(client, 405, 'text/plain', 'Method Not Allowed')
end

status, content_type, body = route(path)
if path.start_with?('/__') || %r{\A/(?:css|js)/}.match?(path)
status, content_type, body = route(path)
else
duration_ms = measure do
status, content_type, body = route(path)
end
$stderr.puts "#{status} #{path} (#{duration_ms}ms)"
end
write_response(client, status, content_type, body)
rescue => e
write_response(client, 500, 'text/html', <<~HTML)
Expand Down Expand Up @@ -185,6 +200,8 @@ def write_response(client, status, content_type, body)
client.write(header)
client.write(body_bytes)
client.flush
rescue Errno::EPIPE
# Client disconnected before we finished writing — harmless.
end

##
Expand Down Expand Up @@ -347,19 +364,23 @@ def reparse_and_refresh(changed_files, removed_files)
end

unless changed_files.empty?
$stderr.puts "Re-parsing: #{changed_files.join(', ')}"
changed_files.each do |f|
begin
changed_file_names = []
duration_ms = measure do
changed_files.each do |f|
relative = @rdoc.relative_path_for(f)
@store.clear_file_contributions(relative, keep_position: true)
@rdoc.parse_file(f)
@file_mtimes[f] = File.mtime(f) rescue nil
rescue => e
$stderr.puts "Error parsing #{f}: #{e.message}"
changed_file_names << relative
begin
@store.clear_file_contributions(relative, keep_position: true)
@rdoc.parse_file(f)
@file_mtimes[f] = File.mtime(f) rescue nil
rescue => e
$stderr.puts "Error parsing #{f}: #{e.message}"
end
end
end

@store.cleanup_stale_contributions
@store.cleanup_stale_contributions
end
$stderr.puts "Re-parsed #{changed_file_names.join(', ')} (#{duration_ms}ms)"
end

@store.complete(@options.visibility)
Expand Down
13 changes: 10 additions & 3 deletions lib/rdoc/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ def initialize(store, num_files, verbosity = 1)
@start = Time.now
@undoc_params = 0

self.verbosity = verbosity
end

##
# Sets the verbosity level, rebuilding the display outputter.

def verbosity=(verbosity)
@display = case verbosity
when 0 then Quiet.new num_files
when 1 then Normal.new num_files
else Verbose.new num_files
when 0 then Quiet.new @num_files
when 1 then Normal.new @num_files
else Verbose.new @num_files
end
end

Expand Down
Loading