@@ -300,7 +300,7 @@ std::shared_ptr<vscode::Serializable> LanguageService::OnRangeFormatting(
300300
301301 LuaFormatRange formatRange (static_cast <int >(param->range .start .line ), static_cast <int >(param->range .end .line ));
302302 auto formatResult = LanguageClient::GetInstance ().GetService <CodeFormatService>()->RangeFormat (
303- formatRange, parser, options);
303+ formatRange, parser, * options);
304304
305305 auto & edit = result->edits .emplace_back ();
306306 edit.newText = std::move (formatResult);
@@ -332,17 +332,14 @@ std::shared_ptr<vscode::Serializable> LanguageService::OnTypeFormatting(
332332 return result;
333333 }
334334
335+ LuaCodeStyleOptions tempOptions = *options;
336+ tempOptions.insert_final_newline = true ;
335337
336338 LuaFormatRange formattedRange (static_cast <int >(position.line ) - 1 , static_cast <int >(position.line ) - 1 );
337339
338340 auto formatResult = LanguageClient::GetInstance ().GetService <CodeFormatService>()->RangeFormat (
339- formattedRange, parser, options );
341+ formattedRange, parser, tempOptions );
340342
341- auto totalLine = parser->GetTotalLine ();
342- if (totalLine == position.line && !options->insert_final_newline )
343- {
344- formatResult.push_back (' \n ' );
345- }
346343
347344 auto & edit = result->edits .emplace_back ();
348345 edit.newText = std::move (formatResult);
0 commit comments