mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-19 14:47:49 -04:00
lsp: handle line-endings appropriately (#3318)
This commit is contained in:
parent
c3e4baf697
commit
272cb32a45
|
@ -108,6 +108,16 @@
|
||||||
"description": "Build with Clang with Debug Symbols",
|
"description": "Build with Clang with Debug Symbols",
|
||||||
"inherits": ["base-windows-debug", "base-clang"]
|
"inherits": ["base-windows-debug", "base-clang"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Debug-windows-clang-static",
|
||||||
|
"displayName": "Windows Static Debug (clang)",
|
||||||
|
"description": "Build with Clang as Debug but statically linked",
|
||||||
|
"inherits": ["base-windows-debug", "base-clang"],
|
||||||
|
"cacheVariables": {
|
||||||
|
"STATICALLY_LINK": "true",
|
||||||
|
"ZYDIS_BUILD_SHARED_LIB": "OFF"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "RelWithDebInfo-windows-clang",
|
"name": "RelWithDebInfo-windows-clang",
|
||||||
"displayName": "Windows RelWithDebInfo (clang)",
|
"displayName": "Windows RelWithDebInfo (clang)",
|
||||||
|
|
|
@ -706,4 +706,24 @@ std::string make_screenshot_filepath(const GameVersion game_version, const std::
|
||||||
return file_path;
|
return file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string get_majority_file_line_endings(const std::string& file_contents) {
|
||||||
|
size_t lf_count = 0;
|
||||||
|
size_t crlf_count = 0;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < file_contents.size(); ++i) {
|
||||||
|
if (file_contents[i] == '\n') {
|
||||||
|
if (i > 0 && file_contents[i - 1] == '\r') {
|
||||||
|
crlf_count++;
|
||||||
|
} else {
|
||||||
|
lf_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crlf_count > lf_count) {
|
||||||
|
return "\r\n";
|
||||||
|
}
|
||||||
|
return "\n";
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace file_util
|
} // namespace file_util
|
||||||
|
|
|
@ -69,4 +69,5 @@ std::vector<fs::path> sort_filepaths(const std::vector<fs::path>& paths, const b
|
||||||
/// Will overwrite the destination if it exists
|
/// Will overwrite the destination if it exists
|
||||||
void copy_file(const fs::path& src, const fs::path& dst);
|
void copy_file(const fs::path& src, const fs::path& dst);
|
||||||
std::string make_screenshot_filepath(const GameVersion game_version, const std::string& name = "");
|
std::string make_screenshot_filepath(const GameVersion game_version, const std::string& name = "");
|
||||||
|
std::string get_majority_file_line_endings(const std::string& file_contents);
|
||||||
} // namespace file_util
|
} // namespace file_util
|
||||||
|
|
|
@ -102,6 +102,22 @@ std::vector<std::string> split(const ::std::string& str, char delimiter) {
|
||||||
return google_diff::split_string(str, delimiter);
|
return google_diff::split_string(str, delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> split_string(const std::string& str, const std::string& delimiter) {
|
||||||
|
std::vector<std::string> parsed;
|
||||||
|
std::string::size_type pos = 0;
|
||||||
|
while (true) {
|
||||||
|
const std::string::size_type found = str.find(delimiter, pos);
|
||||||
|
if (found == std::string::npos) {
|
||||||
|
parsed.push_back(str.substr(pos));
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
parsed.push_back(str.substr(pos, found - pos));
|
||||||
|
pos = found + delimiter.length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> regex_get_capture_groups(const std::string& str,
|
std::vector<std::string> regex_get_capture_groups(const std::string& str,
|
||||||
const std::string& regex) {
|
const std::string& regex) {
|
||||||
std::vector<std::string> groups;
|
std::vector<std::string> groups;
|
||||||
|
|
|
@ -18,7 +18,9 @@ int line_count(const std::string& str);
|
||||||
bool valid_regex(const std::string& regex);
|
bool valid_regex(const std::string& regex);
|
||||||
std::string diff(const std::string& lhs, const std::string& rhs);
|
std::string diff(const std::string& lhs, const std::string& rhs);
|
||||||
/// Default splits on \n characters
|
/// Default splits on \n characters
|
||||||
|
/// DEPRECATED - stop using it, limited as it only takes a char
|
||||||
std::vector<std::string> split(const ::std::string& str, char delimiter = '\n');
|
std::vector<std::string> split(const ::std::string& str, char delimiter = '\n');
|
||||||
|
std::vector<std::string> split_string(const std::string& str, const std::string& delimiter = "\n");
|
||||||
std::string join(const std::vector<std::string>& strs, const std::string& join_with);
|
std::string join(const std::vector<std::string>& strs, const std::string& join_with);
|
||||||
std::vector<std::string> regex_get_capture_groups(const std::string& str, const std::string& regex);
|
std::vector<std::string> regex_get_capture_groups(const std::string& str, const std::string& regex);
|
||||||
bool replace(std::string& str, const std::string& from, const std::string& to);
|
bool replace(std::string& str, const std::string& from, const std::string& to);
|
||||||
|
|
|
@ -295,7 +295,8 @@ void Workspace::stop_tracking_file(const LSPSpec::DocumentUri& file_uri) {
|
||||||
|
|
||||||
WorkspaceOGFile::WorkspaceOGFile(const std::string& content, const GameVersion& game_version)
|
WorkspaceOGFile::WorkspaceOGFile(const std::string& content, const GameVersion& game_version)
|
||||||
: m_content(content), m_game_version(game_version) {
|
: m_content(content), m_game_version(game_version) {
|
||||||
m_lines = str_util::split(content);
|
const auto line_ending = file_util::get_majority_file_line_endings(content);
|
||||||
|
m_lines = str_util::split_string(content, line_ending);
|
||||||
lg::info("Added new OG file. {} lines with {} symbols and {} diagnostics", m_lines.size(),
|
lg::info("Added new OG file. {} lines with {} symbols and {} diagnostics", m_lines.size(),
|
||||||
m_symbols.size(), m_diagnostics.size());
|
m_symbols.size(), m_diagnostics.size());
|
||||||
}
|
}
|
||||||
|
@ -322,24 +323,17 @@ std::optional<std::string> WorkspaceOGFile::get_symbol_at_position(
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkspaceIRFile::WorkspaceIRFile(const std::string& content) {
|
WorkspaceIRFile::WorkspaceIRFile(const std::string& content) {
|
||||||
// Get all lines of file
|
const auto line_ending = file_util::get_majority_file_line_endings(content);
|
||||||
std::string::size_type pos = 0;
|
m_lines = str_util::split_string(content, line_ending);
|
||||||
std::string::size_type prev = 0;
|
|
||||||
|
|
||||||
// TODO - i hate this assignment inside a conditional, get rid of it
|
for (int i = 0; i < m_lines.size(); i++) {
|
||||||
while ((pos = content.find("\r\n", prev)) != std::string::npos) {
|
const auto& line = m_lines.at(i);
|
||||||
std::string line = content.substr(prev, pos - prev);
|
if (m_all_types_uri == "") {
|
||||||
m_lines.push_back(line);
|
find_all_types_path(line);
|
||||||
// Run any checks on that line
|
}
|
||||||
find_all_types_path(line);
|
find_function_symbol(i, line);
|
||||||
find_function_symbol(m_lines.size() - 1, line);
|
identify_diagnostics(i, line);
|
||||||
identify_diagnostics(m_lines.size() - 1, line);
|
|
||||||
prev = pos + 1;
|
|
||||||
}
|
}
|
||||||
std::string line = content.substr(prev);
|
|
||||||
m_lines.push_back(line);
|
|
||||||
find_function_symbol(m_lines.size() - 1, line);
|
|
||||||
identify_diagnostics(m_lines.size() - 1, line);
|
|
||||||
|
|
||||||
lg::info("Added new IR file. {} lines with {} symbols and {} diagnostics", m_lines.size(),
|
lg::info("Added new IR file. {} lines with {} symbols and {} diagnostics", m_lines.size(),
|
||||||
m_symbols.size(), m_diagnostics.size());
|
m_symbols.size(), m_diagnostics.size());
|
||||||
|
|
Loading…
Reference in a new issue