HackStudio: Use new format functions.

This commit is contained in:
asynts 2020-10-08 13:41:36 +02:00 committed by Andreas Kling
parent 3b601cd4bd
commit 7c4fb2b804
Notes: sideshowbarker 2024-07-19 01:56:57 +09:00
23 changed files with 112 additions and 117 deletions

View file

@ -38,7 +38,7 @@ namespace HackStudio {
void CursorTool::on_mousedown(GUI::MouseEvent& event)
{
#ifdef DEBUG_CURSOR_TOOL
dbg() << "CursorTool::on_mousedown";
dbgln("CursorTool::on_mousedown");
#endif
auto& form_widget = m_editor.form_widget();
auto result = form_widget.hit_test(event.position(), GUI::Widget::ShouldRespectGreediness::No);
@ -77,7 +77,7 @@ void CursorTool::on_mousedown(GUI::MouseEvent& event)
void CursorTool::on_mouseup(GUI::MouseEvent& event)
{
#ifdef DEBUG_CURSOR_TOOL
dbg() << "CursorTool::on_mouseup";
dbgln("CursorTool::on_mouseup");
#endif
if (event.button() == GUI::MouseButton::Left) {
auto& form_widget = m_editor.form_widget();
@ -98,7 +98,7 @@ void CursorTool::on_mouseup(GUI::MouseEvent& event)
void CursorTool::on_mousemove(GUI::MouseEvent& event)
{
#ifdef DEBUG_CURSOR_TOOL
dbg() << "CursorTool::on_mousemove";
dbgln("CursorTool::on_mousemove");
#endif
auto& form_widget = m_editor.form_widget();
@ -137,7 +137,7 @@ void CursorTool::on_mousemove(GUI::MouseEvent& event)
void CursorTool::on_keydown(GUI::KeyEvent& event)
{
#ifdef DEBUG_CURSOR_TOOL
dbg() << "CursorTool::on_keydown";
dbgln("CursorTool::on_keydown");
#endif
auto move_selected_widgets_by = [this](int x, int y) {

View file

@ -59,7 +59,7 @@ Vector<BacktraceModel::FrameInfo> BacktraceModel::create_backtrace(const Debug::
do {
String name = debug_session.debug_info().name_of_containing_function(current_instruction);
if (name.is_null()) {
dbg() << "BacktraceModel: couldn't find containing function for address: " << (void*)current_instruction;
dbgln("BacktraceModel: couldn't find containing function for address: {:p}", current_instruction);
name = "<missing>";
}

View file

@ -164,7 +164,7 @@ void DebugInfoWidget::update_state(const Debug::DebugSession& debug_session, con
}
auto selected_index = m_backtrace_view->model()->index(0);
if (!selected_index.is_valid()) {
dbg() << "Warning: DebugInfoWidget: backtrace selected index is invalid";
dbgln("Warning: DebugInfoWidget: backtrace selected index is invalid");
return;
}
m_backtrace_view->selection().set(selected_index);

View file

@ -78,7 +78,7 @@ void Debugger::on_breakpoint_change(const String& file, size_t line, BreakpointC
auto address = session->debug_info().get_instruction_from_source(position.file_path, position.line_number);
if (!address.has_value()) {
dbg() << "Warning: couldn't get instruction address from source";
dbgln("Warning: couldn't get instruction address from source");
// TODO: Currently, the GUI will indicate that a breakpoint was inserted/removed at this line,
// regardless of whether we actually succeeded to insert it. (For example a breakpoint on a comment, or an include statement).
// We should indicate failure via a return value from this function, and not update the breakpoint GUI if we fail.
@ -97,7 +97,7 @@ void Debugger::on_breakpoint_change(const String& file, size_t line, BreakpointC
Debug::DebugInfo::SourcePosition Debugger::create_source_position(const String& file, size_t line)
{
if (!file.starts_with('/') && !file.starts_with("./"))
return { String::format("./%s", file.characters()), line + 1 };
return { String::formatted("./{}", file), line + 1 };
return { file, line + 1 };
}
@ -113,13 +113,13 @@ void Debugger::start()
ASSERT(!!m_debug_session);
for (const auto& breakpoint : m_breakpoints) {
dbg() << "insertig breakpoint at: " << breakpoint.file_path << ":" << breakpoint.line_number;
dbgln("insertig breakpoint at: {}:{}", breakpoint.file_path, breakpoint.line_number);
auto address = m_debug_session->debug_info().get_instruction_from_source(breakpoint.file_path, breakpoint.line_number);
if (address.has_value()) {
bool success = m_debug_session->insert_breakpoint(reinterpret_cast<void*>(address.value()));
ASSERT(success);
} else {
dbg() << "couldn't insert breakpoint";
dbgln("couldn't insert breakpoint");
}
}
@ -132,7 +132,7 @@ int Debugger::debugger_loop()
m_debug_session->run([this](Debug::DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> optional_regs) {
if (reason == Debug::DebugSession::DebugBreakReason::Exited) {
dbg() << "Program exited";
dbgln("Program exited");
m_on_exit_callback();
return Debug::DebugSession::DebugDecision::Detach;
}
@ -183,7 +183,7 @@ int Debugger::debugger_loop()
// NOTE: Is detaching from the debuggee the best thing to do here?
// We could display a dialog in the UI, remind the user that there is
// a live debugged process, and ask whether they want to terminate/detach.
dbg() << "Debugger exiting";
dbgln("Debugger exiting");
return Debug::DebugSession::DebugDecision::Detach;
}
ASSERT_NOT_REACHED();

View file

@ -40,7 +40,7 @@ DisassemblyModel::DisassemblyModel(const Debug::DebugSession& debug_session, con
{
auto containing_function = debug_session.debug_info().get_containing_function(regs.eip);
if (!containing_function.has_value()) {
dbg() << "Cannot disassemble as the containing function was not found.";
dbgln("Cannot disassemble as the containing function was not found.");
return;
}
@ -110,12 +110,11 @@ GUI::Variant DisassemblyModel::data(const GUI::ModelIndex& index, GUI::ModelRole
if (role == GUI::ModelRole::Display) {
if (index.column() == Column::Address)
return String::format("%#08x", insn.address);
return String::formatted("{:p}", insn.address);
if (index.column() == Column::InstructionBytes) {
StringBuilder builder;
for (auto ch : insn.bytes) {
builder.appendf("%02x ", (u8)ch);
}
for (auto ch : insn.bytes)
builder.appendff("{:02x} ", static_cast<unsigned char>(ch));
return builder.to_string();
}
if (index.column() == Column::Disassembly)

View file

@ -107,7 +107,7 @@ GUI::Variant RegistersModel::data(const GUI::ModelIndex& index, GUI::ModelRole r
if (index.column() == Column::Register)
return reg.name;
if (index.column() == Column::Value)
return String::format("%#08x", reg.value);
return String::formatted("{:08x}", reg.value);
return {};
}
return {};

View file

@ -84,19 +84,19 @@ static String variable_value_as_string(const Debug::DebugInfo::VariableInfo& var
return enumerator->constant_data.as_u32 == enumerator_value;
});
ASSERT(!it.is_end());
return String::format("%s::%s", variable.type_name.characters(), (*it)->name.characters());
return String::formatted("{}::{}", variable.type_name, (*it)->name);
}
if (variable.type_name == "int") {
auto value = Debugger::the().session()->peek((u32*)variable_address);
ASSERT(value.has_value());
return String::format("%d", static_cast<int>(value.value()));
return String::formatted("{}", static_cast<int>(value.value()));
}
if (variable.type_name == "char") {
auto value = Debugger::the().session()->peek((u32*)variable_address);
ASSERT(value.has_value());
return String::format("'%c' (%d)", static_cast<char>(value.value()), static_cast<char>(value.value()));
return String::formatted("'{0:c}' ({0:d})", value.value());
}
if (variable.type_name == "bool") {
@ -105,13 +105,13 @@ static String variable_value_as_string(const Debug::DebugInfo::VariableInfo& var
return (value.value() & 1) ? "true" : "false";
}
return String::format("type: %s @ %08x, ", variable.type_name.characters(), variable_address);
return String::formatted("type: {} @ {:p}, ", variable.type_name, variable_address);
}
static Optional<u32> string_to_variable_value(const StringView& string_value, const Debug::DebugInfo::VariableInfo& variable)
{
if (variable.is_enum_type()) {
auto prefix_string = String::format("%s::", variable.type_name.characters());
auto prefix_string = String::formatted("{}::", variable.type_name);
auto string_to_use = string_value;
if (string_value.starts_with(prefix_string))
string_to_use = string_value.substring_view(prefix_string.length(), string_value.length() - prefix_string.length());
@ -155,8 +155,9 @@ void VariablesModel::set_variable_value(const GUI::ModelIndex& index, const Stri
return;
}
GUI::MessageBox::show(parent_window,
String::format("String value \"%s\" could not be converted to a value of type %s.", string_value.to_string().characters(), variable->type_name.characters()),
GUI::MessageBox::show(
parent_window,
String::formatted("String value \"{}\" could not be converted to a value of type {}.", string_value, variable->type_name),
"Set value failed",
GUI::MessageBox::Type::Error);
}
@ -167,7 +168,7 @@ GUI::Variant VariablesModel::data(const GUI::ModelIndex& index, GUI::ModelRole r
switch (role) {
case GUI::ModelRole::Display: {
auto value_as_string = variable_value_as_string(*variable);
return String::format("%s: %s", variable->name.characters(), value_as_string.characters());
return String::formatted("{}: {}", variable->name, value_as_string);
}
case GUI::ModelRole::Icon:
return m_variable_icon;

View file

@ -142,7 +142,7 @@ static HashMap<String, String>& man_paths()
// FIXME: This should also search man3, possibly other places..
Core::DirIterator it("/usr/share/man/man2", Core::DirIterator::Flags::SkipDots);
while (it.has_next()) {
auto path = String::format("/usr/share/man/man2/%s", it.next_path().characters());
auto path = String::formatted("/usr/share/man/man2/{}", it.next_path());
auto title = LexicalPath(path).title();
paths.set(title, path);
}
@ -156,7 +156,7 @@ void Editor::show_documentation_tooltip_if_available(const String& hovered_token
auto it = man_paths().find(hovered_token);
if (it == man_paths().end()) {
#ifdef EDITOR_DEBUG
dbg() << "no man path for " << hovered_token;
dbgln("no man path for {}", hovered_token);
#endif
m_documentation_tooltip_window->hide();
return;
@ -167,18 +167,18 @@ void Editor::show_documentation_tooltip_if_available(const String& hovered_token
}
#ifdef EDITOR_DEBUG
dbg() << "opening " << it->value;
dbgln("opening {}", it->value);
#endif
auto file = Core::File::construct(it->value);
if (!file->open(Core::File::ReadOnly)) {
dbg() << "failed to open " << it->value << " " << file->error_string();
dbgln("failed to open {}, {}", it->value, file->error_string());
return;
}
auto man_document = Markdown::Document::parse(file->read_all());
if (!man_document) {
dbg() << "failed to parse markdown";
dbgln("failed to parse markdown");
return;
}
@ -238,7 +238,7 @@ void Editor::mousemove_event(GUI::MouseEvent& event)
adjusted_range.end().set_column(min(end_line_length, adjusted_range.end().column() + 1));
auto hovered_span_text = document().text_in_range(adjusted_range);
#ifdef EDITOR_DEBUG
dbg() << "Hovering: " << adjusted_range << " \"" << hovered_span_text << "\"";
dbgln("Hovering: {} \"{}\"", adjusted_range, hovered_span_text);
#endif
if (highlighter->is_navigatable(span.data)) {
@ -305,7 +305,7 @@ void Editor::mousedown_event(GUI::MouseEvent& event)
auto span_text = document().text_in_range(adjusted_range);
auto header_path = span_text.substring(1, span_text.length() - 2);
#ifdef EDITOR_DEBUG
dbg() << "Ctrl+click: " << adjusted_range << " \"" << header_path << "\"";
dbgln("Ctrl+click: {} \"{}\"", adjusted_range, header_path);
#endif
navigate_to_include_if_available(header_path);
return;
@ -392,7 +392,7 @@ static HashMap<String, String>& include_paths()
if (!Core::File::is_directory(path)) {
auto key = path.substring(base.length() + 1, path.length() - base.length() - 1);
#ifdef EDITOR_DEBUG
dbg() << "Adding header \"" << key << "\" in path \"" << path << "\"";
dbgln("Adding header \"{}\" in path \"{}\"", key, path);
#endif
paths.set(key, path);
} else {
@ -416,7 +416,7 @@ void Editor::navigate_to_include_if_available(String path)
auto it = include_paths().find(path);
if (it == include_paths().end()) {
#ifdef EDITOR_DEBUG
dbg() << "no header " << path << " found.";
dbgln("no header {} found.", path);
#endif
return;
}

View file

@ -62,7 +62,7 @@ EditorWrapper::EditorWrapper()
m_editor->set_automatic_indentation_enabled(true);
m_editor->on_cursor_change = [this] {
m_cursor_label->set_text(String::format("Line: %d, Column: %d", m_editor->cursor().line() + 1, m_editor->cursor().column()));
m_cursor_label->set_text(String::formatted("Line: {}, Column: {}", m_editor->cursor().line() + 1, m_editor->cursor().column()));
};
m_editor->on_focus = [this] {

View file

@ -161,9 +161,8 @@ void DiffViewer::set_content(const String& original, const String& diff)
m_hunks = Diff::parse_hunks(diff);
#ifdef DEBUG_DIFF
for (size_t i = 0; i < m_original_lines.size(); ++i) {
dbg() << i << ":" << m_original_lines[i];
}
for (size_t i = 0; i < m_original_lines.size(); ++i)
dbgln("{}:{}", i, m_original_lines[i]);
#endif
}

View file

@ -132,7 +132,7 @@ bool GitRepo::commit(const String& message)
Optional<String> GitRepo::original_file_content(const LexicalPath& file) const
{
return command({ "show", String::format("HEAD:%s", file.string().characters()) });
return command({ "show", String::formatted("HEAD:{}", file) });
}
Optional<String> GitRepo::unstaged_diff(const LexicalPath& file) const

View file

@ -128,7 +128,7 @@ bool GitWidget::initialize_if_needed()
void GitWidget::refresh()
{
if (!initialize_if_needed()) {
dbg() << "GitWidget initialization failed";
dbgln("GitWidget initialization failed");
return;
}
@ -140,7 +140,7 @@ void GitWidget::refresh()
void GitWidget::stage_file(const LexicalPath& file)
{
dbg() << "staging: " << file.string();
dbgln("staging: {}", file);
bool rc = m_git_repo->stage(file);
ASSERT(rc);
refresh();
@ -148,7 +148,7 @@ void GitWidget::stage_file(const LexicalPath& file)
void GitWidget::unstage_file(const LexicalPath& file)
{
dbg() << "unstaging: " << file.string();
dbgln("unstaging: {}", file);
bool rc = m_git_repo->unstage(file);
ASSERT(rc);
refresh();
@ -160,7 +160,7 @@ void GitWidget::commit()
auto res = GUI::InputBox::show(message, window(), "Commit message:", "Commit");
if (res != GUI::InputBox::ExecOK || message.is_empty())
return;
dbg() << "commit message: " << message;
dbgln("commit message: {}", message);
m_git_repo->commit(message);
refresh();
}

View file

@ -214,7 +214,7 @@ void HackStudioWidget::open_file(const String& filename)
}
m_currently_open_file = filename;
window()->set_title(String::format("%s - HackStudio", m_currently_open_file.characters()));
window()->set_title(String::formatted("{} - HackStudio", m_currently_open_file));
m_project_tree_view->update();
current_editor_wrapper().filename_label().set_text(filename);
@ -271,11 +271,11 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_action()
return;
auto file = Core::File::construct(filename);
if (!file->open((Core::IODevice::OpenMode)(Core::IODevice::WriteOnly | Core::IODevice::MustBeNew))) {
GUI::MessageBox::show(window(), String::format("Failed to create '%s'", filename.characters()), "Error", GUI::MessageBox::Type::Error);
GUI::MessageBox::show(window(), String::formatted("Failed to create '{}'", filename), "Error", GUI::MessageBox::Type::Error);
return;
}
if (!m_project->add_file(filename)) {
GUI::MessageBox::show(window(), String::format("Failed to add '%s' to project", filename.characters()), "Error", GUI::MessageBox::Type::Error);
GUI::MessageBox::show(window(), String::formatted("Failed to add '{}' to project", filename), "Error", GUI::MessageBox::Type::Error);
// FIXME: Should we unlink the file here maybe?
return;
}
@ -304,7 +304,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_existing_file_action()
return;
auto& filename = result.value();
if (!m_project->add_file(filename)) {
GUI::MessageBox::show(window(), String::format("Failed to add '%s' to project", filename.characters()), "Error", GUI::MessageBox::Type::Error);
GUI::MessageBox::show(window(), String::formatted("Failed to add '{}' to project", filename), "Error", GUI::MessageBox::Type::Error);
return;
}
m_project_tree_view->toggle_index(m_project_tree_view->model()->index(0, 0));
@ -322,9 +322,9 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
String message;
if (files.size() == 1) {
message = String::format("Really remove %s from the project?", LexicalPath(files[0]).basename().characters());
message = String::formatted("Really remove {} from the project?", LexicalPath(files[0]).basename());
} else {
message = String::format("Really remove %d files from the project?", files.size());
message = String::formatted("Really remove {} files from the project?", files.size());
}
auto result = GUI::MessageBox::show(window(),
@ -338,7 +338,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
for (auto& file : files) {
if (!m_project->remove_file(file)) {
GUI::MessageBox::show(window(),
String::format("Removing file %s from the project failed.", file.characters()),
String::formatted("Removing file {} from the project failed.", file),
"Removal failed",
GUI::MessageBox::Type::Error);
break;
@ -492,11 +492,11 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_debug_action()
{
return GUI::Action::create("Debug", Gfx::Bitmap::load_from_file("/res/icons/16x16/debug-run.png"), [this](auto&) {
if (m_project->type() != ProjectType::Cpp) {
GUI::MessageBox::show(window(), String::format("Cannot debug current project type", get_project_executable_path().characters()), "Error", GUI::MessageBox::Type::Error);
GUI::MessageBox::show(window(), "Cannot debug current project type", "Error", GUI::MessageBox::Type::Error);
return;
}
if (!GUI::FilePicker::file_exists(get_project_executable_path())) {
GUI::MessageBox::show(window(), String::format("Could not find file: %s. (did you build the project?)", get_project_executable_path().characters()), "Error", GUI::MessageBox::Type::Error);
GUI::MessageBox::show(window(), String::formatted("Could not find file: {}. (did you build the project?)", get_project_executable_path()), "Error", GUI::MessageBox::Type::Error);
return;
}
if (Debugger::the().session()) {
@ -517,7 +517,7 @@ void HackStudioWidget::initialize_debugger()
const auto& debug_session = *Debugger::the().session();
auto source_position = debug_session.debug_info().get_source_position(regs.eip);
if (!source_position.has_value()) {
dbg() << "Could not find source position for address: " << (void*)regs.eip;
dbgln("Could not find source position for address: {:p}", regs.eip);
return Debugger::HasControlPassedToUser::No;
}
@ -565,7 +565,7 @@ String HackStudioWidget::get_full_path_of_serenity_source(const String& file)
relative_path_builder.join("/", path_parts);
constexpr char SERENITY_LIBS_PREFIX[] = "/usr/src/serenity";
LexicalPath serenity_sources_base(SERENITY_LIBS_PREFIX);
return String::format("%s/%s", serenity_sources_base.string().characters(), relative_path_builder.to_string().characters());
return String::formatted("{}/{}", serenity_sources_base, relative_path_builder.to_string());
}
NonnullRefPtr<EditorWrapper> HackStudioWidget::get_editor_of_file(const String& file_name)
@ -593,7 +593,7 @@ String HackStudioWidget::get_project_executable_path() const
void HackStudioWidget::build(TerminalWrapper& wrapper)
{
if (m_project->type() == ProjectType::JavaScript && m_currently_open_file.ends_with(".js"))
wrapper.run_command(String::format("js -A %s", m_currently_open_file.characters()));
wrapper.run_command(String::formatted("js -A {}", m_currently_open_file));
else
wrapper.run_command("make");
}
@ -601,7 +601,7 @@ void HackStudioWidget::build(TerminalWrapper& wrapper)
void HackStudioWidget::run(TerminalWrapper& wrapper)
{
if (m_project->type() == ProjectType::JavaScript && m_currently_open_file.ends_with(".js"))
wrapper.run_command(String::format("js %s", m_currently_open_file.characters()));
wrapper.run_command(String::format("js {}", m_currently_open_file));
else
wrapper.run_command("make run");
}
@ -666,12 +666,8 @@ void HackStudioWidget::create_form_editor(GUI::Widget& parent)
GUI::WidgetClassRegistration::for_each([&, this](const GUI::WidgetClassRegistration& reg) {
constexpr size_t gui_namespace_prefix_length = sizeof("GUI::") - 1;
auto icon_path = String::format(
"/res/icons/hackstudio/G%s.png",
reg.class_name().substring(
gui_namespace_prefix_length,
reg.class_name().length() - gui_namespace_prefix_length)
.characters());
auto icon_path = String::formatted("/res/icons/hackstudio/G{}.png",
reg.class_name().substring(gui_namespace_prefix_length, reg.class_name().length() - gui_namespace_prefix_length));
if (!Core::File::exists(icon_path))
return;
@ -898,11 +894,11 @@ HackStudioWidget::~HackStudioWidget()
if (!m_debugger_thread.is_null()) {
Debugger::the().set_requested_debugger_action(Debugger::DebuggerAction::Exit);
void* retval;
dbg() << "Waiting for debugger thread to terminate";
dbgln("Waiting for debugger thread to terminate");
int rc = pthread_join(m_debugger_thread->tid(), &retval);
if (rc < 0) {
perror("pthread_join");
dbg() << "error joining debugger thread";
dbgln("error joining debugger thread");
}
}
}

View file

@ -46,7 +46,7 @@ Vector<AutoCompleteResponse> AutoComplete::get_suggestions(const String& code, G
#ifdef DEBUG_AUTOCOMPLETE
for (auto& suggestion : suggestions) {
dbg() << "suggestion: " << suggestion.completion;
dbgln("suggestion: {}", suggestion.completion);
}
#endif

View file

@ -57,7 +57,7 @@ OwnPtr<Messages::LanguageServer::GreetResponse> ClientConnection::handle(const M
{
m_project_root = LexicalPath(message.project_root());
#ifdef DEBUG_CPP_LANGUAGE_SERVER
dbg() << "project_root: " << m_project_root.string();
dbgln("project_root: {}", m_project_root);
#endif
return make<Messages::LanguageServer::GreetResponse>(client_id());
}
@ -81,16 +81,16 @@ static DefaultDocumentClient s_default_document_client;
void ClientConnection::handle(const Messages::LanguageServer::FileOpened& message)
{
LexicalPath file_path(String::format("%s/%s", m_project_root.string().characters(), message.file_name().characters()));
LexicalPath file_path(String::formatted("{}/{}", m_project_root, message.file_name()));
#ifdef DEBUG_CPP_LANGUAGE_SERVER
dbg() << "FileOpened: " << file_path.string();
dbgln("FileOpened: {}", file_path);
#endif
auto file = Core::File::construct(file_path.string());
if (!file->open(Core::IODevice::ReadOnly)) {
errno = file->error();
perror("open");
dbg() << "Failed to open project file: " << file_path.string();
dbgln("Failed to open project file: {}", file_path);
return;
}
auto content = file->read_all();
@ -106,31 +106,31 @@ void ClientConnection::handle(const Messages::LanguageServer::FileOpened& messag
void ClientConnection::handle(const Messages::LanguageServer::FileEditInsertText& message)
{
#ifdef DEBUG_CPP_LANGUAGE_SERVER
dbg() << "InsertText for file: " << message.file_name();
dbg() << "Text: " << message.text();
dbg() << "[" << message.start_line() << ":" << message.start_column() << "]";
dbgln("InsertText for file: {}", message.file_name());
dbgln("Text: {}", message.text());
dbgln("[{}:{}]", message.start_line(), message.start_column());
#endif
auto document = document_for(message.file_name());
if (!document) {
dbg() << "file " << message.file_name() << " has not been opened";
dbgln("file {} has not been opened", message.file_name());
return;
}
GUI::TextPosition start_position { (size_t)message.start_line(), (size_t)message.start_column() };
document->insert_at(start_position, message.text(), &s_default_document_client);
#ifdef DEBUG_FILE_CONTENT
dbg() << document->text();
dbgln("{}", document->text());
#endif
}
void ClientConnection::handle(const Messages::LanguageServer::FileEditRemoveText& message)
{
#ifdef DEBUG_CPP_LANGUAGE_SERVER
dbg() << "RemoveText for file: " << message.file_name();
dbg() << "[" << message.start_line() << ":" << message.start_column() << " - " << message.end_line() << ":" << message.end_column() << "]";
dbgln("RemoveText for file: {}", message.file_name());
dbgln("[{}:{} - {}:{}]", message.start_line(), message.start_column(), message.end_line(), message.end_column());
#endif
auto document = document_for(message.file_name());
if (!document) {
dbg() << "file " << message.file_name() << " has not been opened";
dbgln("file {} has not been opened", message.file_name());
return;
}
GUI::TextPosition start_position { (size_t)message.start_line(), (size_t)message.start_column() };
@ -143,19 +143,19 @@ void ClientConnection::handle(const Messages::LanguageServer::FileEditRemoveText
document->remove(range);
#ifdef DEBUG_FILE_CONTENT
dbg() << document->text();
dbgln("{}", document->text());
#endif
}
void ClientConnection::handle(const Messages::LanguageServer::AutoCompleteSuggestions& message)
{
#ifdef DEBUG_CPP_LANGUAGE_SERVER
dbg() << "AutoCompleteSuggestions for: " << message.file_name() << " " << message.cursor_line() << ":" << message.cursor_column();
dbgln("AutoCompleteSuggestions for: {} {}:{}", message.file_name(), message.cursor_line(), message.cursor_column());
#endif
auto document = document_for(message.file_name());
if (!document) {
dbg() << "file " << message.file_name() << " has not been opened";
dbgln("file {} has not been opened", message.file_name());
return;
}
@ -176,7 +176,7 @@ void ClientConnection::handle(const Messages::LanguageServer::SetFileContent& me
{
auto document = document_for(message.file_name());
if (!document) {
dbg() << "file " << message.file_name() << " has not been opened";
dbgln("file {} has not been opened", message.file_name());
return;
}
auto content = message.content();

View file

@ -43,16 +43,16 @@ Vector<AutoCompleteResponse> AutoComplete::get_suggestions(const String& code, s
return {};
#ifdef DEBUG_AUTOCOMPLETE
dbg() << "Complete '" << code << "': ";
dbgln("Complete '{}'", code);
ast->dump(1);
dbg() << "At offset " << offset;
dbgln("At offset {}", offset);
#endif
auto result = ast->complete_for_editor(m_shell, offset);
Vector<AutoCompleteResponse> completions;
for (auto& entry : result) {
#ifdef DEBUG_AUTOCOMPLETE
dbg() << "Suggestion: '" << entry.text_string << "' starting at " << entry.input_offset;
dbgln("Suggestion: '{}' starting at {}", entry.text_string, entry.input_offset);
#endif
completions.append({ entry.text_string, entry.input_offset });
}

View file

@ -57,7 +57,7 @@ OwnPtr<Messages::LanguageServer::GreetResponse> ClientConnection::handle(const M
{
m_project_root = LexicalPath(message.project_root());
#ifdef DEBUG_SH_LANGUAGE_SERVER
dbg() << "project_root: " << m_project_root.string();
dbgln("project_root: {}", m_project_root);
#endif
return make<Messages::LanguageServer::GreetResponse>(client_id());
}
@ -81,16 +81,16 @@ static DefaultDocumentClient s_default_document_client;
void ClientConnection::handle(const Messages::LanguageServer::FileOpened& message)
{
LexicalPath file_path(String::format("%s/%s", m_project_root.string().characters(), message.file_name().characters()));
LexicalPath file_path(String::formatted("{}/{}", m_project_root, message.file_name()));
#ifdef DEBUG_SH_LANGUAGE_SERVER
dbg() << "FileOpened: " << file_path.string();
dbgln("FileOpened: {}", file_path);
#endif
auto file = Core::File::construct(file_path.string());
if (!file->open(Core::IODevice::ReadOnly)) {
errno = file->error();
perror("open");
dbg() << "Failed to open project file: " << file_path.string();
dbgln("Failed to open project file: {}", file_path);
return;
}
auto content = file->read_all();
@ -106,31 +106,31 @@ void ClientConnection::handle(const Messages::LanguageServer::FileOpened& messag
void ClientConnection::handle(const Messages::LanguageServer::FileEditInsertText& message)
{
#ifdef DEBUG_SH_LANGUAGE_SERVER
dbg() << "InsertText for file: " << message.file_name();
dbg() << "Text: " << message.text();
dbg() << "[" << message.start_line() << ":" << message.start_column() << "]";
dbgln("InsertText for file: {}", message.file_name());
dbgln("Text: {}", message.text());
dbgln("[{}:{}]", message.start_line(), message.start_column());
#endif
auto document = document_for(message.file_name());
if (!document) {
dbg() << "file " << message.file_name() << " has not been opened";
dbgln("file {} has not been opened", message.file_name());
return;
}
GUI::TextPosition start_position { (size_t)message.start_line(), (size_t)message.start_column() };
document->insert_at(start_position, message.text(), &s_default_document_client);
#ifdef DEBUG_FILE_CONTENT
dbg() << document->text();
dbgln("{}", document->text());
#endif
}
void ClientConnection::handle(const Messages::LanguageServer::FileEditRemoveText& message)
{
#ifdef DEBUG_SH_LANGUAGE_SERVER
dbg() << "RemoveText for file: " << message.file_name();
dbg() << "[" << message.start_line() << ":" << message.start_column() << " - " << message.end_line() << ":" << message.end_column() << "]";
dbgln("RemoveText for file: {}", message.file_name());
dbgln("[{}:{} - {}:{}]", message.start_line(), message.start_column(), message.end_line(), message.end_column());
#endif
auto document = document_for(message.file_name());
if (!document) {
dbg() << "file " << message.file_name() << " has not been opened";
dbgln("file {} has not been opened", message.file_name());
return;
}
GUI::TextPosition start_position { (size_t)message.start_line(), (size_t)message.start_column() };
@ -150,12 +150,12 @@ void ClientConnection::handle(const Messages::LanguageServer::FileEditRemoveText
void ClientConnection::handle(const Messages::LanguageServer::AutoCompleteSuggestions& message)
{
#ifdef DEBUG_SH_LANGUAGE_SERVER
dbg() << "AutoCompleteSuggestions for: " << message.file_name() << " " << message.cursor_line() << ":" << message.cursor_column();
dbgln("AutoCompleteSuggestions for: {} {}:{}", message.file_name(), message.cursor_line(), message.cursor_column());
#endif
auto document = document_for(message.file_name());
if (!document) {
dbg() << "file " << message.file_name() << " has not been opened";
dbgln("file {} has not been opened", message.file_name());
return;
}
@ -185,7 +185,7 @@ void ClientConnection::handle(const Messages::LanguageServer::SetFileContent& me
{
auto document = document_for(message.file_name());
if (!document) {
dbg() << "file " << message.file_name() << " has not been opened";
dbgln("file {} has not been opened", message.file_name());
return;
}
auto content = message.content();

View file

@ -179,9 +179,9 @@ void Locator::update_suggestions()
if (file.name().contains(typed_text))
suggestions.append(file.name());
});
dbg() << "I have " << suggestions.size() << " suggestion(s):";
dbgln("I have {} suggestion(s):", suggestions.size());
for (auto& s : suggestions) {
dbg() << " " << s;
dbgln(" {}", s);
}
bool has_suggestions = !suggestions.is_empty();
@ -194,7 +194,7 @@ void Locator::update_suggestions()
m_suggestion_view->selection().set(m_suggestion_view->model()->index(0));
m_popup_window->move_to(screen_relative_rect().top_left().translated(0, -m_popup_window->height()));
dbg() << "Popup rect: " << m_popup_window->rect();
dbgln("Popup rect: {}", m_popup_window->rect());
m_popup_window->show();
}

View file

@ -82,10 +82,10 @@ void ProcessStateWidget::refresh()
auto& data = active_process_data.value();
m_pid_label->set_text(String::format("%s(%d)", data.name.characters(), pid));
m_pid_label->set_text(String::formatted("{}({})", data.name, pid));
m_state_label->set_text(data.threads.first().state);
m_cpu_label->set_text(String::format("%d", data.threads.first().times_scheduled));
m_memory_label->set_text(String::format("%d", data.amount_resident));
m_cpu_label->set_text(String::formatted("{}", data.threads.first().times_scheduled));
m_memory_label->set_text(String::formatted("{}", data.amount_resident));
}
void ProcessStateWidget::set_tty_fd(int tty_fd)

View file

@ -353,11 +353,11 @@ void Project::rebuild_tree()
#if 0
Function<void(ProjectTreeNode&, int indent)> dump_tree = [&](ProjectTreeNode& node, int indent) {
for (int i = 0; i < indent; ++i)
printf(" ");
new_out(" ");
if (node.name.is_null())
printf("(null)\n");
outln("(null)");
else
printf("%s\n", node.name.characters());
outln("{}", node.name);
for (auto& child : node.children) {
dump_tree(*child, indent + 2);
}

View file

@ -76,11 +76,11 @@ void TerminalWrapper::run_command(const String& command)
ASSERT_NOT_REACHED();
}
if (WIFEXITED(wstatus)) {
m_terminal_widget->inject_string(String::format("\033[%d;1m(Command exited with code %d)\033[0m\n", wstatus == 0 ? 32 : 31, WEXITSTATUS(wstatus)));
m_terminal_widget->inject_string(String::formatted("\033[{};1m(Command exited with code {})\033[0m\n", wstatus == 0 ? 32 : 31, WEXITSTATUS(wstatus)));
} else if (WIFSTOPPED(wstatus)) {
m_terminal_widget->inject_string(String::format("\033[34;1m(Command stopped!)\033[0m\n"));
m_terminal_widget->inject_string("\033[34;1m(Command stopped!)\033[0m\n");
} else if (WIFSIGNALED(wstatus)) {
m_terminal_widget->inject_string(String::format("\033[34;1m(Command signaled with %s!)\033[0m\n", strsignal(WTERMSIG(wstatus))));
m_terminal_widget->inject_string(String::formatted("\033[34;1m(Command signaled with {}!)\033[0m\n", strsignal(WTERMSIG(wstatus))));
}
m_process_state_widget->set_tty_fd(-1);
m_pid = -1;

View file

@ -32,25 +32,25 @@ namespace HackStudio {
void WidgetTool::on_mousedown(GUI::MouseEvent& event)
{
(void)event;
dbg() << "WidgetTool::on_mousedown";
dbgln("WidgetTool::on_mousedown");
}
void WidgetTool::on_mouseup(GUI::MouseEvent& event)
{
(void)event;
dbg() << "WidgetTool::on_mouseup";
dbgln("WidgetTool::on_mouseup");
}
void WidgetTool::on_mousemove(GUI::MouseEvent& event)
{
(void)event;
dbg() << "WidgetTool::on_mousemove";
dbgln("WidgetTool::on_mousemove");
}
void WidgetTool::on_keydown(GUI::KeyEvent& event)
{
(void)event;
dbg() << "WidgetTool::on_keydown";
dbgln("WidgetTool::on_keydown");
}
}

View file

@ -93,7 +93,7 @@ GUI::Variant WidgetTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole
return m_widget_icon;
}
if (role == GUI::ModelRole::Display) {
return String::format("%s (%s)", widget->class_name(), widget->relative_rect().to_string().characters());
return String::formatted("{} ({})", widget->class_name(), widget->relative_rect());
}
return {};
}