Skip to content

Commit 837d5ad

Browse files
authored
Merge pull request #94 from r7kamura/feature/fix-formatting-empty
Fix error when empty content is passed to formatting handler
2 parents fed0477 + 94d864c commit 837d5ad

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/rucoa/handlers/text_document_formatting_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def range
3838
line: 1
3939
),
4040
Position.new(
41-
column: @source.content.lines.last.length,
41+
column: @source.content.lines.last&.length || 0,
4242
line: @source.content.lines.count + 1
4343
)
4444
).to_vscode_range

spec/rucoa/handlers/text_document_formatting_handler_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,28 @@
106106
end
107107
end
108108

109+
context 'when content is empty' do
110+
include_context 'when RuboCop is configured'
111+
112+
let(:content) do
113+
''
114+
end
115+
116+
it 'returns empty edits' do
117+
subject
118+
expect(server.responses).to match(
119+
[
120+
hash_including(
121+
'id' => 1,
122+
'result' => [
123+
a_kind_of(Hash)
124+
]
125+
)
126+
]
127+
)
128+
end
129+
end
130+
109131
context 'when URI is for untitled file' do
110132
include_context 'when RuboCop is configured'
111133
include_context 'with some offenses'

0 commit comments

Comments
 (0)