MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / ReformatWorkspace

Method ReformatWorkspace

CodeFormat/src/LuaFormat.cpp:137–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135}
136
137bool LuaFormat::ReformatWorkspace(const FormatContext &context) {
138 auto workspace = context.GetWorkspace();
139 FileFinder finder(workspace);
140 finder.AddFindExtension(".lua");
141 finder.AddFindExtension(".lua.txt");
142 finder.AddIgnoreDirectory(".git");
143 finder.AddIgnoreDirectory(".github");
144 finder.AddIgnoreDirectory(".svn");
145 finder.AddIgnoreDirectory(".idea");
146 finder.AddIgnoreDirectory(".vs");
147 finder.AddIgnoreDirectory(".vscode");
148 for (const auto &pattern: context.GetIgnorePattern()) {
149 finder.AddIgnorePatterns(pattern);
150 }
151
152 auto files = finder.FindFiles();
153 for (auto &filePath: files) {
154 auto opText = ReadFile(filePath);
155 std::string relativePath = filePath;
156 if (!workspace.empty()) {
157 relativePath = string_util::GetFileRelativePath(workspace, filePath);
158 }
159 if (opText.has_value()) {
160 auto style = context.GetStyle(relativePath);
161 if (ReformatSingleFile(context, filePath, std::move(opText.value()), style)) {
162 std::cerr << util::format("Reformat {} succeed.", relativePath) << std::endl;
163 } else {
164 std::cerr << util::format("Reformat {} fail.", relativePath) << std::endl;
165 }
166 } else {
167 std::cerr << util::format("Can not read file {}", relativePath) << std::endl;
168 }
169 }
170 return true;
171}

Callers

nothing calls this directly

Calls 10

ReadFileFunction · 0.85
GetWorkspaceMethod · 0.80
AddFindExtensionMethod · 0.80
AddIgnoreDirectoryMethod · 0.80
AddIgnorePatternsMethod · 0.80
FindFilesMethod · 0.80
GetStyleMethod · 0.80
formatFunction · 0.50
emptyMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected