mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 11:26:18 -04:00
c162c66118
This PR does two main things: 1. Work through the main low-hanging fruit issues in the formatter keeping it from feeling mature and usable 2. Iterate and prove that point by formatting all of the Jak 1 code base. **This has removed around 100K lines in total.** - The decompiler will now format it's results for jak 1 to keep things from drifting back to where they were. This is controlled by a new config flag `format_code`. How am I confident this hasn't broken anything?: - I compiled the entire project and stored it's `out/jak1/obj` files separately - I then recompiled the project after formatting and wrote a script that md5's each file and compares it (`compare-compilation-outputs.py` - The results (eventually) were the same: ![Screenshot 2024-05-25 132900](https://github.com/open-goal/jak-project/assets/13153231/015e6f20-8d19-49b7-9951-97fa88ddc6c2) > This proves that the only difference before and after is non-critical whitespace for all code/macros that is actually in use. I'm still aware of improvements that could be made to the formatter, as well as general optimization of it's performance. But in general these are for rare or non-critical situations in my opinion and I'll work through them before doing Jak 2. The vast majority looks great and is working properly at this point. Those known issues are the following if you are curious: ![image](https://github.com/open-goal/jak-project/assets/13153231/0edfaba1-6d36-40f5-ab23-0642209867c4)
48 lines
2.1 KiB
C++
48 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
namespace formatter_rules {
|
|
namespace config {
|
|
struct FormFormattingConfig {
|
|
bool config_set = false;
|
|
bool force_inline = false;
|
|
bool hang_forms =
|
|
true; // TODO - remove this eventually, it's only involved in setting the
|
|
// indentation width, which we can do via the new indentation_width function
|
|
int indentation_width =
|
|
2; // 2 for a flow // TODO - also remove this, prefer storing the first node's width in the
|
|
// metadata on the first pass, that's basically all this does
|
|
std::function<int(FormFormattingConfig, int)> indentation_width_for_index =
|
|
[](FormFormattingConfig config, int /*index*/) { return config.indentation_width; };
|
|
bool combine_first_two_lines =
|
|
false; // NOTE - basically hang, but will probably stick around after hang is gone, may be
|
|
// redundant (inline_until_index!)
|
|
std::function<std::optional<int>(const std::vector<std::string>& /*curr_lines*/)>
|
|
inline_until_index = [](std::vector<std::string> /*curr_lines*/) { return std::nullopt; };
|
|
bool has_constant_pairs = false;
|
|
bool prevent_inlining = false; // TODO - duplicate of below
|
|
std::function<bool(FormFormattingConfig, int num_refs)> should_prevent_inlining =
|
|
[](FormFormattingConfig config, int /*num_refs*/) { return config.prevent_inlining; };
|
|
int parent_mutable_extra_indent = 0;
|
|
std::optional<std::shared_ptr<FormFormattingConfig>> default_index_config;
|
|
std::unordered_map<int, std::shared_ptr<FormFormattingConfig>> index_configs = {};
|
|
// TODO / NOTe - not fully implemented, only doing `parent_mutable_extra_indent` right now
|
|
std::unordered_map<int, std::shared_ptr<FormFormattingConfig>> index_config_override = {};
|
|
|
|
bool determine_column_widths_for_list_elements = false;
|
|
int num_columns_to_compute_widths = 0;
|
|
std::vector<int> list_element_column_widths = {};
|
|
|
|
bool elide_top_level_newline = false;
|
|
};
|
|
|
|
extern const std::unordered_map<std::string, FormFormattingConfig> opengoal_form_config;
|
|
} // namespace config
|
|
} // namespace formatter_rules
|