Browse Source

Slightly improved C++ include fixits

merge-requests/413/head
eidheim 4 years ago
parent
commit
ae669bfcdf
  1. 29
      src/source_clang.cpp

29
src/source_clang.cpp

@ -270,8 +270,8 @@ void Source::ClangViewParse::update_syntax() {
for(size_t c = 0; c < clang_tokens->size(); ++c) { for(size_t c = 0; c < clang_tokens->size(); ++c) {
auto &token = (*clang_tokens)[c]; auto &token = (*clang_tokens)[c];
auto &token_offsets = clang_tokens_offsets[c]; auto &token_offsets = clang_tokens_offsets[c];
//if(token.get_kind()==clangmm::Token::Kind::Token_Punctuation) // if(token.get_kind()==clangmm::Token::Kind::Token_Punctuation)
//ranges.emplace_back(token_offset, static_cast<int>(token.get_cursor().get_kind())); // ranges.emplace_back(token_offset, static_cast<int>(token.get_cursor().get_kind()));
auto token_kind = token.get_kind(); auto token_kind = token.get_kind();
if(token_kind == clangmm::Token::Kind::Keyword) if(token_kind == clangmm::Token::Kind::Keyword)
apply_tag(token_offsets, 702); apply_tag(token_offsets, 702);
@ -420,8 +420,9 @@ void Source::ClangViewParse::update_diagnostics() {
} }
} }
if(diagnostic.severity >= clangmm::Diagnostic::Severity::Error && if(diagnostic.severity >= clangmm::Diagnostic::Severity::Error &&
starts_with(diagnostic.spelling, "variable has incomplete type '")) { (starts_with(diagnostic.spelling, "variable has incomplete type '") ||
size_t start = 30; starts_with(diagnostic.spelling, "member access into incomplete type '"))) {
auto start = diagnostic.spelling.find('\'') + 1;
auto end = diagnostic.spelling.find('\'', start); auto end = diagnostic.spelling.find('\'', start);
if(end != std::string::npos) { if(end != std::string::npos) {
auto type = diagnostic.spelling.substr(start, end - start); auto type = diagnostic.spelling.substr(start, end - start);
@ -1110,9 +1111,9 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
row = text.substr(0, pos); row = text.substr(0, pos);
else else
row = text; row = text;
//erase existing variable or function before insert iter // Erase existing variable or function before insert iter
get_buffer()->erase(CompletionDialog::get()->start_mark->get_iter(), get_buffer()->get_insert()->get_iter()); get_buffer()->erase(CompletionDialog::get()->start_mark->get_iter(), get_buffer()->get_insert()->get_iter());
//do not insert template argument or function parameters if they already exist // Do not insert template argument or function parameters if they already exist
auto iter = get_buffer()->get_insert()->get_iter(); auto iter = get_buffer()->get_insert()->get_iter();
if(*iter == '<' || *iter == '(') { if(*iter == '<' || *iter == '(') {
auto bracket_pos = row.find(*iter); auto bracket_pos = row.find(*iter);
@ -1120,12 +1121,12 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
row = row.substr(0, bracket_pos); row = row.substr(0, bracket_pos);
} }
} }
//Fixes for the most commonly used stream manipulators // Fixes for the most commonly used stream manipulators
auto manipulators_map = autocomplete_manipulators_map(); auto manipulators_map = autocomplete_manipulators_map();
auto it = manipulators_map.find(row); auto it = manipulators_map.find(row);
if(it != manipulators_map.end()) if(it != manipulators_map.end())
row = it->second; row = it->second;
//Do not insert template argument, function parameters or ':' unless hide_window is true // Do not insert template argument, function parameters or ':' unless hide_window is true
if(!hide_window) { if(!hide_window) {
for(size_t c = 0; c < row.size(); ++c) { for(size_t c = 0; c < row.size(); ++c) {
if(row[c] == '<' || row[c] == '(' || row[c] == ':') { if(row[c] == '<' || row[c] == '(' || row[c] == ':') {
@ -1139,7 +1140,7 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
row.pop_back(); row.pop_back();
get_buffer()->insert(CompletionDialog::get()->start_mark->get_iter(), row); get_buffer()->insert(CompletionDialog::get()->start_mark->get_iter(), row);
//if selection is finalized, select text inside template arguments or function parameters // If selection is finalized, select text inside template arguments or function parameters
if(hide_window) { if(hide_window) {
size_t start_pos = std::string::npos; size_t start_pos = std::string::npos;
size_t end_pos = std::string::npos; size_t end_pos = std::string::npos;
@ -1185,7 +1186,7 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
get_buffer()->select_range(get_buffer()->get_iter_at_offset(start_offset), get_buffer()->get_iter_at_offset(end_offset)); get_buffer()->select_range(get_buffer()->get_iter_at_offset(start_offset), get_buffer()->get_iter_at_offset(end_offset));
} }
else { else {
//new autocomplete after for instance when selecting "std::" // New autocomplete after for instance when selecting "std::"
auto iter = get_buffer()->get_insert()->get_iter(); auto iter = get_buffer()->get_insert()->get_iter();
if(iter.backward_char() && *iter == ':') { if(iter.backward_char() && *iter == ':') {
autocomplete.run(); autocomplete.run();
@ -1206,12 +1207,12 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
} }
const std::unordered_map<std::string, std::string> &Source::ClangViewAutocomplete::autocomplete_manipulators_map() { const std::unordered_map<std::string, std::string> &Source::ClangViewAutocomplete::autocomplete_manipulators_map() {
//TODO: feel free to add more // TODO: feel free to add more
static std::unordered_map<std::string, std::string> map = { static std::unordered_map<std::string, std::string> map = {
{"endl(basic_ostream<_CharT, _Traits> &__os)", "endl"}, {"endl(basic_ostream<_CharT, _Traits> &__os)", "endl"},
{"flush(basic_ostream<_CharT, _Traits> &__os)", "flush"}, {"flush(basic_ostream<_CharT, _Traits> &__os)", "flush"},
{"hex(std::ios_base &__str)", "hex"}, //clang++ headers {"hex(std::ios_base &__str)", "hex"}, // clang++ headers
{"hex(std::ios_base &__base)", "hex"}, //g++ headers {"hex(std::ios_base &__base)", "hex"}, // g++ headers
{"dec(std::ios_base &__str)", "dec"}, {"dec(std::ios_base &__str)", "dec"},
{"dec(std::ios_base &__base)", "dec"}}; {"dec(std::ios_base &__base)", "dec"}};
return map; return map;
@ -1694,7 +1695,7 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file
return usages; return usages;
auto embolden_token = [](std::string &line, unsigned token_start_pos, unsigned token_end_pos) { auto embolden_token = [](std::string &line, unsigned token_start_pos, unsigned token_end_pos) {
//markup token as bold // Markup token as bold
size_t pos = 0; size_t pos = 0;
while((pos = line.find('&', pos)) != std::string::npos) { while((pos = line.find('&', pos)) != std::string::npos) {
size_t pos2 = line.find(';', pos + 2); size_t pos2 = line.find(';', pos + 2);

Loading…
Cancel
Save