File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ EMMY_API void FreeReformatResult(char *ptr);
3030EMMY_API void UpdateCodeStyle (const char *workspaceUri, const char *configPath);
3131
3232EMMY_API void RemoveCodeStyle (const char *workspaceUri);
33+
34+ EMMY_API char * CheckCodeStyle (const char *code, const char *uri);
3335}
3436
3537
Original file line number Diff line number Diff line change @@ -38,4 +38,32 @@ EMMY_API void RemoveCodeStyle(const char *workspaceUri) {
3838 CodeFormat &codeFormat = CodeFormat::GetInstance ();
3939 codeFormat.RemoveCodeStyle (workspaceUri);
4040}
41+
42+ EMMY_API char *CheckCodeStyle (const char *code, const char *uri) {
43+ CodeFormat &codeFormat = CodeFormat::GetInstance ();
44+ auto result = codeFormat.Diagnostic (uri, code);
45+ if (result.Type != ResultType::Ok) {
46+ return nullptr ;
47+ }
48+ auto diagnostic_results = std::move (result.Data );
49+ std::string result_str;
50+ auto total_size = 0 ;
51+ for (auto &diagnostic: diagnostic_results) {
52+ total_size += diagnostic.Message .size ();
53+ }
54+ result_str.reserve (total_size * 2 );
55+
56+ for (auto &diagnostic: diagnostic_results) {
57+ result_str.append (std::to_string (diagnostic.Start .Line )).append (" |" );
58+ result_str.append (std::to_string (diagnostic.Start .Col )).append (" |" );
59+ result_str.append (std::to_string (diagnostic.End .Line )).append (" |" );
60+ result_str.append (std::to_string (diagnostic.End .Col )).append (" |" );
61+ result_str.append (diagnostic.Message );
62+ result_str.append (" \n " );
63+ }
64+ auto ptr = new char [result_str.size () + 1 ];
65+ std::copy (result_str.begin (), result_str.end (), ptr);
66+ ptr[result_str.size ()] = ' \0 ' ;
67+ return ptr;
68+ }
4169}
You can’t perform that action at this time.
0 commit comments