Skip to content

Commit

Permalink
Merge pull request #216 from Shopify/vs/return_nil_if_document_is_alr…
Browse files Browse the repository at this point in the history
…eady_formatted

Return nil if document is already formatted
  • Loading branch information
vinistock authored Jul 25, 2022
2 parents fc780ae + 07c455b commit 00a5508
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests/formatting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def run
return unless formatted_text

size = @document.source.size
return if formatted_text.size == size && formatted_text == @document.source

[
LanguageServer::Protocol::Interface::TextEdit.new(
Expand Down
13 changes: 13 additions & 0 deletions test/requests/formatting_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ def foo
end
end

def test_returns_nil_if_document_is_already_formatted
document = RubyLsp::Document.new(+<<~RUBY)
# typed: strict
# frozen_string_literal: true
class Foo
def foo
end
end
RUBY
assert_nil(RubyLsp::Requests::Formatting.new("file://#{__FILE__}", document).run)
end

private

def with_uninstalled_rubocop(&block)
Expand Down

0 comments on commit 00a5508

Please sign in to comment.