Browse Source

Fixed warnings from clang-tidy's modernize checks

merge-requests/382/head
eidheim 8 years ago
parent
commit
b1ae1656a3
  1. 6
      src/cmake.cc
  2. 8
      src/debug_lldb.cc
  3. 4
      src/directories.h
  4. 8
      src/entrybox.cc
  5. 8
      src/entrybox.h
  6. 2
      src/git.cc
  7. 6
      src/git.h
  8. 2
      src/juci.cc
  9. 2
      src/menu.h
  10. 2
      src/notebook.h
  11. 2
      src/project.cc
  12. 10
      src/project.h
  13. 1
      src/project_build.h
  14. 6
      src/selection_dialog.cc
  15. 2
      src/selection_dialog.h
  16. 8
      src/source.cc
  17. 10
      src/source.h
  18. 14
      src/source_base.cc
  19. 4
      src/source_base.h
  20. 2
      src/source_clang.cc
  21. 4
      src/source_clang.h
  22. 2
      src/source_diff.h
  23. 44
      src/source_language_protocol.cc
  24. 2
      src/source_language_protocol.h
  25. 2
      src/source_spellcheck.h
  26. 6
      src/tooltips.cc
  27. 4
      src/tooltips.h
  28. 6
      src/usages_clang.cc
  29. 6
      src/usages_clang.h
  30. 12
      src/window.cc

6
src/cmake.cc

@ -333,7 +333,7 @@ std::vector<std::string> CMake::get_function_parameters(std::string &data) {
}
std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > CMake::get_functions_parameters(const std::string &name) {
const std::regex function_regex("^ *"+name+" *\\( *(.*)\\) *\\r?$", std::regex::icase);
const std::regex function_regex("^ *"+name+R"( *\( *(.*)\) *\r?$)", std::regex::icase);
variables.clear();
if(!parsed)
parse();
@ -348,8 +348,8 @@ std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > CMak
if(end_line>start_line) {
auto line=files[c].substr(start_line, end_line-start_line);
std::smatch sm;
const static std::regex set_regex("^ *set *\\( *([A-Za-z_][A-Za-z_0-9]*) +(.*)\\) *\\r?$", std::regex::icase);
const static std::regex project_regex("^ *project *\\( *([^ ]+).*\\) *\\r?$", std::regex::icase);
const static std::regex set_regex(R"(^ *set *\( *([A-Za-z_][A-Za-z_0-9]*) +(.*)\) *\r?$)", std::regex::icase);
const static std::regex project_regex(R"(^ *project *\( *([^ ]+).*\) *\r?$)", std::regex::icase);
if(std::regex_match(line, sm, set_regex)) {
auto data=sm[2].str();
while(data.size()>0 && data.back()==' ')

8
src/debug_lldb.cc

@ -1,7 +1,7 @@
#include "debug_lldb.h"
#include <stdio.h>
#include <cstdio>
#ifdef __APPLE__
#include <stdlib.h>
#include <cstdlib>
#endif
#include <boost/filesystem.hpp>
#include <iostream>
@ -103,8 +103,8 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat
auto &arguments=std::get<2>(parsed_run_arguments);
std::vector<const char*> argv;
for(size_t c=0;c<arguments.size();c++)
argv.emplace_back(arguments[c].c_str());
for(auto &argument : arguments)
argv.emplace_back(argument.c_str());
argv.emplace_back(nullptr);
auto target=debugger->CreateTarget(executable.c_str());

4
src/directories.h

@ -24,7 +24,7 @@ class Directories : public Gtk::ListViewText {
class TreeStore : public Gtk::TreeStore {
protected:
TreeStore() {}
TreeStore()=default;
bool row_drop_possible_vfunc(const Gtk::TreeModel::Path &path, const Gtk::SelectionData &selection_data) const override;
bool drag_data_received_vfunc(const TreeModel::Path &path, const Gtk::SelectionData &selection_data) override;
@ -56,7 +56,7 @@ public:
static Directories singleton;
return singleton;
}
~Directories();
~Directories() override;
void open(const boost::filesystem::path &dir_path="");
void update();

8
src/entrybox.cc

@ -2,7 +2,7 @@
std::unordered_map<std::string, std::vector<std::string> > EntryBox::entry_histories;
EntryBox::Entry::Entry(const std::string& content, std::function<void(const std::string& content)> on_activate, unsigned width_chars) : Gtk::Entry(), on_activate(on_activate) {
EntryBox::Entry::Entry(const std::string& content, std::function<void(const std::string& content)> on_activate_, unsigned width_chars) : Gtk::Entry(), on_activate(std::move(on_activate_)) {
set_max_length(0);
set_width_chars(width_chars);
set_text(content);
@ -41,7 +41,7 @@ EntryBox::Entry::Entry(const std::string& content, std::function<void(const std:
});
}
EntryBox::Button::Button(const std::string& label, std::function<void()> on_activate) : Gtk::Button(label), on_activate(on_activate) {
EntryBox::Button::Button(const std::string& label, std::function<void()> on_activate_) : Gtk::Button(label), on_activate(std::move(on_activate_)) {
set_focus_on_click(false);
signal_clicked().connect([this](){
if(this->on_activate)
@ -49,7 +49,7 @@ EntryBox::Button::Button(const std::string& label, std::function<void()> on_acti
});
}
EntryBox::ToggleButton::ToggleButton(const std::string& label, std::function<void()> on_activate) : Gtk::ToggleButton(label), on_activate(on_activate) {
EntryBox::ToggleButton::ToggleButton(const std::string& label, std::function<void()> on_activate_) : Gtk::ToggleButton(label), on_activate(std::move(on_activate_)) {
set_focus_on_click(false);
signal_clicked().connect([this](){
if(this->on_activate)
@ -57,7 +57,7 @@ EntryBox::ToggleButton::ToggleButton(const std::string& label, std::function<voi
});
}
EntryBox::Label::Label(std::function<void(int state, const std::string& message)> update) : Gtk::Label(), update(update) {
EntryBox::Label::Label(std::function<void(int state, const std::string& message)> update_) : Gtk::Label(), update(std::move(update_)) {
if(this->update)
this->update(-1, "");
}

8
src/entrybox.h

@ -10,24 +10,24 @@ class EntryBox : public Gtk::Box {
public:
class Entry : public Gtk::Entry {
public:
Entry(const std::string& content="", std::function<void(const std::string& content)> on_activate=nullptr, unsigned width_chars=-1);
Entry(const std::string& content="", std::function<void(const std::string& content)> on_activate_=nullptr, unsigned width_chars=-1);
std::function<void(const std::string& content)> on_activate;
private:
size_t selected_history;
};
class Button : public Gtk::Button {
public:
Button(const std::string& label, std::function<void()> on_activate=nullptr);
Button(const std::string& label, std::function<void()> on_activate_=nullptr);
std::function<void()> on_activate;
};
class ToggleButton : public Gtk::ToggleButton {
public:
ToggleButton(const std::string& label, std::function<void()> on_activate=nullptr);
ToggleButton(const std::string& label, std::function<void()> on_activate_=nullptr);
std::function<void()> on_activate;
};
class Label : public Gtk::Label {
public:
Label(std::function<void(int state, const std::string& message)> update=nullptr);
Label(std::function<void(int state, const std::string& message)> update_=nullptr);
std::function<void(int state, const std::string& message)> update;
};

2
src/git.cc

@ -225,7 +225,7 @@ boost::filesystem::path Git::Repository::get_path() noexcept {
boost::filesystem::path Git::Repository::get_root_path(const boost::filesystem::path &path) {
initialize();
git_buf root = {0, 0, 0};
git_buf root = {nullptr, 0, 0};
{
Error error;
std::lock_guard<std::mutex> lock(mutex);

6
src/git.h

@ -17,7 +17,6 @@ public:
std::string message() noexcept;
public:
int code=0;
Error() {}
operator bool() noexcept {return code<0;}
};
@ -42,13 +41,12 @@ public:
private:
friend class Repository;
Diff(const boost::filesystem::path &path, git_repository *repository);
git_repository *repository;
std::shared_ptr<git_blob> blob;
git_repository *repository=nullptr;
std::shared_ptr<git_blob> blob=nullptr;
git_diff_options options;
static int hunk_cb(const git_diff_delta *delta, const git_diff_hunk *hunk, void *payload) noexcept;
static int line_cb(const git_diff_delta *delta, const git_diff_hunk *hunk, const git_diff_line *line, void *payload) noexcept;
public:
Diff() : repository(nullptr), blob(nullptr) {}
Lines get_lines(const std::string &buffer);
static std::vector<Hunk> get_hunks(const std::string &old_buffer, const std::string &new_buffer);
std::string get_details(const std::string &buffer, int line_nr);

2
src/juci.cc

@ -6,7 +6,7 @@
#include "config.h"
#include "terminal.h"
#ifndef _WIN32
#include <signal.h>
#include <csignal>
#endif
int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) {

2
src/menu.h

@ -5,7 +5,7 @@
#include <gtkmm.h>
class Menu {
Menu() {}
Menu() = default;
public:
static Menu &get() {
static Menu singleton;

2
src/notebook.h

@ -15,7 +15,7 @@ class Notebook : public Gtk::Paned {
class CursorLocation {
public:
CursorLocation(Source::View *view, Glib::RefPtr<Gtk::TextBuffer::Mark> mark) : view(view), mark(mark) {}
CursorLocation(Source::View *view, Glib::RefPtr<Gtk::TextBuffer::Mark> mark_) : view(view), mark(std::move(mark_)) {}
Source::View *view;
Glib::RefPtr<Gtk::TextBuffer::Mark> mark;
};

2
src/project.cc

@ -713,7 +713,7 @@ void Project::LanguageProtocol::show_symbols() {
}
std::vector<std::string> names;
std::promise<void> result_processed;
client->write_request(nullptr, "workspace/symbol", "\"query\":\""+text+"\"", [&result_processed, &names, offsets, project_path](const boost::property_tree::ptree &result, bool error) {
client->write_request(nullptr, "workspace/symbol", R"("query":")"+text+'"', [&result_processed, &names, offsets, project_path](const boost::property_tree::ptree &result, bool error) {
if(!error) {
for(auto it=result.begin();it!=result.end();++it) {
auto name=it->second.get<std::string>("name", "");

10
src/project.h

@ -41,9 +41,9 @@ namespace Project {
protected:
static std::unique_ptr<DebugOptions> debug_options;
public:
Base() {}
Base() = default;
Base(std::unique_ptr<Build> &&build): build(std::move(build)) {}
virtual ~Base() {}
virtual ~Base() = default;
std::unique_ptr<Build> build;
@ -78,8 +78,7 @@ namespace Project {
class LLDB : public virtual Base {
public:
LLDB() {}
~LLDB() { dispatcher.disconnect(); }
~LLDB() override { dispatcher.disconnect(); }
#ifdef JUCI_ENABLE_DEBUG
std::pair<std::string, std::string> debug_get_run_arguments() override;
@ -104,7 +103,6 @@ namespace Project {
class LanguageProtocol : public virtual Base {
public:
LanguageProtocol() {}
virtual std::string get_language_id()=0;
void show_symbols() override;
};
@ -122,7 +120,7 @@ namespace Project {
class Markdown : public Base {
public:
Markdown(std::unique_ptr<Build> &&build) : Base(std::move(build)) {}
~Markdown();
~Markdown() override;
boost::filesystem::path last_temp_path;
void compile_and_run() override;

1
src/project_build.h

@ -6,7 +6,6 @@
namespace Project {
class Build {
public:
Build() {}
virtual ~Build() {}
boost::filesystem::path project_path;

6
src/selection_dialog.cc

@ -36,8 +36,8 @@ void SelectionDialogBase::ListViewText::clear() {
size=0;
}
SelectionDialogBase::SelectionDialogBase(Gtk::TextView *text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark, bool show_search_entry, bool use_markup):
start_mark(start_mark), text_view(text_view), window(Gtk::WindowType::WINDOW_POPUP), vbox(Gtk::Orientation::ORIENTATION_VERTICAL), list_view_text(use_markup), show_search_entry(show_search_entry) {
SelectionDialogBase::SelectionDialogBase(Gtk::TextView *text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark_, bool show_search_entry, bool use_markup):
start_mark(std::move(start_mark_)), text_view(text_view), window(Gtk::WindowType::WINDOW_POPUP), vbox(Gtk::Orientation::ORIENTATION_VERTICAL), list_view_text(use_markup), show_search_entry(show_search_entry) {
auto g_application=g_application_get_default();
auto gio_application=Glib::wrap(g_application, true);
auto application=Glib::RefPtr<Gtk::Application>::cast_static(gio_application);
@ -133,7 +133,7 @@ void SelectionDialogBase::cursor_changed() {
if(!is_visible())
return;
auto it=list_view_text.get_selection()->get_selected();
unsigned int index=static_cast<unsigned int>(-1);
auto index=static_cast<unsigned int>(-1);
if(it)
index=it->get_value(list_view_text.column_record.index);
if(last_index==index)

2
src/selection_dialog.h

@ -34,7 +34,7 @@ class SelectionDialogBase {
};
public:
SelectionDialogBase(Gtk::TextView *text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark, bool show_search_entry, bool use_markup);
SelectionDialogBase(Gtk::TextView *text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark_, bool show_search_entry, bool use_markup);
virtual ~SelectionDialogBase();
void add_row(const std::string& row);
void erase_rows();

8
src/source.cc

@ -71,8 +71,8 @@ Glib::RefPtr<Gsv::Language> Source::guess_language(const boost::filesystem::path
return language;
}
Source::FixIt::FixIt(const std::string &source, const std::pair<Offset, Offset> &offsets) : source(source), offsets(offsets) {
if(source.size()==0)
Source::FixIt::FixIt(std::string source_, std::pair<Offset, Offset> offsets_) : source(std::move(source_)), offsets(std::move(offsets_)) {
if(this->source.size()==0)
type=Type::ERASE;
else {
if(this->offsets.first==this->offsets.second)
@ -82,7 +82,7 @@ Source::FixIt::FixIt(const std::string &source, const std::pair<Offset, Offset>
}
}
std::string Source::FixIt::string(Glib::RefPtr<Gtk::TextBuffer> buffer) {
std::string Source::FixIt::string(const Glib::RefPtr<Gtk::TextBuffer> &buffer) {
auto iter=buffer->get_iter_at_line_index(offsets.first.line, offsets.first.index);
unsigned first_line_offset=iter.get_line_offset()+1;
iter=buffer->get_iter_at_line_index(offsets.second.line, offsets.second.index);
@ -641,7 +641,7 @@ void Source::View::setup_format_style(bool is_generic_view) {
}
}
else if(is_generic_view) {
static std::regex regex("^\\[error\\] stdin: (.*) \\(([0-9]*):([0-9]*)\\)$");
static std::regex regex(R"(^\[error\] stdin: (.*) \(([0-9]*):([0-9]*)\)$)");
std::string line;
std::getline(stderr_stream, line);
std::smatch sm;

10
src/source.h

@ -25,8 +25,8 @@ namespace Source {
class Offset {
public:
Offset() {}
Offset(unsigned line, unsigned index, const boost::filesystem::path &file_path=""): line(line), index(index), file_path(file_path) {}
Offset() = default;
Offset(unsigned line, unsigned index, boost::filesystem::path file_path_=""): line(line), index(index), file_path(std::move(file_path_)) {}
operator bool() { return !file_path.empty(); }
bool operator==(const Offset &o) {return (line==o.line && index==o.index);}
@ -39,9 +39,9 @@ namespace Source {
public:
enum class Type {INSERT, REPLACE, ERASE};
FixIt(const std::string &source, const std::pair<Offset, Offset> &offsets);
FixIt(std::string source_, std::pair<Offset, Offset> offsets_);
std::string string(Glib::RefPtr<Gtk::TextBuffer> buffer);
std::string string(const Glib::RefPtr<Gtk::TextBuffer> &buffer);
Type type;
std::string source;
@ -54,7 +54,7 @@ namespace Source {
static std::unordered_set<View*> views;
View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language, bool is_generic_view=false);
~View();
~View() override;
bool save() override;

14
src/source_base.cc

@ -1,3 +1,5 @@
#include <utility>
#include "source_base.h"
#include "info.h"
#include "terminal.h"
@ -5,9 +7,9 @@
#include "config.h"
#include <fstream>
Source::BaseView::BaseView(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language): Gsv::View(), file_path(file_path), language(language), status_diagnostics(0, 0, 0) {
Source::BaseView::BaseView(boost::filesystem::path file_path_, Glib::RefPtr<Gsv::Language> language_): Gsv::View(), file_path(std::move(file_path_)), language(std::move(language_)), status_diagnostics(0, 0, 0) {
load(true);
get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0));
get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0));
signal_focus_in_event().connect([this](GdkEventFocus *event) {
if(this->last_write_time!=static_cast<std::time_t>(-1))
@ -119,10 +121,10 @@ void Source::BaseView::replace_text(const std::string &new_text) {
std::vector<std::pair<const char*, const char*>> new_lines;
const char* line_start=new_text.c_str();
for(size_t i=0;i<new_text.size();++i) {
if(new_text[i]=='\n') {
new_lines.emplace_back(line_start, &new_text[i]+1);
line_start = &new_text[i]+1;
for(const char &chr: new_text) {
if(chr=='\n') {
new_lines.emplace_back(line_start, &chr+1);
line_start = &chr+1;
}
}
if(new_text.empty() || new_text.back()!='\n')

4
src/source_base.h

@ -8,8 +8,8 @@
namespace Source {
class BaseView : public Gsv::View {
public:
BaseView(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language);
~BaseView();
BaseView(boost::filesystem::path file_path_, Glib::RefPtr<Gsv::Language> language_);
~BaseView() override;
boost::filesystem::path file_path;
Glib::RefPtr<Gsv::Language> language;

2
src/source_clang.cc

@ -535,7 +535,7 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
show_arguments=false;
std::string line=" "+get_line_before();
const static std::regex dot_or_arrow("^.*[a-zA-Z0-9_\\)\\]\\>](\\.|->)([a-zA-Z0-9_]*)$");
const static std::regex dot_or_arrow(R"(^.*[a-zA-Z0-9_\)\]\>](\.|->)([a-zA-Z0-9_]*)$)");
const static std::regex colon_colon("^.*::([a-zA-Z0-9_]*)$");
const static std::regex part_of_symbol("^.*[^a-zA-Z0-9_]+([a-zA-Z0-9_]{3,})$");
std::smatch sm;

4
src/source_clang.h

@ -70,8 +70,8 @@ namespace Source {
class ClangViewRefactor : public virtual ClangViewParse {
class Identifier {
public:
Identifier(const std::string &spelling, const clangmm::Cursor &cursor)
: kind(cursor.get_kind()), spelling(spelling), usr_extended(cursor.get_usr_extended()), cursor(cursor) {}
Identifier(std::string spelling_, const clangmm::Cursor &cursor)
: kind(cursor.get_kind()), spelling(std::move(spelling_)), usr_extended(cursor.get_usr_extended()), cursor(cursor) {}
Identifier() : kind(static_cast<clangmm::Cursor::Kind>(0)) {}
operator bool() const { return static_cast<int>(kind)!=0; }

2
src/source_diff.h

@ -30,7 +30,7 @@ namespace Source {
};
public:
DiffView(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language);
~DiffView();
~DiffView() override;
void configure() override;

44
src/source_language_protocol.cc

@ -88,7 +88,7 @@ LanguageProtocol::Capabilities LanguageProtocol::Client::initialize(Source::Lang
return capabilities;
std::promise<void> result_processed;
write_request(nullptr, "initialize", "\"processId\":"+std::to_string(process->get_id())+",\"rootUri\":\"file://"+root_uri+"\",\"capabilities\":{\"workspace\":{\"didChangeConfiguration\":{\"dynamicRegistration\":true},\"didChangeWatchedFiles\":{\"dynamicRegistration\":true},\"symbol\":{\"dynamicRegistration\":true},\"executeCommand\":{\"dynamicRegistration\":true}},\"textDocument\":{\"synchronization\":{\"dynamicRegistration\":true,\"willSave\":true,\"willSaveWaitUntil\":true,\"didSave\":true},\"completion\":{\"dynamicRegistration\":true,\"completionItem\":{\"snippetSupport\":true}},\"hover\":{\"dynamicRegistration\":true},\"signatureHelp\":{\"dynamicRegistration\":true},\"definition\":{\"dynamicRegistration\":true},\"references\":{\"dynamicRegistration\":true},\"documentHighlight\":{\"dynamicRegistration\":true},\"documentSymbol\":{\"dynamicRegistration\":true},\"codeAction\":{\"dynamicRegistration\":true},\"codeLens\":{\"dynamicRegistration\":true},\"formatting\":{\"dynamicRegistration\":true},\"rangeFormatting\":{\"dynamicRegistration\":true},\"onTypeFormatting\":{\"dynamicRegistration\":true},\"rename\":{\"dynamicRegistration\":true},\"documentLink\":{\"dynamicRegistration\":true}}},\"initializationOptions\":{\"omitInitBuild\":true},\"trace\":\"off\"", [this, &result_processed](const boost::property_tree::ptree &result, bool error) {
write_request(nullptr, "initialize", "\"processId\":"+std::to_string(process->get_id())+R"(,"rootUri":"file://)"+root_uri+R"(","capabilities":{"workspace":{"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true},"executeCommand":{"dynamicRegistration":true}},"textDocument":{"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"completionItem":{"snippetSupport":true}},"hover":{"dynamicRegistration":true},"signatureHelp":{"dynamicRegistration":true},"definition":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true},"codeAction":{"dynamicRegistration":true},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true},"documentLink":{"dynamicRegistration":true}}},"initializationOptions":{"omitInitBuild":true},"trace":"off")", [this, &result_processed](const boost::property_tree::ptree &result, bool error) {
if(!error) {
auto capabilities_pt=result.find("capabilities");
if(capabilities_pt!=result.not_found()) {
@ -106,7 +106,7 @@ LanguageProtocol::Capabilities LanguageProtocol::Client::initialize(Source::Lang
write_notification("initialized", "");
if(language_id=="rust")
write_notification("workspace/didChangeConfiguration", "\"settings\":{\"rust\":{\"sysroot\":null,\"target\":null,\"rustflags\":null,\"clear_env_rust_log\":true,\"build_lib\":null,\"build_bin\":null,\"cfg_test\":false,\"unstable_features\":false,\"wait_to_build\":500,\"show_warnings\":true,\"goto_def_racer_fallback\":false,\"use_crate_blacklist\":true,\"build_on_save\":false,\"workspace_mode\":true,\"analyze_package\":null,\"features\":[],\"all_features\":false,\"no_default_features\":false}}");
write_notification("workspace/didChangeConfiguration", R"("settings":{"rust":{"sysroot":null,"target":null,"rustflags":null,"clear_env_rust_log":true,"build_lib":null,"build_bin":null,"cfg_test":false,"unstable_features":false,"wait_to_build":500,"show_warnings":true,"goto_def_racer_fallback":false,"use_crate_blacklist":true,"build_on_save":false,"workspace_mode":true,"analyze_package":null,"features":[],"all_features":false,"no_default_features":false}})");
}
result_processed.set_value();
});
@ -261,7 +261,7 @@ void LanguageProtocol::Client::write_request(Source::LanguageProtocolView *view,
}
});
}
std::string content("{\"jsonrpc\":\"2.0\",\"id\":"+std::to_string(message_id++)+",\"method\":\""+method+"\",\"params\":{"+params+"}}");
std::string content(R"({"jsonrpc":"2.0","id":)"+std::to_string(message_id++)+R"(,"method":")"+method+R"(","params":{)"+params+"}}");
auto message="Content-Length: "+std::to_string(content.size())+"\r\n\r\n"+content;
if(output_messages_and_errors)
std::cout << "Language client: " << content << std::endl;
@ -280,7 +280,7 @@ void LanguageProtocol::Client::write_request(Source::LanguageProtocolView *view,
void LanguageProtocol::Client::write_notification(const std::string &method, const std::string &params) {
std::unique_lock<std::mutex> lock(read_write_mutex);
std::string content("{\"jsonrpc\":\"2.0\",\"method\":\""+method+"\",\"params\":{"+params+"}}");
std::string content(R"({"jsonrpc":"2.0","method":")"+method+R"(","params":{)"+params+"}}");
auto message="Content-Length: "+std::to_string(content.size())+"\r\n\r\n"+content;
if(output_messages_and_errors)
std::cout << "Language client: " << content << std::endl;
@ -356,7 +356,7 @@ Source::LanguageProtocolView::LanguageProtocolView(const boost::filesystem::path
std::string text=get_buffer()->get_text();
escape_text(text);
client->write_notification("textDocument/didOpen", "\"textDocument\":{\"uri\":\""+uri+"\",\"languageId\":\""+language_id+"\",\"version\":"+std::to_string(document_version++)+",\"text\":\""+text+"\"}");
client->write_notification("textDocument/didOpen", R"("textDocument":{"uri":")"+uri+R"(","languageId":")"+language_id+R"(","version":)"+std::to_string(document_version++)+R"(,"text":")"+text+"\"}");
setup_autocomplete();
setup_navigation_and_refactoring();
@ -391,14 +391,14 @@ Source::LanguageProtocolView::LanguageProtocolView(const boost::filesystem::path
if(capabilities.text_document_sync==LanguageProtocol::Capabilities::TextDocumentSync::INCREMENTAL) {
std::string text=text_;
escape_text(text);
content_changes="{\"range\":{\"start\":{\"line\": "+std::to_string(start.get_line())+",\"character\":"+std::to_string(start.get_line_offset())+"},\"end\":{\"line\":"+std::to_string(start.get_line())+",\"character\":"+std::to_string(start.get_line_offset())+"}},\"text\":\""+text+"\"}";
content_changes=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+"\"}";
}
else {
std::string text=get_buffer()->get_text();
escape_text(text);
content_changes="{\"text\":\""+text+"\"}";
content_changes=R"({"text":")"+text+"\"}";
}
client->write_notification("textDocument/didChange", "\"textDocument\":{\"uri\":\""+uri+"\",\"version\":"+std::to_string(document_version++)+"},\"contentChanges\":["+content_changes+"]");
client->write_notification("textDocument/didChange", R"("textDocument":{"uri":")"+uri+R"(","version":)"+std::to_string(document_version++)+"},\"contentChanges\":["+content_changes+"]");
}, false);
get_buffer()->signal_erase().connect([this](const Gtk::TextBuffer::iterator &start, const Gtk::TextBuffer::iterator &end) {
@ -406,13 +406,13 @@ Source::LanguageProtocolView::LanguageProtocolView(const boost::filesystem::path
if(capabilities.text_document_sync==LanguageProtocol::Capabilities::TextDocumentSync::NONE)
return;
if(capabilities.text_document_sync==LanguageProtocol::Capabilities::TextDocumentSync::INCREMENTAL)
content_changes="{\"range\":{\"start\":{\"line\": "+std::to_string(start.get_line())+",\"character\":"+std::to_string(start.get_line_offset())+"},\"end\":{\"line\":"+std::to_string(end.get_line())+",\"character\":"+std::to_string(end.get_line_offset())+"}},\"text\":\"\"}";
content_changes=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":""})";
else {
std::string text=get_buffer()->get_text();
escape_text(text);
content_changes="{\"text\":\""+text+"\"}";
content_changes=R"({"text":")"+text+"\"}";
}
client->write_notification("textDocument/didChange", "\"textDocument\":{\"uri\":\""+uri+"\",\"version\":"+std::to_string(document_version++)+"},\"contentChanges\":["+content_changes+"]");
client->write_notification("textDocument/didChange", R"("textDocument":{"uri":")"+uri+R"(","version":)"+std::to_string(document_version++)+"},\"contentChanges\":["+content_changes+"]");
}, false);
}
@ -424,7 +424,7 @@ Source::LanguageProtocolView::~LanguageProtocolView() {
if(autocomplete.thread.joinable())
autocomplete.thread.join();
client->write_notification("textDocument/didClose", "\"textDocument\":{\"uri\":\""+uri+"\"}");
client->write_notification("textDocument/didClose", R"("textDocument":{"uri":")"+uri+"\"}");
client->close(this);
client=nullptr;
@ -477,11 +477,11 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
method="textDocument/rangeFormatting";
Gtk::TextIter start, end;
get_buffer()->get_selection_bounds(start, end);
params="\"textDocument\":{\"uri\":\""+uri+"\"},\"range\":{\"start\":{\"line\":"+std::to_string(start.get_line())+",\"character\":"+std::to_string(start.get_line_offset())+"},\"end\":{\"line\":"+std::to_string(end.get_line())+",\"character\":"+std::to_string(end.get_line_offset())+"}},\"options\":{"+options+"}";
params=R"("textDocument":{"uri":")"+uri+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())+"}},\"options\":{"+options+"}";
}
else {
method="textDocument/formatting";
params="\"textDocument\":{\"uri\":\""+uri+"\"},\"options\":{"+options+"}";
params=R"("textDocument":{"uri":")"+uri+R"("},"options":{)"+options+"}";
}
client->write_request(this, method, params, [&replaces, &result_processed](const boost::property_tree::ptree &result, bool error) {
@ -552,7 +552,7 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
std::vector<std::pair<Offset, std::string>> usages;
std::vector<Offset> end_offsets;
std::promise<void> result_processed;
client->write_request(this, "textDocument/references", "\"textDocument\":{\"uri\":\""+uri+"\"}, \"position\": {\"line\": "+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+"}, \"context\": {\"includeDeclaration\": true}", [&usages, &end_offsets, &result_processed](const boost::property_tree::ptree &result, bool error) {
client->write_request(this, "textDocument/references", R"("textDocument":{"uri":")"+uri+R"("}, "position": {"line": )"+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+R"(}, "context": {"includeDeclaration": true})", [&usages, &end_offsets, &result_processed](const boost::property_tree::ptree &result, bool error) {
if(!error) {
try {
for(auto it=result.begin();it!=result.end();++it) {
@ -612,7 +612,7 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
};
std::map<boost::filesystem::path, std::vector<std::string>> file_lines;
size_t c=static_cast<size_t>(-1);
auto c=static_cast<size_t>(-1);
for(auto &usage: usages) {
++c;
auto view_it=views.end();
@ -697,7 +697,7 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
auto iter=get_buffer()->get_insert()->get_iter();
std::vector<Usages> usages;
std::promise<void> result_processed;
client->write_request(this, "textDocument/rename", "\"textDocument\":{\"uri\":\""+uri+"\"}, \"position\": {\"line\": "+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+"}, \"newName\": \""+text+"\"", [this, &usages, &result_processed](const boost::property_tree::ptree &result, bool error) {
client->write_request(this, "textDocument/rename", R"("textDocument":{"uri":")"+uri+R"("}, "position": {"line": )"+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+R"(}, "newName": ")"+text+"\"", [this, &usages, &result_processed](const boost::property_tree::ptree &result, bool error) {
if(!error) {
boost::filesystem::path project_path;
auto build=Project::Build::create(file_path);
@ -955,7 +955,7 @@ void Source::LanguageProtocolView::show_type_tooltips(const Gdk::Rectangle &rect
static int request_count=0;
request_count++;
auto current_request=request_count;
client->write_request(this, "textDocument/hover", "\"textDocument\": {\"uri\":\"file://"+file_path.string()+"\"}, \"position\": {\"line\": "+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+"}", [this, offset, current_request](const boost::property_tree::ptree &result, bool error) {
client->write_request(this, "textDocument/hover", R"("textDocument": {"uri":"file://)"+file_path.string()+R"("}, "position": {"line": )"+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+"}", [this, offset, current_request](const boost::property_tree::ptree &result, bool error) {
if(!error) {
// hover result structure vary significantly from the different language servers
std::string content;
@ -1053,7 +1053,7 @@ void Source::LanguageProtocolView::tag_similar_symbols() {
static int request_count=0;
request_count++;
auto current_request=request_count;
client->write_request(this, method, "\"textDocument\":{\"uri\":\""+uri+"\"}, \"position\": {\"line\": "+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+"}, \"context\": {\"includeDeclaration\": true}", [this, current_request](const boost::property_tree::ptree &result, bool error) {
client->write_request(this, method, R"("textDocument":{"uri":")"+uri+R"("}, "position": {"line": )"+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+R"(}, "context": {"includeDeclaration": true})", [this, current_request](const boost::property_tree::ptree &result, bool error) {
if(!error) {
std::vector<std::pair<Offset, Offset>> offsets;
for(auto it=result.begin();it!=result.end();++it) {
@ -1089,7 +1089,7 @@ void Source::LanguageProtocolView::tag_similar_symbols() {
Source::Offset Source::LanguageProtocolView::get_declaration(const Gtk::TextIter &iter) {
auto offset=std::make_shared<Offset>();
std::promise<void> result_processed;
client->write_request(this, "textDocument/definition", "\"textDocument\":{\"uri\":\""+uri+"\"}, \"position\": {\"line\": "+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+"}", [offset, &result_processed](const boost::property_tree::ptree &result, bool error) {
client->write_request(this, "textDocument/definition", R"("textDocument":{"uri":")"+uri+R"("}, "position": {"line": )"+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+"}", [offset, &result_processed](const boost::property_tree::ptree &result, bool error) {
if(!error) {
for(auto it=result.begin();it!=result.end();++it) {
auto uri=it->second.get<std::string>("uri", "");
@ -1147,7 +1147,7 @@ void Source::LanguageProtocolView::setup_autocomplete() {
return false;
std::string line=" "+get_line_before();
const static std::regex dot_or_arrow("^.*[a-zA-Z0-9_\\)\\]\\>\"'](\\.)([a-zA-Z0-9_]*)$");
const static std::regex dot_or_arrow(R"(^.*[a-zA-Z0-9_\)\]\>"'](\.)([a-zA-Z0-9_]*)$)");
const static std::regex colon_colon("^.*::([a-zA-Z0-9_]*)$");
const static std::regex part_of_symbol("^.*[^a-zA-Z0-9_]+([a-zA-Z0-9_]{3,})$");
std::smatch sm;
@ -1211,7 +1211,7 @@ void Source::LanguageProtocolView::setup_autocomplete() {
autocomplete_comment.clear();
autocomplete_insert.clear();
std::promise<void> result_processed;
client->write_request(this, "textDocument/completion", "\"textDocument\":{\"uri\":\""+uri+"\"}, \"position\": {\"line\": "+std::to_string(line_number-1)+", \"character\": "+std::to_string(column-1)+"}", [this, &result_processed](const boost::property_tree::ptree &result, bool error) {
client->write_request(this, "textDocument/completion", R"("textDocument":{"uri":")"+uri+R"("}, "position": {"line": )"+std::to_string(line_number-1)+", \"character\": "+std::to_string(column-1)+"}", [this, &result_processed](const boost::property_tree::ptree &result, bool error) {
if(!error) {
auto begin=result.begin(); // rust language server is bugged
auto end=result.end();

2
src/source_language_protocol.h

@ -85,7 +85,7 @@ namespace Source {
class LanguageProtocolView : public View {
public:
LanguageProtocolView(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language, std::string language_id_);
~LanguageProtocolView();
~LanguageProtocolView() override;
std::string uri;
bool save() override;

2
src/source_spellcheck.h

@ -6,7 +6,7 @@ namespace Source {
class SpellCheckView : virtual public Source::BaseView {
public:
SpellCheckView(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language);
~SpellCheckView();
~SpellCheckView() override;
void configure() override;
void hide_dialogs() override;

6
src/tooltips.cc

@ -4,9 +4,9 @@
std::set<Tooltip*> Tooltips::shown_tooltips;
Gdk::Rectangle Tooltips::drawn_tooltips_rectangle=Gdk::Rectangle();
Tooltip::Tooltip(std::function<Glib::RefPtr<Gtk::TextBuffer>()> create_tooltip_buffer, Gtk::TextView *text_view,
Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark, Glib::RefPtr<Gtk::TextBuffer::Mark> end_mark)
: start_mark(start_mark), end_mark(end_mark), create_tooltip_buffer(create_tooltip_buffer), text_view(text_view) {}
Tooltip::Tooltip(std::function<Glib::RefPtr<Gtk::TextBuffer>()> create_tooltip_buffer_, Gtk::TextView *text_view,
Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark_, Glib::RefPtr<Gtk::TextBuffer::Mark> end_mark_)
: start_mark(std::move(start_mark_)), end_mark(std::move(end_mark_)), create_tooltip_buffer(std::move(create_tooltip_buffer_)), text_view(text_view) {}
Tooltip::~Tooltip() {
Tooltips::shown_tooltips.erase(this);

4
src/tooltips.h

@ -7,8 +7,8 @@
class Tooltip {
public:
Tooltip(std::function<Glib::RefPtr<Gtk::TextBuffer>()> create_tooltip_buffer, Gtk::TextView *text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark, Glib::RefPtr<Gtk::TextBuffer::Mark> end_mark);
Tooltip(std::function<Glib::RefPtr<Gtk::TextBuffer>()> create_tooltip_buffer) : Tooltip(create_tooltip_buffer, nullptr, Glib::RefPtr<Gtk::TextBuffer::Mark>(), Glib::RefPtr<Gtk::TextBuffer::Mark>()) {}
Tooltip(std::function<Glib::RefPtr<Gtk::TextBuffer>()> create_tooltip_buffer_, Gtk::TextView *text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark_, Glib::RefPtr<Gtk::TextBuffer::Mark> end_mark_);
Tooltip(std::function<Glib::RefPtr<Gtk::TextBuffer>()> create_tooltip_buffer_) : Tooltip(std::move(create_tooltip_buffer_), nullptr, Glib::RefPtr<Gtk::TextBuffer::Mark>(), Glib::RefPtr<Gtk::TextBuffer::Mark>()) {}
~Tooltip();
void update();

6
src/usages_clang.cc

@ -33,9 +33,9 @@ bool Usages::Clang::Cache::Cursor::operator==(const Cursor &o) {
return false;
}
Usages::Clang::Cache::Cache(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &path,
Usages::Clang::Cache::Cache(boost::filesystem::path project_path_, boost::filesystem::path build_path_, const boost::filesystem::path &path,
std::time_t before_parse_time, clangmm::TranslationUnit *translation_unit, clangmm::Tokens *clang_tokens)
: project_path(project_path), build_path(build_path) {
: project_path(std::move(project_path_)), build_path(std::move(build_path_)) {
for(auto &clang_token : *clang_tokens) {
tokens.emplace_back(Token{clang_token.get_spelling(), clang_token.get_source_range().get_offsets(), static_cast<size_t>(-1)});
@ -71,7 +71,7 @@ Usages::Clang::Cache::Cache(const boost::filesystem::path &project_path, const b
std::time_t before_parse_time;
std::map<boost::filesystem::path, std::time_t> &paths_and_last_write_times;
};
VisitorData visitor_data{project_path, path, before_parse_time, paths_and_last_write_times};
VisitorData visitor_data{this->project_path, path, before_parse_time, paths_and_last_write_times};
clang_getInclusions(translation_unit->cx_tu, [](CXFile included_file, CXSourceLocation *inclusion_stack, unsigned include_len, CXClientData data) {
auto visitor_data = static_cast<VisitorData *>(data);

6
src/usages_clang.h

@ -30,7 +30,7 @@ namespace boost {
namespace Usages {
class Clang {
public:
typedef std::set<boost::filesystem::path> PathSet;
using PathSet = std::set<boost::filesystem::path>;
class Usages {
public:
@ -89,8 +89,8 @@ namespace Usages {
std::vector<Cursor> cursors;
std::map<boost::filesystem::path, std::time_t> paths_and_last_write_times;
Cache() {}
Cache(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &path,
Cache() = default;
Cache(boost::filesystem::path project_path_, boost::filesystem::path build_path_, const boost::filesystem::path &path,
std::time_t before_parse_time, clangmm::TranslationUnit *translation_unit, clangmm::Tokens *clang_tokens);
operator bool() const { return !paths_and_last_write_times.empty(); }

12
src/window.cc

@ -235,9 +235,9 @@ void Window::set_menu_actions() {
boost::filesystem::path project_path = Dialog::new_folder(Notebook::get().get_current_folder());
if(project_path!="") {
auto project_name=project_path.filename().string();
for(size_t c=0;c<project_name.size();c++) {
if(project_name[c]==' ')
project_name[c]='_';
for(auto &chr: project_name) {
if(chr==' ')
chr='_';
}
auto cmakelists_path=project_path;
cmakelists_path/="CMakeLists.txt";
@ -267,9 +267,9 @@ void Window::set_menu_actions() {
boost::filesystem::path project_path = Dialog::new_folder(Notebook::get().get_current_folder());
if(project_path!="") {
auto project_name=project_path.filename().string();
for(size_t c=0;c<project_name.size();c++) {
if(project_name[c]==' ')
project_name[c]='_';
for(auto &chr: project_name) {
if(chr==' ')
chr='_';
}
auto cmakelists_path=project_path;
cmakelists_path/="CMakeLists.txt";

Loading…
Cancel
Save