1515#include " Util/FileFinder.h"
1616
1717LuaFormat::LuaFormat () {
18+ _diagnosticStyle.name_style_check = false ;
1819}
1920
2021void LuaFormat::SetWorkspace (std::string_view workspace) {
@@ -156,7 +157,15 @@ bool LuaFormat::ReformatSingleFile(std::string_view inputPath, std::string_view
156157
157158bool LuaFormat::Check () {
158159 if (_mode == WorkMode::File) {
159- return CheckSingleFile (_inputPath, std::move (_inputFileText));
160+ if (_inputPath != " stdin" ) {
161+ std::cerr << util::format (" Check {} ..." , _inputPath) << std::endl;
162+ }
163+
164+ if (CheckSingleFile (_inputPath, std::move (_inputFileText))) {
165+ std::cerr << util::format (" Check {} ... ok" , _inputPath) << std::endl;
166+ return true ;
167+ }
168+ return false ;
160169 }
161170 return CheckWorkspace ();
162171}
@@ -167,7 +176,7 @@ void LuaFormat::DiagnosticInspection(std::string_view message, TextRange range,
167176 auto startChar = file->GetColumn (range.StartOffset );
168177 auto endLine = file->GetLine (range.EndOffset );
169178 auto endChar = file->GetColumn (range.EndOffset );
170- std::cout << util::format (" \t {}({}:{} to {}:{}): {}" , path, startLine + 1 , startChar, endLine + 1 , endChar,
179+ std::cerr << util::format (" \t {}({}:{} to {}:{}): {}" , path, startLine + 1 , startChar, endLine + 1 , endChar,
171180 message) << std::endl;
172181}
173182
@@ -269,14 +278,17 @@ bool LuaFormat::CheckWorkspace() {
269278 auto files = finder.FindFiles ();
270279 for (auto &filePath: files) {
271280 auto opText = ReadFile (filePath);
281+ std::string displayPath = filePath;
282+ if (!_workspace.empty ())
283+ {
284+ displayPath = string_util::GetFileRelativePath (_workspace, filePath);
285+ }
272286 if (opText.has_value ()) {
273- if (CheckSingleFile (filePath, std::move (opText.value ()))) {
274- std::cerr << util::format (" Check {} ok." , filePath) << std::endl;
275- } else {
276- std::cerr << util::format (" Check {} fail." , filePath) << std::endl;
287+ if (CheckSingleFile (displayPath, std::move (opText.value ()))) {
288+ std::cerr << util::format (" Check {} ok." , displayPath) << std::endl;
277289 }
278290 } else {
279- std::cerr << util::format (" Can not read file {}" , filePath ) << std::endl;
291+ std::cerr << util::format (" Can not read file {}" , displayPath ) << std::endl;
280292 }
281293 }
282294 return true ;
@@ -317,17 +329,26 @@ bool LuaFormat::ReformatWorkspace() {
317329 auto files = finder.FindFiles ();
318330 for (auto &filePath: files) {
319331 auto opText = ReadFile (filePath);
332+ std::string displayPath = filePath;
333+ if (!_workspace.empty ())
334+ {
335+ displayPath = string_util::GetFileRelativePath (_workspace, filePath);
336+ }
320337 if (opText.has_value ()) {
321- if (ReformatSingleFile (filePath , filePath, std::move (opText.value ()))) {
322- std::cerr << util::format (" Reformat {} succeed." , filePath ) << std::endl;
338+ if (ReformatSingleFile (displayPath , filePath, std::move (opText.value ()))) {
339+ std::cerr << util::format (" Reformat {} succeed." , displayPath ) << std::endl;
323340 } else {
324- std::cerr << util::format (" Reformat {} fail." , filePath ) << std::endl;
341+ std::cerr << util::format (" Reformat {} fail." , displayPath ) << std::endl;
325342 }
326343 } else {
327- std::cerr << util::format (" Can not read file {}" , filePath ) << std::endl;
344+ std::cerr << util::format (" Can not read file {}" , displayPath ) << std::endl;
328345 }
329346 }
330347 return true ;
331348}
332349
350+ void LuaFormat::SupportNameStyleCheck () {
351+ _diagnosticStyle.name_style_check = true ;
352+ }
353+
333354
0 commit comments