yard 0.9.26 → 0.9.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +104 -8
- data/LEGAL +29 -1
- data/LICENSE +1 -1
- data/README.md +9 -2
- data/docs/Tags.md +1 -1
- data/docs/WhatsNew.md +2 -2
- data/lib/yard/autoload.rb +3 -1
- data/lib/yard/cli/command.rb +1 -1
- data/lib/yard/cli/stats.rb +4 -1
- data/lib/yard/cli/yardoc.rb +5 -3
- data/lib/yard/code_objects/base.rb +5 -1
- data/lib/yard/code_objects/macro_object.rb +0 -1
- data/lib/yard/config.rb +5 -1
- data/lib/yard/docstring_parser.rb +1 -2
- data/lib/yard/handlers/processor.rb +0 -1
- data/lib/yard/handlers/ruby/attribute_handler.rb +1 -1
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +1 -1
- data/lib/yard/handlers/ruby/method_handler.rb +2 -2
- data/lib/yard/handlers/ruby/mixin_handler.rb +15 -6
- data/lib/yard/handlers/ruby/module_function_handler.rb +15 -3
- data/lib/yard/handlers/ruby/visibility_handler.rb +13 -1
- data/lib/yard/i18n/locale.rb +1 -1
- data/lib/yard/i18n/message.rb +2 -2
- data/lib/yard/i18n/messages.rb +1 -1
- data/lib/yard/i18n/pot_generator.rb +1 -1
- data/lib/yard/logging.rb +116 -61
- data/lib/yard/open_struct.rb +67 -0
- data/lib/yard/options.rb +1 -1
- data/lib/yard/parser/ruby/ast_node.rb +9 -2
- data/lib/yard/parser/ruby/legacy/ruby_lex.rb +19 -4
- data/lib/yard/parser/ruby/ruby_parser.rb +9 -3
- data/lib/yard/parser/source_parser.rb +4 -5
- data/lib/yard/registry_resolver.rb +2 -1
- data/lib/yard/server/commands/base.rb +1 -1
- data/lib/yard/server/commands/library_command.rb +9 -9
- data/lib/yard/server/commands/static_file_helpers.rb +1 -2
- data/lib/yard/server/http_utils.rb +512 -0
- data/lib/yard/server/rack_adapter.rb +13 -5
- data/lib/yard/tags/default_factory.rb +1 -0
- data/lib/yard/tags/directives.rb +10 -2
- data/lib/yard/tags/tag.rb +3 -2
- data/lib/yard/tags/types_explainer.rb +1 -1
- data/lib/yard/templates/engine.rb +0 -1
- data/lib/yard/templates/helpers/html_helper.rb +5 -2
- data/lib/yard/templates/helpers/markup_helper.rb +2 -1
- data/lib/yard/templates/helpers/method_helper.rb +3 -1
- data/lib/yard/templates/template.rb +3 -1
- data/lib/yard/templates/template_options.rb +0 -1
- data/lib/yard/version.rb +1 -1
- data/lib/yard.rb +6 -0
- data/po/ja.po +19 -19
- data/templates/default/fulldoc/html/css/full_list.css +3 -3
- data/templates/default/fulldoc/html/css/style.css +6 -0
- data/templates/default/fulldoc/html/frames.erb +9 -4
- data/templates/default/fulldoc/html/full_list.erb +5 -2
- data/templates/default/fulldoc/html/js/app.js +294 -264
- data/templates/default/fulldoc/html/js/full_list.js +30 -4
- data/templates/default/fulldoc/html/setup.rb +10 -2
- data/templates/default/layout/html/footer.erb +1 -1
- data/templates/default/onefile/html/headers.erb +2 -0
- data/templates/default/tags/html/example.erb +2 -2
- data/templates/default/tags/html/option.erb +1 -1
- metadata +5 -41
- data/.dockerignore +0 -2
- data/.gitattributes +0 -4
- data/.github/FUNDING.yml +0 -3
- data/.github/ISSUE_TEMPLATE.md +0 -33
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -12
- data/.github/workflows/ci.yml +0 -42
- data/.github/workflows/gem.yml +0 -27
- data/.gitignore +0 -14
- data/.rspec +0 -2
- data/.rubocop.yml +0 -112
- data/.travis.yml +0 -49
- data/CODE_OF_CONDUCT.md +0 -15
- data/CONTRIBUTING.md +0 -140
- data/Dockerfile.samus +0 -28
- data/Gemfile +0 -33
- data/Rakefile +0 -39
- data/SECURITY.md +0 -26
- data/benchmarks/builtins_vs_eval.rb +0 -24
- data/benchmarks/concat_vs_join.rb +0 -13
- data/benchmarks/erb_vs_erubis.rb +0 -54
- data/benchmarks/format_args.rb +0 -47
- data/benchmarks/generation.rb +0 -38
- data/benchmarks/marshal_vs_dbm.rb +0 -64
- data/benchmarks/parsing.rb +0 -46
- data/benchmarks/pathname_vs_string.rb +0 -51
- data/benchmarks/rdoc_vs_yardoc.rb +0 -11
- data/benchmarks/registry_store_types.rb +0 -49
- data/benchmarks/ri_vs_yri.rb +0 -19
- data/benchmarks/ripper_parser.rb +0 -13
- data/benchmarks/splat_vs_flatten.rb +0 -13
- data/benchmarks/template_erb.rb +0 -23
- data/benchmarks/template_format.rb +0 -7
- data/benchmarks/template_profile.rb +0 -18
- data/benchmarks/yri_cache.rb +0 -20
- data/samus.json +0 -49
- data/tasks/update_error_map.rake +0 -53
- data/yard.gemspec +0 -23
data/lib/yard/logging.rb
CHANGED
@@ -1,12 +1,44 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
|
-
require 'logger'
|
4
3
|
require 'thread'
|
5
4
|
|
6
5
|
module YARD
|
7
6
|
# Handles console logging for info, warnings and errors.
|
8
7
|
# Uses the stdlib Logger class in Ruby for all the backend logic.
|
9
|
-
class Logger
|
8
|
+
class Logger
|
9
|
+
# Log severity levels
|
10
|
+
module Severity
|
11
|
+
# Debugging log level
|
12
|
+
DEBUG = 0
|
13
|
+
|
14
|
+
# Information log level
|
15
|
+
INFO = 1
|
16
|
+
|
17
|
+
# Warning log level
|
18
|
+
WARN = 2
|
19
|
+
|
20
|
+
# Error log level
|
21
|
+
ERROR = 3
|
22
|
+
|
23
|
+
# Fatal log level
|
24
|
+
FATAL = 4
|
25
|
+
|
26
|
+
# Unknown log level
|
27
|
+
UNKNOWN = 5
|
28
|
+
|
29
|
+
# @private
|
30
|
+
SEVERITIES = {
|
31
|
+
DEBUG => :debug,
|
32
|
+
INFO => :info,
|
33
|
+
WARN => :warn,
|
34
|
+
ERROR => :error,
|
35
|
+
FATAL => :fatal,
|
36
|
+
UNKNOWN => :unknown
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
include Severity
|
41
|
+
|
10
42
|
# The list of characters displayed beside the progress bar to indicate
|
11
43
|
# "movement".
|
12
44
|
# @since 0.8.2
|
@@ -14,25 +46,31 @@ module YARD
|
|
14
46
|
|
15
47
|
# @return [IO] the IO object being logged to
|
16
48
|
# @since 0.8.2
|
17
|
-
|
18
|
-
def io=(pipe) @logdev = pipe end
|
49
|
+
attr_accessor :io
|
19
50
|
|
20
51
|
# @return [Boolean] whether backtraces should be shown (by default
|
21
52
|
# this is on).
|
22
53
|
def show_backtraces; @show_backtraces || level == DEBUG end
|
23
54
|
attr_writer :show_backtraces
|
24
55
|
|
56
|
+
# @return [DEBUG, INFO, WARN, ERROR, FATAL, UNKNOWN] the logging level
|
57
|
+
attr_accessor :level
|
58
|
+
|
59
|
+
# @return [Boolean] whether a warn message has been emitted. Used for status tracking.
|
60
|
+
attr_accessor :warned
|
61
|
+
|
25
62
|
# @return [Boolean] whether progress indicators should be shown when
|
26
63
|
# logging CLIs (by default this is off).
|
27
64
|
def show_progress
|
28
65
|
return false if YARD.ruby18? # threading is too ineffective for progress support
|
29
|
-
return false if YARD.windows? # windows has poor ANSI support
|
30
66
|
return false unless io.tty? # no TTY support on IO
|
31
67
|
return false unless level > INFO # no progress in verbose/debug modes
|
32
68
|
@show_progress
|
33
69
|
end
|
34
70
|
attr_writer :show_progress
|
35
71
|
|
72
|
+
# @!group Constructor Methods
|
73
|
+
|
36
74
|
# The logger instance
|
37
75
|
# @return [Logger] the logger instance
|
38
76
|
def self.instance(pipe = STDOUT)
|
@@ -40,13 +78,12 @@ module YARD
|
|
40
78
|
end
|
41
79
|
|
42
80
|
# Creates a new logger
|
81
|
+
# @private
|
43
82
|
def initialize(pipe, *args)
|
44
|
-
super(pipe, *args)
|
45
83
|
self.io = pipe
|
46
84
|
self.show_backtraces = true
|
47
85
|
self.show_progress = false
|
48
86
|
self.level = WARN
|
49
|
-
self.formatter = method(:format_log)
|
50
87
|
self.warned = false
|
51
88
|
@progress_indicator = 0
|
52
89
|
@mutex = Mutex.new
|
@@ -54,36 +91,64 @@ module YARD
|
|
54
91
|
@progress_last_update = Time.now
|
55
92
|
end
|
56
93
|
|
57
|
-
#
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
|
94
|
+
# @!macro [attach] logger.create_log_method
|
95
|
+
# @method $1(message)
|
96
|
+
# Logs a message with the $1 severity level.
|
97
|
+
# @param message [String] the message to log
|
98
|
+
# @see #log
|
99
|
+
# @return [void]
|
100
|
+
# @private
|
101
|
+
def self.create_log_method(name)
|
102
|
+
severity = Severity.const_get(name.to_s.upcase)
|
103
|
+
define_method(name) { |message| log(severity, message) }
|
62
104
|
end
|
63
105
|
|
106
|
+
# @!group Logging Methods
|
107
|
+
|
108
|
+
create_log_method :info
|
109
|
+
create_log_method :error
|
110
|
+
create_log_method :fatal
|
111
|
+
create_log_method :unknown
|
112
|
+
|
113
|
+
# Changes the debug level to DEBUG if $DEBUG is set and writes a debugging message.
|
114
|
+
create_log_method :debug
|
115
|
+
|
64
116
|
# Remembers when a warning occurs and writes a warning message.
|
65
|
-
|
66
|
-
|
67
|
-
|
117
|
+
create_log_method :warn
|
118
|
+
|
119
|
+
# Logs a message with a given severity
|
120
|
+
# @param severity [DEBUG, INFO, WARN, ERROR, FATAL, UNKNOWN] the severity level
|
121
|
+
# @param message [String] the message to log
|
122
|
+
def log(severity, message)
|
123
|
+
self.level = DEBUG if $DEBUG
|
124
|
+
return unless severity >= level
|
125
|
+
|
126
|
+
self.warned = true if severity == WARN
|
127
|
+
clear_line
|
128
|
+
puts "[#{SEVERITIES[severity].to_s.downcase}]: #{message}"
|
68
129
|
end
|
69
|
-
attr_accessor :warned
|
70
130
|
|
71
|
-
#
|
72
|
-
|
131
|
+
# @!group Level Control Methods
|
132
|
+
|
133
|
+
# Sets the logger level for the duration of the block
|
73
134
|
#
|
74
|
-
# @
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
# @
|
79
|
-
#
|
80
|
-
|
81
|
-
|
135
|
+
# @example
|
136
|
+
# log.enter_level(Logger::ERROR) do
|
137
|
+
# YARD.parse_string "def x; end"
|
138
|
+
# end
|
139
|
+
# @param [Fixnum] new_level the logger level for the duration of the block.
|
140
|
+
# values can be found in Ruby's Logger class.
|
141
|
+
# @yield the block with the logger temporarily set to +new_level+
|
142
|
+
def enter_level(new_level = level)
|
143
|
+
old_level = level
|
144
|
+
self.level = new_level
|
82
145
|
yield
|
83
146
|
ensure
|
84
|
-
|
147
|
+
self.level = old_level
|
85
148
|
end
|
86
149
|
|
150
|
+
# @!group Utility Printing Methods
|
151
|
+
|
87
152
|
# Displays a progress indicator for a given message. This progress report
|
88
153
|
# is only displayed on TTY displays, otherwise the message is passed to
|
89
154
|
# the +nontty_log+ level.
|
@@ -120,7 +185,7 @@ module YARD
|
|
120
185
|
# @since 0.8.2
|
121
186
|
def clear_progress
|
122
187
|
return unless show_progress
|
123
|
-
|
188
|
+
io.write("\e[?25h\e[2K")
|
124
189
|
@progress_msg = nil
|
125
190
|
end
|
126
191
|
|
@@ -133,16 +198,13 @@ module YARD
|
|
133
198
|
print("#{msg}\n")
|
134
199
|
end
|
135
200
|
|
136
|
-
alias print_no_newline <<
|
137
|
-
private :print_no_newline
|
138
|
-
|
139
201
|
# Displays an unformatted line to the logger output stream.
|
140
202
|
# @param [String] msg the message to display
|
141
203
|
# @return [void]
|
142
204
|
# @since 0.8.2
|
143
205
|
def print(msg = '')
|
144
206
|
clear_line
|
145
|
-
|
207
|
+
io.write(msg)
|
146
208
|
end
|
147
209
|
alias << print
|
148
210
|
|
@@ -158,48 +220,41 @@ module YARD
|
|
158
220
|
exc.backtrace[0..5].map {|x| "\n\t#{x}" }.join + "\n")
|
159
221
|
end
|
160
222
|
|
223
|
+
# @!group Benchmarking Methods
|
224
|
+
|
225
|
+
# Captures the duration of a block of code for benchmark analysis. Also
|
226
|
+
# calls {#progress} on the message to display it to the user.
|
227
|
+
#
|
228
|
+
# @todo Implement capture storage for reporting of benchmarks
|
229
|
+
# @param [String] msg the message to display
|
230
|
+
# @param [Symbol, nil] nontty_log the level to log as if the output
|
231
|
+
# stream is not a TTY. Use +nil+ for no alternate logging.
|
232
|
+
# @yield a block of arbitrary code to benchmark
|
233
|
+
# @return [void]
|
234
|
+
def capture(msg, nontty_log = :debug)
|
235
|
+
progress(msg, nontty_log)
|
236
|
+
yield
|
237
|
+
ensure
|
238
|
+
clear_progress
|
239
|
+
end
|
240
|
+
|
241
|
+
# @!endgroup
|
242
|
+
|
161
243
|
# Warns that the Ruby environment does not support continuations. Applies
|
162
244
|
# to JRuby, Rubinius and MacRuby. This warning will only display once
|
163
245
|
# per Ruby process.
|
164
246
|
#
|
165
247
|
# @deprecated Continuations are no longer needed by YARD 0.8.0+.
|
166
248
|
# @return [void]
|
249
|
+
# @private
|
167
250
|
def warn_no_continuations
|
168
251
|
end
|
169
252
|
|
170
|
-
# Sets the logger level for the duration of the block
|
171
|
-
#
|
172
|
-
# @example
|
173
|
-
# log.enter_level(Logger::ERROR) do
|
174
|
-
# YARD.parse_string "def x; end"
|
175
|
-
# end
|
176
|
-
# @param [Fixnum] new_level the logger level for the duration of the block.
|
177
|
-
# values can be found in Ruby's Logger class.
|
178
|
-
# @yield the block with the logger temporarily set to +new_level+
|
179
|
-
def enter_level(new_level = level)
|
180
|
-
old_level = level
|
181
|
-
self.level = new_level
|
182
|
-
yield
|
183
|
-
ensure
|
184
|
-
self.level = old_level
|
185
|
-
end
|
186
|
-
|
187
253
|
private
|
188
254
|
|
189
|
-
# Override this internal Logger method to clear line
|
190
|
-
def add(*args)
|
191
|
-
clear_line
|
192
|
-
super(*args)
|
193
|
-
end
|
194
|
-
|
195
255
|
def clear_line
|
196
256
|
return unless @progress_msg
|
197
|
-
|
198
|
-
end
|
199
|
-
|
200
|
-
# Log format (from Logger implementation). Used by Logger internally
|
201
|
-
def format_log(sev, _time, _prog, msg)
|
202
|
-
"[#{sev.downcase}]: #{msg}\n"
|
257
|
+
io.write("\e[2K\r")
|
203
258
|
end
|
204
259
|
end
|
205
260
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module YARD
|
2
|
+
# An OpenStruct compatible struct class that allows for basic access of attributes
|
3
|
+
# via +struct.attr_name+ and +struct.attr_name = value+.
|
4
|
+
class OpenStruct
|
5
|
+
def initialize(hash = {})
|
6
|
+
@table = hash.each_pair { |k, v| [k.to_sym, v] }
|
7
|
+
end
|
8
|
+
|
9
|
+
# @private
|
10
|
+
def method_missing(name, *args)
|
11
|
+
if name.to_s.end_with?('=')
|
12
|
+
varname = name.to_s[0..-2].to_sym
|
13
|
+
__cache_lookup__(varname)
|
14
|
+
send(name, args.first)
|
15
|
+
else
|
16
|
+
__cache_lookup__(name)
|
17
|
+
send(name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_h
|
22
|
+
@table.dup
|
23
|
+
end
|
24
|
+
|
25
|
+
def ==(other)
|
26
|
+
other.is_a?(self.class) && to_h == other.to_h
|
27
|
+
end
|
28
|
+
|
29
|
+
def hash
|
30
|
+
@table.hash
|
31
|
+
end
|
32
|
+
|
33
|
+
def dig(*keys)
|
34
|
+
@table.dig(*keys)
|
35
|
+
end
|
36
|
+
|
37
|
+
def []=(key, value)
|
38
|
+
@table[key.to_sym] = value
|
39
|
+
end
|
40
|
+
|
41
|
+
def [](key)
|
42
|
+
@table[key.to_sym]
|
43
|
+
end
|
44
|
+
|
45
|
+
def each_pair(&block)
|
46
|
+
@table.each_pair(&block)
|
47
|
+
end
|
48
|
+
|
49
|
+
def marshal_dump
|
50
|
+
@table
|
51
|
+
end
|
52
|
+
|
53
|
+
def marshal_load(data)
|
54
|
+
@table = data
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def __cache_lookup__(name)
|
60
|
+
key = name.to_sym.inspect
|
61
|
+
instance_eval <<-RUBY, __FILE__, __LINE__ + 1
|
62
|
+
def #{name}; @table[#{key}]; end
|
63
|
+
def #{name.to_s.sub('?','_')}=(v); @table[#{key}] = v; end unless #{key}.to_s.include?('?')
|
64
|
+
RUBY
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/yard/options.rb
CHANGED
@@ -94,7 +94,7 @@ module YARD
|
|
94
94
|
#
|
95
95
|
# @example Setting an option with Hash syntax
|
96
96
|
# options[:format] = :html # equivalent to: options.format = :html
|
97
|
-
# @param [Symbol, String] key the
|
97
|
+
# @param [Symbol, String] key the option to set
|
98
98
|
# @param [Object] value the value to set for the option
|
99
99
|
# @return [Object] the value being set
|
100
100
|
def []=(key, value) send("#{key}=", value) end
|
@@ -426,6 +426,13 @@ module YARD
|
|
426
426
|
def block_param
|
427
427
|
self[-1] ? self[-1][0] : nil
|
428
428
|
end
|
429
|
+
|
430
|
+
def args_forward
|
431
|
+
# shape is (required, optional, rest, more, keyword, keyword_rest, block)
|
432
|
+
# Ruby 3.1 moves :args_forward from rest to keyword_rest
|
433
|
+
args_index = YARD.ruby31? ? -2 : 2
|
434
|
+
self[args_index].type == :args_forward if self[args_index]
|
435
|
+
end
|
429
436
|
end
|
430
437
|
|
431
438
|
class MethodCallNode < AstNode
|
@@ -480,7 +487,7 @@ module YARD
|
|
480
487
|
end
|
481
488
|
|
482
489
|
def parameters(include_block_param = true)
|
483
|
-
params = self[1 + index_adjust]
|
490
|
+
return unless params = self[1 + index_adjust]
|
484
491
|
params = params[0] if params.type == :paren
|
485
492
|
include_block_param ? params : params[0...-1]
|
486
493
|
end
|
@@ -488,7 +495,7 @@ module YARD
|
|
488
495
|
def signature
|
489
496
|
params_src = ''
|
490
497
|
params = self[1 + index_adjust]
|
491
|
-
if params.first
|
498
|
+
if params and params.first
|
492
499
|
params_src = params.type == :paren ? '' : ' '
|
493
500
|
params_src += params.source.gsub(/\s+(\s|\))/m, '\1')
|
494
501
|
end
|
@@ -656,7 +656,7 @@ module YARD
|
|
656
656
|
if @lex_state != EXPR_END && @lex_state != EXPR_CLASS &&
|
657
657
|
(@lex_state != EXPR_ARG || @space_seen)
|
658
658
|
c = peek(0)
|
659
|
-
tk = identify_here_document if /[
|
659
|
+
tk = identify_here_document if /[-~\w\"\'\`]/ =~ c
|
660
660
|
end
|
661
661
|
if !tk
|
662
662
|
@lex_state = EXPR_BEG
|
@@ -1063,6 +1063,8 @@ module YARD
|
|
1063
1063
|
ch = getc
|
1064
1064
|
if ch == "-"
|
1065
1065
|
ch = getc
|
1066
|
+
elsif ch == "~"
|
1067
|
+
ch = getc
|
1066
1068
|
indent = true
|
1067
1069
|
end
|
1068
1070
|
if /['"`]/ =~ ch # '
|
@@ -1096,9 +1098,12 @@ module YARD
|
|
1096
1098
|
str = String.new
|
1097
1099
|
while (l = gets)
|
1098
1100
|
l.chomp!
|
1099
|
-
l
|
1100
|
-
|
1101
|
-
|
1101
|
+
if l == quoted
|
1102
|
+
str = dedent(str) if indent
|
1103
|
+
break
|
1104
|
+
else
|
1105
|
+
str << l.chomp << "\n"
|
1106
|
+
end
|
1102
1107
|
end
|
1103
1108
|
|
1104
1109
|
@reader.divert_read_from(reserve)
|
@@ -1108,6 +1113,16 @@ module YARD
|
|
1108
1113
|
Token(Ltype2Token[lt], str).set_text(str.dump)
|
1109
1114
|
end
|
1110
1115
|
|
1116
|
+
def dedent(str)
|
1117
|
+
lines = str.split("\n", -1)
|
1118
|
+
dedent_amt = lines.map do |line|
|
1119
|
+
line =~ /\S/ ? line.match(/^ */).offset(0)[1] : nil
|
1120
|
+
end.compact.min || 0
|
1121
|
+
return str if dedent_amt.zero?
|
1122
|
+
|
1123
|
+
lines.map { |line| line =~ /\S/ ? line.gsub(/^ {#{dedent_amt}}/, "") : line }.join("\n")
|
1124
|
+
end
|
1125
|
+
|
1111
1126
|
def identify_quotation(initial_char)
|
1112
1127
|
ch = getc
|
1113
1128
|
if lt = PERCENT_LTYPE[ch]
|
@@ -133,6 +133,12 @@ module YARD
|
|
133
133
|
AST_TOKENS = [:CHAR, :backref, :const, :cvar, :gvar, :heredoc_end, :ident,
|
134
134
|
:int, :float, :ivar, :label, :period, :regexp_end, :tstring_content, :backtick]
|
135
135
|
|
136
|
+
COMMENT_SKIP_NODE_TYPES = [
|
137
|
+
:comment,
|
138
|
+
:void_stmt,
|
139
|
+
:list
|
140
|
+
].freeze
|
141
|
+
|
136
142
|
MAPPINGS.each do |k, v|
|
137
143
|
if Array === v
|
138
144
|
v.each {|vv| (REV_MAPPINGS[vv] ||= []) << k }
|
@@ -144,7 +150,7 @@ module YARD
|
|
144
150
|
PARSER_EVENT_TABLE.each do |event, arity|
|
145
151
|
node_class = AstNode.node_class_for(event)
|
146
152
|
|
147
|
-
if /_new\z/ =~ event.to_s
|
153
|
+
if arity == 0 && /_new\z/ =~ event.to_s
|
148
154
|
module_eval(<<-eof, __FILE__, __LINE__ + 1)
|
149
155
|
def on_#{event}(*args)
|
150
156
|
#{node_class}.new(:list, args, :listchar => charno...charno, :listline => lineno..lineno)
|
@@ -370,7 +376,7 @@ module YARD
|
|
370
376
|
|
371
377
|
def on_aref(*args)
|
372
378
|
@map[:lbracket].pop
|
373
|
-
ll, lc = *@map[:aref].
|
379
|
+
ll, lc = *@map[:aref].shift
|
374
380
|
sr = args.first.source_range.first..lc
|
375
381
|
lr = args.first.line_range.first..ll
|
376
382
|
AstNode.new(:aref, args, :char => sr, :line => lr)
|
@@ -613,7 +619,7 @@ module YARD
|
|
613
619
|
|
614
620
|
def insert_comments
|
615
621
|
root.traverse do |node|
|
616
|
-
next if
|
622
|
+
next if COMMENT_SKIP_NODE_TYPES.include?(node.type) || node.parent.type != :list
|
617
623
|
|
618
624
|
# never attach comments to if/unless mod nodes
|
619
625
|
if node.type == :if_mod || node.type == :unless_mod
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'stringio'
|
3
|
-
require 'ostruct'
|
4
3
|
|
5
4
|
module YARD
|
6
5
|
module Parser
|
@@ -108,7 +107,8 @@ module YARD
|
|
108
107
|
files = [paths].flatten.
|
109
108
|
map {|p| File.directory?(p) ? "#{p}/**/*.{rb,c,cc,cxx,cpp}" : p }.
|
110
109
|
map {|p| p.include?("*") ? Dir[p].sort_by {|d| [d.length, d] } : p }.flatten.
|
111
|
-
reject {|p| !File.file?(p) || excluded.any? {|re| p =~ re } }
|
110
|
+
reject {|p| !File.file?(p) || excluded.any? {|re| p =~ re } }.
|
111
|
+
map {|p| p.encoding == Encoding.default_external ? p : p.dup.force_encoding(Encoding.default_external) }
|
112
112
|
|
113
113
|
log.enter_level(level) do
|
114
114
|
parse_in_order(*files.uniq)
|
@@ -476,9 +476,8 @@ module YARD
|
|
476
476
|
content.force_encoding('binary')
|
477
477
|
ENCODING_BYTE_ORDER_MARKS.each do |encoding, bom|
|
478
478
|
bom.force_encoding('binary')
|
479
|
-
if content
|
480
|
-
content.force_encoding(encoding)
|
481
|
-
return content
|
479
|
+
if content.start_with?(bom)
|
480
|
+
return content.sub(bom, '').force_encoding(encoding)
|
482
481
|
end
|
483
482
|
end
|
484
483
|
content.force_encoding('utf-8') # UTF-8 is default encoding
|
@@ -132,7 +132,8 @@ module YARD
|
|
132
132
|
|
133
133
|
path.scan(split_on_separators_match).each do |part, sep|
|
134
134
|
cur_obj = nil
|
135
|
-
pos +=
|
135
|
+
pos += part.length
|
136
|
+
pos += sep.length
|
136
137
|
parsed_end = pos == path.length
|
137
138
|
|
138
139
|
if !last_obj || (!parsed_end && !last_obj.is_a?(CodeObjects::NamespaceObject))
|
@@ -31,7 +31,7 @@ module YARD
|
|
31
31
|
# @abstract
|
32
32
|
class LibraryCommand < Base
|
33
33
|
begin
|
34
|
-
Process.fork {
|
34
|
+
Process.fork { }
|
35
35
|
CAN_FORK = true
|
36
36
|
rescue Exception # rubocop:disable Lint/RescueException
|
37
37
|
CAN_FORK = false
|
@@ -94,16 +94,16 @@ module YARD
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def call_with_fork(request, &block)
|
97
|
-
reader, writer
|
97
|
+
IO.pipe(:binmode => true) do |reader, writer|
|
98
|
+
fork do
|
99
|
+
log.debug "[pid=#{Process.pid}] fork serving: #{request.path}"
|
100
|
+
reader.close
|
101
|
+
writer.print(Marshal.dump(call_without_fork(request, &block)))
|
102
|
+
end
|
98
103
|
|
99
|
-
|
100
|
-
|
101
|
-
reader.close
|
102
|
-
writer.print(Marshal.dump(call_without_fork(request, &block)))
|
104
|
+
writer.close
|
105
|
+
Marshal.load(reader.read)
|
103
106
|
end
|
104
|
-
|
105
|
-
writer.close
|
106
|
-
Marshal.load(reader.read)
|
107
107
|
end
|
108
108
|
|
109
109
|
def can_fork?
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'webrick/httputils'
|
3
2
|
|
4
3
|
module YARD
|
5
4
|
module Server
|
@@ -7,7 +6,7 @@ module YARD
|
|
7
6
|
# Include this module to get access to {#static_template_file?}
|
8
7
|
# and {favicon?} helpers.
|
9
8
|
module StaticFileHelpers
|
10
|
-
include
|
9
|
+
include Server::HTTPUtils
|
11
10
|
|
12
11
|
# Serves an empty favicon.
|
13
12
|
# @raise [FinishRequest] finalizes an empty body if the path matches
|