diff options
author | schneems <richard.schneeman+foo@gmail.com> | 2023-04-14 17:32:45 -0500 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-04-25 14:43:06 +0900 |
commit | 3d5febf65b46f1a76759aa68d10f0888748831ab (patch) | |
tree | 9c4828657ec31154f7529476c7bde8f77181e529 /lib | |
parent | f77dc6fb1630f01c2b5dd1a407931c829ad6e77c (diff) | |
download | ruby-3d5febf65b46f1a76759aa68d10f0888748831ab.tar.gz |
[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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/syntax_suggest/around_block_scan.rb | 22 | ||||
-rw-r--r-- | lib/syntax_suggest/capture_code_context.rb | 1 |
2 files changed, 2 insertions, 21 deletions
diff --git a/lib/syntax_suggest/around_block_scan.rb b/lib/syntax_suggest/around_block_scan.rb index 656246c0af..fe63470dee 100644 --- a/lib/syntax_suggest/around_block_scan.rb +++ b/lib/syntax_suggest/around_block_scan.rb @@ -176,7 +176,7 @@ module SyntaxSuggest break end - lines << line + lines << line if line.is_kw? || line.is_end? end lines.reverse! @@ -195,7 +195,7 @@ module SyntaxSuggest break end - lines << line + lines << line if line.is_kw? || line.is_end? end lines @@ -319,24 +319,6 @@ module SyntaxSuggest self end - # TODO: Doc or delete - # - # I don't remember why this is needed, but it's called in code_context. - # It's related to the implementation of `capture_neighbor_context` somehow - # and that display improvement is only triggered when there's one visible line - # - # I think the primary purpose is to not include the current line in the - # logic evaluation of `capture_neighbor_context`. If that's true, then - # we should fix that method to handle this logic instead of only using - # it in one place and together. - def start_at_next_line - before_index - after_index - @before_index -= 1 - @after_index += 1 - self - end - # Return the currently matched lines as a `CodeBlock` # # When a `CodeBlock` is created it will gather metadata about diff --git a/lib/syntax_suggest/capture_code_context.rb b/lib/syntax_suggest/capture_code_context.rb index 547072e2bd..a618b2ec68 100644 --- a/lib/syntax_suggest/capture_code_context.rb +++ b/lib/syntax_suggest/capture_code_context.rb @@ -116,7 +116,6 @@ module SyntaxSuggest return unless block.visible_lines.count == 1 around_lines = AroundBlockScan.new(code_lines: @code_lines, block: block) - .start_at_next_line .capture_neighbor_context around_lines -= block.lines |