diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/syntax_suggest/api.rb | 1 | ||||
-rw-r--r-- | lib/syntax_suggest/core_ext.rb | 18 | ||||
-rw-r--r-- | lib/syntax_suggest/mini_stringio.rb | 24 |
3 files changed, 25 insertions, 18 deletions
diff --git a/lib/syntax_suggest/api.rb b/lib/syntax_suggest/api.rb index 65660ec5e5..46c9c8adac 100644 --- a/lib/syntax_suggest/api.rb +++ b/lib/syntax_suggest/api.rb @@ -227,6 +227,7 @@ require_relative "lex_all" require_relative "code_line" require_relative "code_block" require_relative "block_expand" +require_relative "mini_stringio" require_relative "priority_queue" require_relative "unvisited_lines" require_relative "around_block_scan" diff --git a/lib/syntax_suggest/core_ext.rb b/lib/syntax_suggest/core_ext.rb index c299627bb7..94f57ba605 100644 --- a/lib/syntax_suggest/core_ext.rb +++ b/lib/syntax_suggest/core_ext.rb @@ -3,24 +3,6 @@ # Ruby 3.2+ has a cleaner way to hook into Ruby that doesn't use `require` if SyntaxError.method_defined?(:detailed_message) module SyntaxSuggest - # Mini String IO [Private] - # - # Acts like a StringIO with reduced API, but without having to require that - # class. - class MiniStringIO - def initialize(isatty: $stderr.isatty) - @string = +"" - @isatty = isatty - end - - attr_reader :isatty - def puts(value = $/, **) - @string << value - end - - attr_reader :string - end - # SyntaxSuggest.module_for_detailed_message [Private] # # Used to monkeypatch SyntaxError via Module.prepend diff --git a/lib/syntax_suggest/mini_stringio.rb b/lib/syntax_suggest/mini_stringio.rb new file mode 100644 index 0000000000..ee5192ba90 --- /dev/null +++ b/lib/syntax_suggest/mini_stringio.rb @@ -0,0 +1,24 @@ +module SyntaxSuggest + # Mini String IO [Private] + # + # Acts like a StringIO with reduced API, but without having to require that + # class. + class MiniStringIO + EMPTY_ARG = Object.new + + def initialize(isatty: $stderr.isatty) + @string = +"" + @isatty = isatty + end + + attr_reader :isatty + def puts(value = EMPTY_ARG, **) + if !value.equal?(EMPTY_ARG) + @string << value + end + @string << $/ + end + + attr_reader :string + end +end |