diff --git a/lib/ruby_lsp/requests/on_type_formatting.rb b/lib/ruby_lsp/requests/on_type_formatting.rb index 1c6f876fb..cfe0c1f3b 100644 --- a/lib/ruby_lsp/requests/on_type_formatting.rb +++ b/lib/ruby_lsp/requests/on_type_formatting.rb @@ -63,7 +63,7 @@ def perform if (comment_match = @previous_line.match(/^#(\s*)/)) handle_comment_line(T.must(comment_match[1])) elsif @document.syntax_error? - match = /(?<=<<(-|~))(?['"`]?)(?\w+)\k/.match(@previous_line) + match = /(<<((-|~)?))(?['"`]?)(?\w+)\k/.match(@previous_line) heredoc_delimiter = match && match.named_captures["delimiter"] if heredoc_delimiter diff --git a/test/requests/on_type_formatting_test.rb b/test/requests/on_type_formatting_test.rb index a6e4088b2..b808225eb 100644 --- a/test/requests/on_type_formatting_test.rb +++ b/test/requests/on_type_formatting_test.rb @@ -570,6 +570,76 @@ def test_adding_heredoc_delimiter assert_equal(expected_edits.to_json, T.must(edits).to_json) end + def test_plain_heredoc_completion + document = RubyLsp::RubyDocument.new(source: +"", version: 1, uri: URI("file:///fake.rb")) + + document.push_edits( + [{ + range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } }, + text: "str = <