From 3d5febf65b46f1a76759aa68d10f0888748831ab Mon Sep 17 00:00:00 2001 From: schneems Date: Fri, 14 Apr 2023 17:32:45 -0500 Subject: [ruby/syntax_suggest] Clean up output I previously left a comment stating I didn't know why a certain method existed. In investigating the code in `CaptureCodeContext#capture_before_after_kws` I found that it was added as to give a slightly less noisy output. The docs for AroundBlockScan#capture_neighbor_context only describe keywords as being a primary concern. I modified that code to only include lines that are keywords or ends. This reduces the output noise even more. This allows me to remove that `start_at_next_line` method. One weird side effect of the prior logic is it would cause this code to produce this output: ``` class OH def hello def hai end end ``` ``` 1 class OH > 2 def hello 4 def hai 5 end 6 end ``` But this code to produce this output: ``` class OH def hello def hai end end ``` ``` 1 class OH > 2 def hello 4 end 5 end ``` Note the missing `def hai`. The only difference between them is that space. With this change, they're now both consistent. https://github.com/ruby/syntax_suggest/commit/4a54767a3e --- spec/syntax_suggest/integration/syntax_suggest_spec.rb | 4 ---- spec/syntax_suggest/unit/capture_code_context_spec.rb | 5 +++-- spec/syntax_suggest/unit/display_invalid_blocks_spec.rb | 2 ++ 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'spec/syntax_suggest') diff --git a/spec/syntax_suggest/integration/syntax_suggest_spec.rb b/spec/syntax_suggest/integration/syntax_suggest_spec.rb index bb50fafce7..f1ceac23c5 100644 --- a/spec/syntax_suggest/integration/syntax_suggest_spec.rb +++ b/spec/syntax_suggest/integration/syntax_suggest_spec.rb @@ -115,9 +115,6 @@ module SyntaxSuggest expect(io.string).to include(<<~'EOM') 5 module DerailedBenchmarks 6 class RequireTree - 7 REQUIRED_BY = {} - 9 attr_reader :name - 10 attr_writer :cost > 13 def initialize(name) > 18 def self.reset! > 25 end @@ -160,7 +157,6 @@ module SyntaxSuggest out = io.string expect(out).to include(<<~EOM) 16 class Rexe - 18 VERSION = '1.5.1' > 77 class Lookups > 140 def format_requires > 148 end diff --git a/spec/syntax_suggest/unit/capture_code_context_spec.rb b/spec/syntax_suggest/unit/capture_code_context_spec.rb index e1bc281c13..1563149b3c 100644 --- a/spec/syntax_suggest/unit/capture_code_context_spec.rb +++ b/spec/syntax_suggest/unit/capture_code_context_spec.rb @@ -16,13 +16,14 @@ module SyntaxSuggest EOM code_lines = CleanDocument.new(source: source).call.lines - block = CodeBlock.new(lines: code_lines[0]) + block = CodeBlock.new(lines: code_lines[3]) display = CaptureCodeContext.new( blocks: [block], code_lines: code_lines ) - lines = display.call + + lines = display.capture_before_after_kws(block).sort expect(lines.join).to eq(<<~'EOM') def sit end diff --git a/spec/syntax_suggest/unit/display_invalid_blocks_spec.rb b/spec/syntax_suggest/unit/display_invalid_blocks_spec.rb index 2c59d9dc78..b11d7d242e 100644 --- a/spec/syntax_suggest/unit/display_invalid_blocks_spec.rb +++ b/spec/syntax_suggest/unit/display_invalid_blocks_spec.rb @@ -144,6 +144,7 @@ module SyntaxSuggest expect(io.string).to include([ " 1 class OH", "> 2 def hello", + " 3 def hai", " 4 end", " 5 end", "" @@ -162,6 +163,7 @@ module SyntaxSuggest [ " 1 class OH", ["> 2 ", DisplayCodeWithLineNumbers::TERMINAL_HIGHLIGHT, " def hello"].join, + " 3 def hai", " 4 end", " 5 end", "" -- cgit v1.2.1