From df09dcbce7729fd0d430c79cf1f84e85f9d69ca0 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 15 Nov 2015 10:58:25 +0100 Subject: [PATCH] Source::Token cleanup in preparation for Find Usages. --- src/source.h | 9 +++------ src/source_clang.cc | 5 +++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/source.h b/src/source.h index ce0ccec..9de045a 100644 --- a/src/source.h +++ b/src/source.h @@ -16,14 +16,11 @@ namespace Source { class Token { public: Token(): type(-1) {} - Token(int type, const std::string &spelling, const std::string &usr): - type(type), spelling(spelling), usr(usr) {} + Token(Glib::RefPtr language, int type, const std::string &spelling, const std::string &usr): + language(language), type(type), spelling(spelling), usr(usr) {} operator bool() const {return (type>=0 && spelling.size()>0 && usr.size()>0);} - bool operator==(const Token &o) const {return (type==o.type && - spelling==o.spelling && - usr==o.usr);} - bool operator!=(const Token &o) const {return !(*this==o);} + Glib::RefPtr language; int type; std::string spelling; std::string usr; diff --git a/src/source_clang.cc b/src/source_clang.cc index bc35142..fdf1d9c 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -984,7 +984,7 @@ Source::ClangViewAutocomplete(file_path, project_path, language) { continue; auto referenced=cursor.get_referenced(); if(referenced) - return Token(static_cast(referenced.get_kind()), token.get_spelling(), referenced.get_usr()); + return Token(this->language, static_cast(referenced.get_kind()), token.get_spelling(), referenced.get_usr()); } } } @@ -994,7 +994,8 @@ Source::ClangViewAutocomplete(file_path, project_path, language) { rename_similar_tokens=[this](const Token &token, const std::string &text) { size_t number=0; - if(source_readable) { + if(source_readable && token.language && + (token.language->get_id()=="chdr" || token.language->get_id()=="cpphdr" || token.language->get_id()=="c" || token.language->get_id()=="cpp" || token.language->get_id()=="objc")) { auto offsets=clang_tokens->get_similar_token_offsets(static_cast(token.type), token.spelling, token.usr); std::vector, Glib::RefPtr > > marks; for(auto &offset: offsets) {