Skip to content

Commit

Permalink
Delete comment prefix when lazy fetching (#2584)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Sep 20, 2024
1 parent 5c6fc94 commit db50fc3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/ruby_indexer/lib/ruby_indexer/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ def comments
# object is dropped, so this will not prevent updates
if correct_group
correct_group.filter_map do |comment|
content = comment.slice
content if content.valid_encoding?
content = comment.slice.chomp

if content.valid_encoding?
content.delete_prefix!("#")
content.delete_prefix!(" ")
content
end
end.join("\n")
else
""
Expand Down
14 changes: 14 additions & 0 deletions lib/ruby_indexer/test/classes_and_modules_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -605,5 +605,19 @@ class ::Qux
assert_entry("Foo::Bar", Entry::Class, "/fake/path/foo.rb:2-4:3-7")
assert_entry("Qux", Entry::Class, "/fake/path/foo.rb:5-4:6-7")
end

def test_lazy_comment_fetching_uses_correct_line_breaks_for_rendering
path = "lib/ruby_lsp/node_context.rb"
indexable = IndexablePath.new("#{Dir.pwd}/lib", path)

@index.index_single(indexable, collect_comments: false)

entry = @index["RubyLsp::NodeContext"].first

assert_equal(<<~COMMENTS.chomp, entry.comments)
This class allows listeners to access contextual information about a node in the AST, such as its parent,
its namespace nesting, and the surrounding CallNode (e.g. a method call).
COMMENTS
end
end
end

0 comments on commit db50fc3

Please sign in to comment.