mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 11:26:18 -04:00
0e31a9c407
This change adds a few new features: - Decompiler automatically knows the type of `find-parent-method` use in jak 1 and jak2 when used in a method or virtual state handler. - Decompiler inserts a call to `call-parent-method` or `find-parent-state` - Removed most casts related to these functions There are still a few minor issues around this: - There are still some casts needed when using `post` methods, as `post` is just a `function`, and needs a cast to `(function none)` or similar. It didn't seem easy to change the type of `post`, so I'm not going to worry about it for this PR. It only shows up in like 3 places in jak 2. (and 0 in jak 1) - If "call the handler if it's not #f" logic should probably be another macro. Fixes #805
38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <optional>
|
|
|
|
#include "common/formatter/formatter.h"
|
|
|
|
#include "lsp/protocol/common_types.h"
|
|
#include "lsp/protocol/formatting.h"
|
|
#include "lsp/state/data/mips_instructions.h"
|
|
#include "lsp/state/workspace.h"
|
|
|
|
std::optional<json> formatting_handler(Workspace& workspace, int /*id*/, json raw_params) {
|
|
auto params = raw_params.get<LSPSpec::DocumentFormattingParams>();
|
|
const auto file_type = workspace.determine_filetype_from_uri(params.textDocument.m_uri);
|
|
|
|
if (file_type == Workspace::FileType::OpenGOALIR) {
|
|
return nullptr;
|
|
} else if (file_type == Workspace::FileType::OpenGOAL) {
|
|
auto tracked_file = workspace.get_tracked_og_file(params.textDocument.m_uri);
|
|
if (!tracked_file) {
|
|
return nullptr;
|
|
}
|
|
// TODO move away from holding the content directly
|
|
const auto result = formatter::format_code(tracked_file->m_content);
|
|
if (!result) {
|
|
return nullptr;
|
|
}
|
|
json edits = json::array();
|
|
auto format_edit = LSPSpec::TextEdit();
|
|
format_edit.range = {{0, 0}, {(uint32_t)tracked_file->m_lines.size(), 0}};
|
|
format_edit.newText = result.value();
|
|
edits.push_back(format_edit);
|
|
return edits;
|
|
}
|
|
|
|
return nullptr;
|
|
}
|