Browse Source

Formatting cleanup

pipelines/235045657
eidheim 5 years ago
parent
commit
3c726f52da
  1. 3
      src/autocomplete.cpp
  2. 6
      src/directories.cpp
  3. 6
      src/files.hpp
  4. 3
      src/git.cpp
  5. 3
      src/info.cpp
  6. 3
      src/notebook.cpp
  7. 3
      src/selection_dialog.cpp
  8. 12
      src/source.cpp
  9. 9
      src/source_base.cpp
  10. 15
      src/source_clang.cpp
  11. 15
      src/source_diff.cpp
  12. 6
      src/source_generic.cpp
  13. 43
      src/source_language_protocol.cpp
  14. 12
      src/source_spellcheck.cpp
  15. 30
      src/terminal.cpp
  16. 8
      tests/process_test.cpp

3
src/autocomplete.cpp

@ -25,7 +25,8 @@ Autocomplete::Autocomplete(Gsv::View *view, bool &interactive_completion, guint
stop(); stop();
}); });
view->signal_key_release_event().connect([](GdkEventKey *event) { view->signal_key_release_event().connect(
[](GdkEventKey *event) {
if(CompletionDialog::get() && CompletionDialog::get()->is_visible()) { if(CompletionDialog::get() && CompletionDialog::get()->is_visible()) {
if(CompletionDialog::get()->on_key_release(event)) if(CompletionDialog::get()->on_key_release(event))
return true; return true;

6
src/directories.cpp

@ -674,7 +674,8 @@ void Directories::add_or_update_path(const boost::filesystem::path &dir_path, co
if(repository) if(repository)
repository->clear_saved_status(); repository->clear_saved_status();
connection->disconnect(); connection->disconnect();
*connection = Glib::signal_timeout().connect([path_and_row, this]() { *connection = Glib::signal_timeout().connect(
[path_and_row, this]() {
if(directories.find(path_and_row->first.string()) != directories.end()) if(directories.find(path_and_row->first.string()) != directories.end())
add_or_update_path(path_and_row->first, path_and_row->second, true); add_or_update_path(path_and_row->first, path_and_row->second, true);
return false; return false;
@ -695,7 +696,8 @@ void Directories::add_or_update_path(const boost::filesystem::path &dir_path, co
Gio::FileMonitorEvent monitor_event) { Gio::FileMonitorEvent monitor_event) {
if(monitor_event != Gio::FileMonitorEvent::FILE_MONITOR_EVENT_CHANGES_DONE_HINT) { if(monitor_event != Gio::FileMonitorEvent::FILE_MONITOR_EVENT_CHANGES_DONE_HINT) {
connection->disconnect(); connection->disconnect();
*connection = Glib::signal_timeout().connect([this, path_and_row] { *connection = Glib::signal_timeout().connect(
[this, path_and_row] {
if(directories.find(path_and_row->first.string()) != directories.end()) if(directories.find(path_and_row->first.string()) != directories.end())
colorize_path(path_and_row->first, false); colorize_path(path_and_row->first, false);
return false; return false;

6
src/files.hpp

@ -4,8 +4,10 @@
/// If you add or remove nodes from the default_config_file, increase the juci /// If you add or remove nodes from the default_config_file, increase the juci
/// version number (JUCI_VERSION) in ../CMakeLists.txt to automatically apply /// version number (JUCI_VERSION) in ../CMakeLists.txt to automatically apply
/// the changes to user's ~/.juci/config/config.json files /// the changes to user's ~/.juci/config/config.json files
const std::string default_config_file = R"RAW({ const std::string default_config_file =
"version": ")RAW" + std::string(JUCI_VERSION) + R"RAW({
"version": ")RAW" +
std::string(JUCI_VERSION) +
R"RAW(", R"RAW(",
"gtk_theme": { "gtk_theme": {
"name_comment": "Use \"\" for default theme, At least these two exist on all systems: Adwaita, Raleigh", "name_comment": "Use \"\" for default theme, At least these two exist on all systems: Adwaita, Raleigh",

3
src/git.cpp

@ -116,7 +116,8 @@ Git::Repository::Repository(const boost::filesystem::path &path) {
auto git_directory = Gio::File::create_for_path(get_path().string()); auto git_directory = Gio::File::create_for_path(get_path().string());
monitor = git_directory->monitor_directory(Gio::FileMonitorFlags::FILE_MONITOR_WATCH_MOVES); monitor = git_directory->monitor_directory(Gio::FileMonitorFlags::FILE_MONITOR_WATCH_MOVES);
monitor_changed_connection = monitor->signal_changed().connect([this](const Glib::RefPtr<Gio::File> &file, monitor_changed_connection = monitor->signal_changed().connect(
[this](const Glib::RefPtr<Gio::File> &file,
const Glib::RefPtr<Gio::File> &, const Glib::RefPtr<Gio::File> &,
Gio::FileMonitorEvent monitor_event) { Gio::FileMonitorEvent monitor_event) {
if(monitor_event != Gio::FileMonitorEvent::FILE_MONITOR_EVENT_CHANGES_DONE_HINT) { if(monitor_event != Gio::FileMonitorEvent::FILE_MONITOR_EVENT_CHANGES_DONE_HINT) {

3
src/info.cpp

@ -26,7 +26,8 @@ void Info::print(const std::string &text) {
//Timeout based on https://en.wikipedia.org/wiki/Words_per_minute //Timeout based on https://en.wikipedia.org/wiki/Words_per_minute
//(average_words_per_minute*average_letters_per_word)/60 => (228*4.5)/60 = 17.1 //(average_words_per_minute*average_letters_per_word)/60 => (228*4.5)/60 = 17.1
double timeout = 1000.0 * std::max(3.0, 1.0 + text.size() / 17.1); double timeout = 1000.0 * std::max(3.0, 1.0 + text.size() / 17.1);
timeout_connection = Glib::signal_timeout().connect([this]() { timeout_connection = Glib::signal_timeout().connect(
[this]() {
hide(); hide();
return false; return false;
}, },

3
src/notebook.cpp

@ -618,7 +618,8 @@ void Notebook::toggle_split() {
show_all(); show_all();
//Make sure the position is correct //Make sure the position is correct
//TODO: report bug to gtk if it is not fixed in gtk3.22 //TODO: report bug to gtk if it is not fixed in gtk3.22
Glib::signal_timeout().connect([this] { Glib::signal_timeout().connect(
[this] {
set_position(get_width() / 2); set_position(get_width() / 2);
return false; return false;
}, },

3
src/selection_dialog.cpp

@ -44,7 +44,8 @@ SelectionDialogBase::SelectionDialogBase(Gtk::TextView *text_view, const boost::
window.set_type_hint(Gdk::WindowTypeHint::WINDOW_TYPE_HINT_COMBO); window.set_type_hint(Gdk::WindowTypeHint::WINDOW_TYPE_HINT_COMBO);
search_entry.signal_changed().connect([this] { search_entry.signal_changed().connect(
[this] {
if(on_search_entry_changed) if(on_search_entry_changed)
on_search_entry_changed(search_entry.get_text()); on_search_entry_changed(search_entry.get_text());
}, },

12
src/source.cpp

@ -588,7 +588,8 @@ void Source::View::setup_signals() {
if(on_motion_last_x != event->x || on_motion_last_y != event->y) { if(on_motion_last_x != event->x || on_motion_last_y != event->y) {
delayed_tooltips_connection.disconnect(); delayed_tooltips_connection.disconnect();
if((event->state & GDK_BUTTON1_MASK) == 0) { if((event->state & GDK_BUTTON1_MASK) == 0) {
delayed_tooltips_connection = Glib::signal_timeout().connect([this, x = event->x, y = event->y]() { delayed_tooltips_connection = Glib::signal_timeout().connect(
[this, x = event->x, y = event->y]() {
type_tooltips.hide(); type_tooltips.hide();
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
Tooltips::init(); Tooltips::init();
@ -608,7 +609,8 @@ void Source::View::setup_signals() {
} }
if((event->state & primary_modifier_mask) && !(event->state & GDK_SHIFT_MASK) && !(event->state & GDK_BUTTON1_MASK)) { if((event->state & primary_modifier_mask) && !(event->state & GDK_SHIFT_MASK) && !(event->state & GDK_BUTTON1_MASK)) {
delayed_tag_clickable_connection.disconnect(); delayed_tag_clickable_connection.disconnect();
delayed_tag_clickable_connection = Glib::signal_timeout().connect([this, x = event->x, y = event->y]() { delayed_tag_clickable_connection = Glib::signal_timeout().connect(
[this, x = event->x, y = event->y]() {
int buffer_x, buffer_y; int buffer_x, buffer_y;
window_to_buffer_coords(Gtk::TextWindowType::TEXT_WINDOW_TEXT, x, y, buffer_x, buffer_y); window_to_buffer_coords(Gtk::TextWindowType::TEXT_WINDOW_TEXT, x, y, buffer_x, buffer_y);
Gtk::TextIter iter; Gtk::TextIter iter;
@ -646,7 +648,8 @@ void Source::View::setup_signals() {
hide_tooltips(); hide_tooltips();
delayed_tooltips_connection.disconnect(); delayed_tooltips_connection.disconnect();
delayed_tooltips_connection = Glib::signal_timeout().connect([this]() { delayed_tooltips_connection = Glib::signal_timeout().connect(
[this]() {
Tooltips::init(); Tooltips::init();
Gdk::Rectangle rectangle; Gdk::Rectangle rectangle;
get_iter_location(get_buffer()->get_insert()->get_iter(), rectangle); get_iter_location(get_buffer()->get_insert()->get_iter(), rectangle);
@ -664,7 +667,8 @@ void Source::View::setup_signals() {
500); 500);
delayed_tag_similar_symbols_connection.disconnect(); delayed_tag_similar_symbols_connection.disconnect();
delayed_tag_similar_symbols_connection = Glib::signal_timeout().connect([this] { delayed_tag_similar_symbols_connection = Glib::signal_timeout().connect(
[this] {
apply_similar_symbol_tag(); apply_similar_symbol_tag();
similar_symbol_tag_applied = true; similar_symbol_tag_applied = true;
return false; return false;

9
src/source_base.cpp

@ -343,7 +343,8 @@ void Source::BaseView::monitor_file() {
public: public:
static void f(BaseView *view, boost::optional<std::time_t> previous_last_write_time = {}, bool check_called = false) { static void f(BaseView *view, boost::optional<std::time_t> previous_last_write_time = {}, bool check_called = false) {
view->delayed_monitor_changed_connection.disconnect(); view->delayed_monitor_changed_connection.disconnect();
view->delayed_monitor_changed_connection = Glib::signal_timeout().connect([view, previous_last_write_time, check_called]() { view->delayed_monitor_changed_connection = Glib::signal_timeout().connect(
[view, previous_last_write_time, check_called]() {
boost::system::error_code ec; boost::system::error_code ec;
auto last_write_time = boost::filesystem::last_write_time(view->file_path, ec); auto last_write_time = boost::filesystem::last_write_time(view->file_path, ec);
if(!ec && last_write_time != view->last_write_time) { if(!ec && last_write_time != view->last_write_time) {
@ -374,7 +375,8 @@ void Source::BaseView::monitor_file() {
Gio::FileMonitorEvent monitor_event) { Gio::FileMonitorEvent monitor_event) {
if(monitor_event != Gio::FileMonitorEvent::FILE_MONITOR_EVENT_CHANGES_DONE_HINT) { if(monitor_event != Gio::FileMonitorEvent::FILE_MONITOR_EVENT_CHANGES_DONE_HINT) {
delayed_monitor_changed_connection.disconnect(); delayed_monitor_changed_connection.disconnect();
delayed_monitor_changed_connection = Glib::signal_timeout().connect([this]() { delayed_monitor_changed_connection = Glib::signal_timeout().connect(
[this]() {
check_last_write_time(); check_last_write_time();
return false; return false;
}, },
@ -1322,7 +1324,8 @@ void Source::BaseView::setup_extra_cursor_signals() {
auto erase_backward_length = std::make_shared<int>(0); auto erase_backward_length = std::make_shared<int>(0);
auto erase_forward_length = std::make_shared<int>(0); auto erase_forward_length = std::make_shared<int>(0);
auto erase_selection = std::make_shared<bool>(false); auto erase_selection = std::make_shared<bool>(false);
get_buffer()->signal_erase().connect([this, erase_backward_length, erase_forward_length, erase_selection](const Gtk::TextIter &iter_start, const Gtk::TextIter &iter_end) { get_buffer()->signal_erase().connect(
[this, erase_backward_length, erase_forward_length, erase_selection](const Gtk::TextIter &iter_start, const Gtk::TextIter &iter_end) {
if(enable_multiple_cursors && (!extra_cursors.empty())) { if(enable_multiple_cursors && (!extra_cursors.empty())) {
auto insert_offset = get_buffer()->get_insert()->get_iter().get_offset(); auto insert_offset = get_buffer()->get_insert()->get_iter().get_offset();
*erase_backward_length = insert_offset - iter_start.get_offset(); *erase_backward_length = insert_offset - iter_start.get_offset();

15
src/source_clang.cpp

@ -643,7 +643,8 @@ void Source::ClangViewParse::show_type_tooltips(const Gdk::Rectangle &rectangle)
}; };
VisitorData visitor_data{cursor.get_source_range().get_offsets(), cursor.get_spelling(), {}}; VisitorData visitor_data{cursor.get_source_range().get_offsets(), cursor.get_spelling(), {}};
auto start_cursor = cursor; auto start_cursor = cursor;
for(auto parent = cursor.get_semantic_parent(); parent.get_kind() != clangmm::Cursor::Kind::TranslationUnit && for(auto parent = cursor.get_semantic_parent();
parent.get_kind() != clangmm::Cursor::Kind::TranslationUnit &&
parent.get_kind() != clangmm::Cursor::Kind::ClassDecl; parent.get_kind() != clangmm::Cursor::Kind::ClassDecl;
parent = parent.get_semantic_parent()) parent = parent.get_semantic_parent())
start_cursor = parent; start_cursor = parent;
@ -801,7 +802,8 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
}; };
// Activate argument completions // Activate argument completions
get_buffer()->signal_changed().connect([this] { get_buffer()->signal_changed().connect(
[this] {
if(!interactive_completion) if(!interactive_completion)
return; return;
if(CompletionDialog::get() && CompletionDialog::get()->is_visible()) if(CompletionDialog::get() && CompletionDialog::get()->is_visible())
@ -812,7 +814,8 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
autocomplete.stop(); autocomplete.stop();
show_parameters = false; show_parameters = false;
delayed_show_arguments_connection.disconnect(); delayed_show_arguments_connection.disconnect();
delayed_show_arguments_connection = Glib::signal_timeout().connect([this]() { delayed_show_arguments_connection = Glib::signal_timeout().connect(
[this]() {
if(get_buffer()->get_has_selection()) if(get_buffer()->get_has_selection())
return false; return false;
if(CompletionDialog::get() && CompletionDialog::get()->is_visible()) if(CompletionDialog::get() && CompletionDialog::get()->is_visible())
@ -830,7 +833,8 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
false); false);
// Remove argument completions // Remove argument completions
signal_key_press_event().connect([this](GdkEventKey *event) { signal_key_press_event().connect(
[this](GdkEventKey *event) {
if(show_parameters && CompletionDialog::get() && CompletionDialog::get()->is_visible() && if(show_parameters && CompletionDialog::get() && CompletionDialog::get()->is_visible() &&
event->keyval != GDK_KEY_Down && event->keyval != GDK_KEY_Up && event->keyval != GDK_KEY_Down && event->keyval != GDK_KEY_Up &&
event->keyval != GDK_KEY_Return && event->keyval != GDK_KEY_KP_Enter && event->keyval != GDK_KEY_Return && event->keyval != GDK_KEY_KP_Enter &&
@ -2060,7 +2064,8 @@ void Source::ClangView::full_reparse() {
return; return;
if(full_reparse_running) { if(full_reparse_running) {
delayed_full_reparse_connection = Glib::signal_timeout().connect([this] { delayed_full_reparse_connection = Glib::signal_timeout().connect(
[this] {
full_reparse(); full_reparse();
return false; return false;
}, },

15
src/source_diff.cpp

@ -118,7 +118,8 @@ void Source::DiffView::configure() {
parse_stop = false; parse_stop = false;
monitor_changed = false; monitor_changed = false;
buffer_insert_connection = get_buffer()->signal_insert().connect([this](const Gtk::TextIter &iter, const Glib::ustring &text, int) { buffer_insert_connection = get_buffer()->signal_insert().connect(
[this](const Gtk::TextIter &iter, const Glib::ustring &text, int) {
//Do not perform git diff if no newline is added and line is already marked as added //Do not perform git diff if no newline is added and line is already marked as added
if(!iter.starts_line() && iter.has_tag(renderer->tag_added)) { if(!iter.starts_line() && iter.has_tag(renderer->tag_added)) {
bool newline = false; bool newline = false;
@ -141,7 +142,8 @@ void Source::DiffView::configure() {
} }
parse_state = ParseState::idle; parse_state = ParseState::idle;
delayed_buffer_changed_connection.disconnect(); delayed_buffer_changed_connection.disconnect();
delayed_buffer_changed_connection = Glib::signal_timeout().connect([this]() { delayed_buffer_changed_connection = Glib::signal_timeout().connect(
[this]() {
parse_state = ParseState::starting; parse_state = ParseState::starting;
return false; return false;
}, },
@ -149,14 +151,16 @@ void Source::DiffView::configure() {
}, },
false); false);
buffer_erase_connection = get_buffer()->signal_erase().connect([this](const Gtk::TextIter &start_iter, const Gtk::TextIter &end_iter) { buffer_erase_connection = get_buffer()->signal_erase().connect(
[this](const Gtk::TextIter &start_iter, const Gtk::TextIter &end_iter) {
//Do not perform git diff if start_iter and end_iter is at the same line in addition to the line is tagged added //Do not perform git diff if start_iter and end_iter is at the same line in addition to the line is tagged added
if(start_iter.get_line() == end_iter.get_line() && start_iter.has_tag(renderer->tag_added)) if(start_iter.get_line() == end_iter.get_line() && start_iter.has_tag(renderer->tag_added))
return; return;
parse_state = ParseState::idle; parse_state = ParseState::idle;
delayed_buffer_changed_connection.disconnect(); delayed_buffer_changed_connection.disconnect();
delayed_buffer_changed_connection = Glib::signal_timeout().connect([this]() { delayed_buffer_changed_connection = Glib::signal_timeout().connect(
[this]() {
parse_state = ParseState::starting; parse_state = ParseState::starting;
return false; return false;
}, },
@ -169,7 +173,8 @@ void Source::DiffView::configure() {
Gio::FileMonitorEvent monitor_event) { Gio::FileMonitorEvent monitor_event) {
if(monitor_event != Gio::FileMonitorEvent::FILE_MONITOR_EVENT_CHANGES_DONE_HINT) { if(monitor_event != Gio::FileMonitorEvent::FILE_MONITOR_EVENT_CHANGES_DONE_HINT) {
delayed_monitor_changed_connection.disconnect(); delayed_monitor_changed_connection.disconnect();
delayed_monitor_changed_connection = Glib::signal_timeout().connect([this]() { delayed_monitor_changed_connection = Glib::signal_timeout().connect(
[this]() {
monitor_changed = true; monitor_changed = true;
parse_state = ParseState::starting; parse_state = ParseState::starting;
LockGuard lock(parse_mutex); LockGuard lock(parse_mutex);

6
src/source_generic.cpp

@ -112,7 +112,8 @@ void Source::GenericView::setup_buffer_words() {
} }
// Remove changed word at insert // Remove changed word at insert
get_buffer()->signal_insert().connect([this](const Gtk::TextIter &iter_, const Glib::ustring &text, int bytes) { get_buffer()->signal_insert().connect(
[this](const Gtk::TextIter &iter_, const Glib::ustring &text, int bytes) {
auto iter = iter_; auto iter = iter_;
if(!is_token_char(*iter)) if(!is_token_char(*iter))
iter.backward_char(); iter.backward_char();
@ -152,7 +153,8 @@ void Source::GenericView::setup_buffer_words() {
}); });
// Remove words within text that was removed // Remove words within text that was removed
get_buffer()->signal_erase().connect([this](const Gtk::TextIter &start_, const Gtk::TextIter &end_) { get_buffer()->signal_erase().connect(
[this](const Gtk::TextIter &start_, const Gtk::TextIter &end_) {
auto start = start_; auto start = start_;
auto end = end_; auto end = end_;
if(!is_token_char(*start)) if(!is_token_char(*start))

43
src/source_language_protocol.cpp

@ -51,9 +51,15 @@ LanguageProtocol::TextEdit::TextEdit(const boost::property_tree::ptree &pt, std:
LanguageProtocol::Client::Client(boost::filesystem::path root_path_, std::string language_id_) : root_path(std::move(root_path_)), language_id(std::move(language_id_)) { LanguageProtocol::Client::Client(boost::filesystem::path root_path_, std::string language_id_) : root_path(std::move(root_path_)), language_id(std::move(language_id_)) {
process = std::make_unique<TinyProcessLib::Process>( process = std::make_unique<TinyProcessLib::Process>(
filesystem::escape_argument(language_id + "-language-server"), root_path.string(), [this](const char *bytes, size_t n) { filesystem::escape_argument(language_id + "-language-server"), root_path.string(),
[this](const char *bytes, size_t n) {
server_message_stream.write(bytes, n); server_message_stream.write(bytes, n);
parse_server_message(); }, [](const char *bytes, size_t n) { std::cerr.write(bytes, n); }, true, TinyProcessLib::Config{1048576}); parse_server_message();
},
[](const char *bytes, size_t n) {
std::cerr.write(bytes, n);
},
true, TinyProcessLib::Config{1048576});
} }
std::shared_ptr<LanguageProtocol::Client> LanguageProtocol::Client::get(const boost::filesystem::path &file_path, const std::string &language_id) { std::shared_ptr<LanguageProtocol::Client> LanguageProtocol::Client::get(const boost::filesystem::path &file_path, const std::string &language_id) {
@ -126,7 +132,8 @@ LanguageProtocol::Capabilities LanguageProtocol::Client::initialize(Source::Lang
LockGuard lock(read_write_mutex); LockGuard lock(read_write_mutex);
process_id = process->get_id(); process_id = process->get_id();
} }
write_request(nullptr, "initialize", "\"processId\":" + std::to_string(process_id) + R"(,"rootUri":")" + filesystem::get_uri_from_path(root_path) + R"(","capabilities": { write_request(
nullptr, "initialize", "\"processId\":" + std::to_string(process_id) + R"(,"rootUri":")" + filesystem::get_uri_from_path(root_path) + R"(","capabilities": {
"workspace": { "symbol": { "dynamicRegistration": true } }, "workspace": { "symbol": { "dynamicRegistration": true } },
"textDocument": { "textDocument": {
"synchronization": { "dynamicRegistration": true, "didSave": true }, "synchronization": { "dynamicRegistration": true, "didSave": true },
@ -1024,7 +1031,11 @@ void Source::LanguageProtocolView::update_diagnostics_async(std::vector<Language
for(auto &quickfix_diagnostic : quickfix_diagnostics) { for(auto &quickfix_diagnostic : quickfix_diagnostics) {
if(diagnostic.message == quickfix_diagnostic.message && diagnostic.range == quickfix_diagnostic.range) { if(diagnostic.message == quickfix_diagnostic.message && diagnostic.range == quickfix_diagnostic.range) {
auto pair = diagnostic.quickfixes.emplace(title, std::vector<Source::FixIt>{}); auto pair = diagnostic.quickfixes.emplace(title, std::vector<Source::FixIt>{});
pair.first->second.emplace_back(edit.new_text, filesystem::get_path_from_uri(file_it->first).string(), std::make_pair<Offset, Offset>(Offset(edit.range.start.line, edit.range.start.character), Offset(edit.range.end.line, edit.range.end.character))); pair.first->second.emplace_back(
edit.new_text,
filesystem::get_path_from_uri(file_it->first).string(),
std::make_pair<Offset, Offset>(Offset(edit.range.start.line, edit.range.start.character),
Offset(edit.range.end.line, edit.range.end.character)));
break; break;
} }
} }
@ -1034,7 +1045,11 @@ void Source::LanguageProtocolView::update_diagnostics_async(std::vector<Language
for(auto &diagnostic : diagnostics) { for(auto &diagnostic : diagnostics) {
if(edit.range.start.line == diagnostic.range.start.line) { if(edit.range.start.line == diagnostic.range.start.line) {
auto pair = diagnostic.quickfixes.emplace(title, std::vector<Source::FixIt>{}); auto pair = diagnostic.quickfixes.emplace(title, std::vector<Source::FixIt>{});
pair.first->second.emplace_back(edit.new_text, filesystem::get_path_from_uri(file_it->first).string(), std::make_pair<Offset, Offset>(Offset(edit.range.start.line, edit.range.start.character), Offset(edit.range.end.line, edit.range.end.character))); pair.first->second.emplace_back(
edit.new_text,
filesystem::get_path_from_uri(file_it->first).string(),
std::make_pair<Offset, Offset>(Offset(edit.range.start.line, edit.range.start.character),
Offset(edit.range.end.line, edit.range.end.character)));
break; break;
} }
} }
@ -1400,14 +1415,16 @@ Source::Offset Source::LanguageProtocolView::get_declaration(const Gtk::TextIter
void Source::LanguageProtocolView::setup_signals() { void Source::LanguageProtocolView::setup_signals() {
if(capabilities.text_document_sync == LanguageProtocol::Capabilities::TextDocumentSync::incremental) { if(capabilities.text_document_sync == LanguageProtocol::Capabilities::TextDocumentSync::incremental) {
get_buffer()->signal_insert().connect([this](const Gtk::TextIter &start, const Glib::ustring &text_, int bytes) { get_buffer()->signal_insert().connect(
[this](const Gtk::TextIter &start, const Glib::ustring &text_, int bytes) {
std::string text = text_; std::string text = text_;
escape_text(text); escape_text(text);
client->write_notification("textDocument/didChange", R"("textDocument":{"uri":")" + this->uri + R"(","version":)" + std::to_string(document_version++) + "},\"contentChanges\":[" + R"({"range":{"start":{"line": )" + std::to_string(start.get_line()) + ",\"character\":" + std::to_string(start.get_line_offset()) + R"(},"end":{"line":)" + std::to_string(start.get_line()) + ",\"character\":" + std::to_string(start.get_line_offset()) + R"(}},"text":")" + text + "\"}" + "]"); client->write_notification("textDocument/didChange", R"("textDocument":{"uri":")" + this->uri + R"(","version":)" + std::to_string(document_version++) + "},\"contentChanges\":[" + R"({"range":{"start":{"line": )" + std::to_string(start.get_line()) + ",\"character\":" + std::to_string(start.get_line_offset()) + R"(},"end":{"line":)" + std::to_string(start.get_line()) + ",\"character\":" + std::to_string(start.get_line_offset()) + R"(}},"text":")" + text + "\"}" + "]");
}, },
false); false);
get_buffer()->signal_erase().connect([this](const Gtk::TextIter &start, const Gtk::TextIter &end) { get_buffer()->signal_erase().connect(
[this](const Gtk::TextIter &start, const Gtk::TextIter &end) {
client->write_notification("textDocument/didChange", R"("textDocument":{"uri":")" + this->uri + R"(","version":)" + std::to_string(document_version++) + "},\"contentChanges\":[" + R"({"range":{"start":{"line": )" + std::to_string(start.get_line()) + ",\"character\":" + std::to_string(start.get_line_offset()) + R"(},"end":{"line":)" + std::to_string(end.get_line()) + ",\"character\":" + std::to_string(end.get_line_offset()) + R"(}},"text":""})" + "]"); client->write_notification("textDocument/didChange", R"("textDocument":{"uri":")" + this->uri + R"(","version":)" + std::to_string(document_version++) + "},\"contentChanges\":[" + R"({"range":{"start":{"line": )" + std::to_string(start.get_line()) + ",\"character\":" + std::to_string(start.get_line_offset()) + R"(},"end":{"line":)" + std::to_string(end.get_line()) + ",\"character\":" + std::to_string(end.get_line_offset()) + R"(}},"text":""})" + "]");
}, },
false); false);
@ -1439,7 +1456,8 @@ void Source::LanguageProtocolView::setup_autocomplete() {
if(capabilities.signature_help) { if(capabilities.signature_help) {
// Activate argument completions // Activate argument completions
get_buffer()->signal_changed().connect([this] { get_buffer()->signal_changed().connect(
[this] {
if(!interactive_completion) if(!interactive_completion)
return; return;
if(CompletionDialog::get() && CompletionDialog::get()->is_visible()) if(CompletionDialog::get() && CompletionDialog::get()->is_visible())
@ -1450,7 +1468,8 @@ void Source::LanguageProtocolView::setup_autocomplete() {
autocomplete->stop(); autocomplete->stop();
autocomplete_show_arguments = false; autocomplete_show_arguments = false;
autocomplete_delayed_show_arguments_connection.disconnect(); autocomplete_delayed_show_arguments_connection.disconnect();
autocomplete_delayed_show_arguments_connection = Glib::signal_timeout().connect([this]() { autocomplete_delayed_show_arguments_connection = Glib::signal_timeout().connect(
[this]() {
if(get_buffer()->get_has_selection()) if(get_buffer()->get_has_selection())
return false; return false;
if(CompletionDialog::get() && CompletionDialog::get()->is_visible()) if(CompletionDialog::get() && CompletionDialog::get()->is_visible())
@ -1468,7 +1487,8 @@ void Source::LanguageProtocolView::setup_autocomplete() {
false); false);
// Remove argument completions // Remove argument completions
signal_key_press_event().connect([this](GdkEventKey *event) { signal_key_press_event().connect(
[this](GdkEventKey *event) {
if(autocomplete_show_arguments && CompletionDialog::get() && CompletionDialog::get()->is_visible() && if(autocomplete_show_arguments && CompletionDialog::get() && CompletionDialog::get()->is_visible() &&
event->keyval != GDK_KEY_Down && event->keyval != GDK_KEY_Up && event->keyval != GDK_KEY_Down && event->keyval != GDK_KEY_Up &&
event->keyval != GDK_KEY_Return && event->keyval != GDK_KEY_KP_Enter && event->keyval != GDK_KEY_Return && event->keyval != GDK_KEY_KP_Enter &&
@ -1826,7 +1846,8 @@ void Source::LanguageProtocolView::update_type_coverage() {
if(update_type_coverage_retries > 0) { // Retry typeCoverage request, since these requests can fail while waiting for language server to start if(update_type_coverage_retries > 0) { // Retry typeCoverage request, since these requests can fail while waiting for language server to start
dispatcher.post([this] { dispatcher.post([this] {
update_type_coverage_connection.disconnect(); update_type_coverage_connection.disconnect();
update_type_coverage_connection = Glib::signal_timeout().connect([this]() { update_type_coverage_connection = Glib::signal_timeout().connect(
[this]() {
--update_type_coverage_retries; --update_type_coverage_retries;
update_type_coverage(); update_type_coverage();
return false; return false;

12
src/source_spellcheck.cpp

@ -13,7 +13,8 @@ Source::SpellCheckView::SpellCheckView(const boost::filesystem::path &file_path,
spellcheck_error_tag = get_buffer()->create_tag("spellcheck_error"); spellcheck_error_tag = get_buffer()->create_tag("spellcheck_error");
spellcheck_error_tag->property_underline() = Pango::Underline::UNDERLINE_ERROR; spellcheck_error_tag->property_underline() = Pango::Underline::UNDERLINE_ERROR;
signal_key_press_event().connect([](GdkEventKey *event) { signal_key_press_event().connect(
[](GdkEventKey *event) {
if(SelectionDialog::get() && SelectionDialog::get()->is_visible()) { if(SelectionDialog::get() && SelectionDialog::get()->is_visible()) {
if(SelectionDialog::get()->on_key_press(event)) if(SelectionDialog::get()->on_key_press(event))
return true; return true;
@ -83,7 +84,8 @@ Source::SpellCheckView::SpellCheckView(const boost::filesystem::path &file_path,
} }
} }
delayed_spellcheck_error_clear.disconnect(); delayed_spellcheck_error_clear.disconnect();
delayed_spellcheck_error_clear = Glib::signal_timeout().connect([this]() { delayed_spellcheck_error_clear = Glib::signal_timeout().connect(
[this]() {
auto iter = get_buffer()->begin(); auto iter = get_buffer()->begin();
Gtk::TextIter begin_no_spellcheck_iter; Gtk::TextIter begin_no_spellcheck_iter;
if(spellcheck_all) { if(spellcheck_all) {
@ -130,7 +132,8 @@ Source::SpellCheckView::SpellCheckView(const boost::filesystem::path &file_path,
}); });
// In case of for instance text paste or undo/redo // In case of for instance text paste or undo/redo
get_buffer()->signal_insert().connect([this](const Gtk::TextIter &start_iter, const Glib::ustring &inserted_string, int) { get_buffer()->signal_insert().connect(
[this](const Gtk::TextIter &start_iter, const Glib::ustring &inserted_string, int) {
if(!spellcheck_checker) if(!spellcheck_checker)
return; return;
@ -155,7 +158,8 @@ Source::SpellCheckView::SpellCheckView(const boost::filesystem::path &file_path,
delayed_spellcheck_suggestions_connection.disconnect(); delayed_spellcheck_suggestions_connection.disconnect();
if(get_buffer()->get_has_selection()) if(get_buffer()->get_has_selection())
return; return;
delayed_spellcheck_suggestions_connection = Glib::signal_timeout().connect([this]() { delayed_spellcheck_suggestions_connection = Glib::signal_timeout().connect(
[this]() {
if(get_buffer()->get_insert()->get_iter().has_tag(spellcheck_error_tag)) { if(get_buffer()->get_insert()->get_iter().has_tag(spellcheck_error_tag)) {
SelectionDialog::create(this, false); SelectionDialog::create(this, false);
auto word = get_word(get_buffer()->get_insert()->get_iter()); auto word = get_word(get_buffer()->get_insert()->get_iter());

30
src/terminal.cpp

@ -211,7 +211,13 @@ int Terminal::process(const std::string &command, const boost::filesystem::path
std::unique_ptr<TinyProcessLib::Process> process; std::unique_ptr<TinyProcessLib::Process> process;
if(use_pipes) if(use_pipes)
process = std::make_unique<TinyProcessLib::Process>( process = std::make_unique<TinyProcessLib::Process>(
command, path.string(), [this](const char *bytes, size_t n) { async_print(std::string(bytes, n)); }, [this](const char *bytes, size_t n) { async_print(std::string(bytes, n), true); }); command, path.string(),
[this](const char *bytes, size_t n) {
async_print(std::string(bytes, n));
},
[this](const char *bytes, size_t n) {
async_print(std::string(bytes, n), true);
});
else else
process = std::make_unique<TinyProcessLib::Process>(command, path.string()); process = std::make_unique<TinyProcessLib::Process>(command, path.string());
@ -228,7 +234,8 @@ int Terminal::process(std::istream &stdin_stream, std::ostream &stdout_stream, c
scroll_to_bottom(); scroll_to_bottom();
TinyProcessLib::Process process( TinyProcessLib::Process process(
command, path.string(), [&stdout_stream](const char *bytes, size_t n) { command, path.string(),
[&stdout_stream](const char *bytes, size_t n) {
Glib::ustring umessage(std::string(bytes, n)); Glib::ustring umessage(std::string(bytes, n));
Glib::ustring::iterator iter; Glib::ustring::iterator iter;
while(!umessage.validate(iter)) { while(!umessage.validate(iter)) {
@ -236,11 +243,15 @@ int Terminal::process(std::istream &stdin_stream, std::ostream &stdout_stream, c
next_char_iter++; next_char_iter++;
umessage.replace(iter, next_char_iter, "?"); umessage.replace(iter, next_char_iter, "?");
} }
stdout_stream.write(umessage.data(), n); }, [this, stderr_stream](const char *bytes, size_t n) { stdout_stream.write(umessage.data(), n);
},
[this, stderr_stream](const char *bytes, size_t n) {
if(stderr_stream) if(stderr_stream)
stderr_stream->write(bytes, n); stderr_stream->write(bytes, n);
else else
async_print(std::string(bytes, n), true); }, true); async_print(std::string(bytes, n), true);
},
true);
if(process.get_id() <= 0) { if(process.get_id() <= 0) {
async_print("\e[31mError\e[m: failed to run command: " + command + "\n", true); async_print("\e[31mError\e[m: failed to run command: " + command + "\n", true);
@ -268,7 +279,8 @@ std::shared_ptr<TinyProcessLib::Process> Terminal::async_process(const std::stri
stdin_buffer.clear(); stdin_buffer.clear();
auto process = std::make_shared<TinyProcessLib::Process>( auto process = std::make_shared<TinyProcessLib::Process>(
command, path.string(), [this, quiet](const char *bytes, size_t n) { command, path.string(),
[this, quiet](const char *bytes, size_t n) {
if(!quiet) { if(!quiet) {
// Print stdout message sequentially to avoid the GUI becoming unresponsive // Print stdout message sequentially to avoid the GUI becoming unresponsive
std::promise<void> message_printed; std::promise<void> message_printed;
@ -277,7 +289,9 @@ std::shared_ptr<TinyProcessLib::Process> Terminal::async_process(const std::stri
message_printed.set_value(); message_printed.set_value();
}); });
message_printed.get_future().get(); message_printed.get_future().get();
} }, [this, quiet](const char *bytes, size_t n) { }
},
[this, quiet](const char *bytes, size_t n) {
if(!quiet) { if(!quiet) {
// Print stderr message sequentially to avoid the GUI becoming unresponsive // Print stderr message sequentially to avoid the GUI becoming unresponsive
std::promise<void> message_printed; std::promise<void> message_printed;
@ -286,7 +300,9 @@ std::shared_ptr<TinyProcessLib::Process> Terminal::async_process(const std::stri
message_printed.set_value(); message_printed.set_value();
}); });
message_printed.get_future().get(); message_printed.get_future().get();
} }, true); }
},
true);
auto pid = process->get_id(); auto pid = process->get_id();
if(pid <= 0) { if(pid <= 0) {

8
tests/process_test.cpp

@ -15,7 +15,13 @@ int main() {
{ {
TinyProcessLib::Process process( TinyProcessLib::Process process(
"echo Test && ls an_incorrect_path", "", [output](const char *bytes, size_t n) { *output += std::string(bytes, n); }, [error](const char *bytes, size_t n) { *error += std::string(bytes, n); }); "echo Test && ls an_incorrect_path", "",
[output](const char *bytes, size_t n) {
*output += std::string(bytes, n);
},
[error](const char *bytes, size_t n) {
*error += std::string(bytes, n);
});
g_assert(process.get_exit_status() > 0); g_assert(process.get_exit_status() > 0);
g_assert(output->substr(0, 4) == "Test"); g_assert(output->substr(0, 4) == "Test");
g_assert(!error->empty()); g_assert(!error->empty());

Loading…
Cancel
Save