#ifndef JUCI_SOURCE_CLANG_H_ #define JUCI_SOURCE_CLANG_H_ #include #include #include #include #include #include "clangmm.h" #include "source.h" namespace Source { class ClangViewParse : public View { public: class TokenRange { public: TokenRange(std::pair offsets, int kind): offsets(offsets), kind(kind) {} std::pair offsets; int kind; }; ClangViewParse(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr language); ~ClangViewParse(); void configure(); void start_reparse(); bool reparse_needed=false; protected: void init_parse(); bool on_key_press_event(GdkEventKey* key); std::unique_ptr clang_tu; std::mutex parsing_mutex; std::unique_ptr clang_tokens; sigc::connection delayed_reparse_connection; std::shared_ptr parsing_in_progress; std::thread parse_thread; std::atomic parse_thread_stop; std::atomic parse_error; void show_diagnostic_tooltips(const Gdk::Rectangle &rectangle); void show_type_tooltips(const Gdk::Rectangle &rectangle); std::regex bracket_regex; std::regex no_bracket_statement_regex; std::regex no_bracket_no_para_statement_regex; std::set diagnostic_offsets; std::vector fix_its; private: std::map get_buffer_map() const; void update_syntax(); std::set last_syntax_tags; void update_diagnostics(); static clang::Index clang_index; std::vector get_compilation_commands(); Glib::Dispatcher parse_done; Glib::Dispatcher parse_start; Glib::Dispatcher parse_fail; std::map parse_thread_buffer_map; std::mutex parse_thread_buffer_map_mutex; std::atomic parse_thread_go; std::atomic parse_thread_mapped; }; class ClangViewAutocomplete : public ClangViewParse { public: class AutoCompleteData { public: explicit AutoCompleteData(const std::vector &chunks) : chunks(chunks) { } std::vector chunks; std::string brief_comments; }; ClangViewAutocomplete(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr language); void async_delete(); bool restart_parse(); protected: bool on_key_press_event(GdkEventKey* key); std::thread autocomplete_thread; private: void start_autocomplete(); void autocomplete(); std::unique_ptr completion_dialog; bool completion_dialog_shown=false; std::vector get_autocomplete_suggestions(int line_number, int column, std::map& buffer_map); Glib::Dispatcher autocomplete_done; sigc::connection autocomplete_done_connection; Glib::Dispatcher autocomplete_fail; sigc::connection autocomplete_fail_connection; bool autocomplete_starting=false; std::atomic autocomplete_cancel_starting; guint last_keyval=0; std::string prefix; std::mutex prefix_mutex; Glib::Dispatcher do_delete_object; Glib::Dispatcher do_restart_parse; std::thread delete_thread; std::thread restart_parse_thread; bool restart_parse_running=false; }; class ClangViewRefactor : public ClangViewAutocomplete { public: ClangViewRefactor(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr language); ~ClangViewRefactor(); private: std::list, Glib::RefPtr > > similar_token_marks; void tag_similar_tokens(const Token &token); Glib::RefPtr similar_tokens_tag; Token last_tagged_token; sigc::connection delayed_tag_similar_tokens_connection; std::unique_ptr selection_dialog; bool renaming=false; }; class ClangView : public ClangViewRefactor { public: ClangView(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr language); }; } #endif // JUCI_SOURCE_CLANG_H_