Skip to content

Commit

Permalink
Prevent lazy comment fetching from failing if file gets deleted (#2661)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Oct 3, 2024
1 parent 6b6dcf8 commit 9154bfc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ruby_indexer/lib/ruby_indexer/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def comments
else
""
end
rescue Errno::ENOENT
# If the file was deleted, but the entry hasn't been removed yet (could happen due to concurrency), then we do
# not want to fail. Just set the comments to an empty string
""
end
end

Expand Down
12 changes: 12 additions & 0 deletions lib/ruby_indexer/test/classes_and_modules_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -630,5 +630,17 @@ def test_lazy_comment_fetching_uses_correct_line_breaks_for_rendering
its namespace nesting, and the surrounding CallNode (e.g. a method call).
COMMENTS
end

def test_lazy_comment_fetching_does_not_fail_if_file_gets_deleted
indexable = IndexablePath.new("#{Dir.pwd}/lib", "lib/ruby_lsp/does_not_exist.rb")

@index.index_single(indexable, <<~RUBY, collect_comments: false)
class Foo
end
RUBY

entry = @index["Foo"].first
assert_empty(entry.comments)
end
end
end

0 comments on commit 9154bfc

Please sign in to comment.