@@ -41,11 +41,11 @@ bool IsSubRelative(std::filesystem::path& path, std::filesystem::path base)
4141{
4242 auto relative = std::filesystem::relative (path, base);
4343 auto relativeString = relative.string ();
44- if (relativeString.empty ())
44+ if (relativeString.empty ())
4545 {
4646 return false ;
4747 }
48- if (relativeString == " ." )
48+ if (relativeString == " ." )
4949 {
5050 return true ;
5151 }
@@ -54,30 +54,29 @@ bool IsSubRelative(std::filesystem::path& path, std::filesystem::path base)
5454
5555void LuaFormat::AutoDetectConfigRoot (std::string_view root)
5656{
57- if (_inputFile.empty ())
57+ if (_inputFile.empty ())
5858 {
5959 return ;
6060 }
6161 std::filesystem::path workspace (root);
6262 std::filesystem::path inputPath (_inputFile);
63- if (!IsSubRelative (inputPath, workspace))
63+ if (!IsSubRelative (inputPath, workspace))
6464 {
6565 return ;
6666 }
6767
6868 auto directory = inputPath.parent_path ();
69- while (IsSubRelative (directory, workspace))
69+ while (IsSubRelative (directory, workspace))
7070 {
7171 auto editorconfigPath = directory / " .editorconfig" ;
72- if (std::filesystem::exists (editorconfigPath))
72+ if (std::filesystem::exists (editorconfigPath))
7373 {
7474 SetConfigPath (editorconfigPath.string ());
7575 return ;
7676 }
7777
7878 directory = directory.parent_path ();
7979 }
80-
8180}
8281
8382void LuaFormat::SetConfigPath (std::string_view config)
@@ -115,7 +114,7 @@ bool LuaFormat::Reformat()
115114 }
116115 }
117116
118- if (_outFile.empty ())
117+ if (_outFile.empty ())
119118 {
120119 _options->end_of_line = " \n " ;
121120 }
@@ -143,6 +142,16 @@ bool LuaFormat::Check()
143142
144143 if (_parser->HasError ())
145144 {
145+ auto errors = _parser->GetErrors ();
146+
147+ std::cerr << format (" Check {}\t {} error" , _inputFile, errors.size ()) << std::endl;
148+
149+ for (auto & error : errors)
150+ {
151+ auto luaFile = _parser->GetLuaFile ();
152+ DiagnosisInspection (error.ErrorMessage , error.ErrorRange , luaFile);
153+ }
154+
146155 return false ;
147156 }
148157
@@ -161,12 +170,34 @@ bool LuaFormat::Check()
161170 auto diagnosis = formatter.GetDiagnosisInfos ();
162171 if (!diagnosis.empty ())
163172 {
173+ std::cerr << format (" Check {}\t {} warning" , _inputFile, diagnosis.size ()) << std::endl;
174+
164175 for (auto & d : diagnosis)
165176 {
166- std::cout << format (" {} from {}:{} to {}:{}" , d.Message , d.Range .Start .Line , d.Range .Start .Character ,
167- d.Range .End .Line , d.Range .End .Character ) << std::endl;
177+ auto luaFile = _parser->GetLuaFile ();
178+
179+ DiagnosisInspection (d.Message , TextRange (
180+ luaFile->GetOffsetFromPosition (d.Range .Start .Line , d.Range .Start .Character ),
181+ luaFile->GetOffsetFromPosition (d.Range .End .Line , d.Range .End .Character )
182+ ), luaFile);
168183 }
184+
169185 return false ;
170186 }
187+ std::cout << format (" Check {} OK" , _inputFile) << std::endl;
171188 return true ;
172189}
190+
191+ void LuaFormat::DiagnosisInspection (std::string_view message, TextRange range, std::shared_ptr<LuaFile> file)
192+ {
193+ std::string_view source = file->GetSource ();
194+ auto startLine = file->GetLine (range.StartOffset );
195+ auto startChar = file->GetColumn (range.StartOffset );
196+ auto endLine = file->GetLine (range.EndOffset );
197+ auto endChar = file->GetColumn (range.EndOffset );
198+ std::cerr << format (" {}({}:{} to {}:{}): {}" , file->GetFilename (), startLine + 1 , startChar, endLine + 1 , endChar,
199+ message) << std::endl;
200+
201+
202+
203+ }
0 commit comments