File: ProtocolHandler.hpp

package info (click to toggle)
codelite 17.0.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 136,384 kB
  • sloc: cpp: 491,550; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 805; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (132 lines) | stat: -rw-r--r-- 5,470 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef PROTOCOLHANDLER_HPP
#define PROTOCOLHANDLER_HPP

#include "Channel.hpp"
#include "CompletionHelper.hpp"
#include "CxxCodeCompletion.hpp"
#include "JSON.h"
#include "ParseThread.hpp"
#include "Scanner.hpp"
#include "Settings.hpp"
#include "istorage.h"
#include "macros.h"

#include <algorithm>
#include <memory>
#include <wx/string.h>

struct CachedComment {
    wxString str;
    long line;
    long column;
    // line to comment map
    typedef std::unordered_map<long, wxString> Map_t;
};

struct ParsedFileInfo {
    wxStringSet_t included_files;
    wxStringSet_t using_namespace;
};

class ProtocolHandler
{
public:
    typedef void (ProtocolHandler::*CallbackFunc)(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);

private:
    CTagsdSettings m_settings;
    wxString m_root_folder;
    wxString m_settings_folder;
    wxStringMap_t m_filesOpened;

    // cached parsed comments file <-> comments
    std::unordered_map<wxString, CachedComment::Map_t> m_comments_cache;
    std::unordered_map<wxString, ParsedFileInfo> m_parsed_files_info;
    std::unordered_map<wxString, std::vector<wxString>> m_additional_scopes;
    wxArrayString m_search_paths;
    Scanner m_file_scanner;
    CxxCodeCompletion::ptr_t m_completer;
    ParseThread m_parse_thread;

private:
    JSONItem build_result(JSONItem& reply, size_t id, int result_kind);

    /**
     * @brief parse source file
     */
    static void parse_file(const wxFileName& filename, const CTagsdSettings& settings);
    /**
     * @brief parse buffer of a given file name
     */
    static void parse_buffer(const wxFileName& filename, const wxString& buffer, const CTagsdSettings& settings);
    /**
     * @brief parse list of files
     */
    static void parse_files(const std::vector<wxString>& files, const CTagsdSettings& settings);

    // helper method for parsing a chunk of files
    static void do_parse_chunk(ITagsStoragePtr db, const std::vector<wxString>& files, size_t chunk_id,
                               const CTagsdSettings& settings);

    bool ensure_file_content_exists(const wxString& filepath, Channel::ptr_t channel, size_t req_id);
    void update_comments_for_file(const wxString& filepath, const wxString& file_content);
    void update_comments_for_file(const wxString& filepath);
    const wxString& get_comment(const wxString& filepath, long line, const wxString& default_value) const;
    bool do_comments_exist_for_file(const wxString& filepath) const;
    std::vector<wxString> update_additional_scopes_for_file(const wxString& filepath);

    wxArrayString FilterNonWantedNamespaces(const wxArrayString& namespace_arr) const;
    void do_definition(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel, bool try_definition_first);
    size_t do_find_definition_tags(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel, bool try_definition_first,
                                   std::vector<TagEntryPtr>& tags, wxString* file_match);

    void build_search_path();
    void parse_file_for_includes_and_using_namespace(const wxString& filepath);
    void parse_buffer_for_includes_and_using_namespace(const wxString& filepath, const wxString& buffer);

    /**
     * @brief return list of files for parsing. The list is constructed using the `#include`
     * statements found in `files` and their children (recursively)
     */
    wxArrayString get_files_to_parse(const wxArrayString& files);
    /**
     * @brief return list of files included directly by `filepath`
     */
    wxArrayString get_first_level_includes(const wxString& filepath);

    size_t get_includes_recrusively(const wxString& filepath, wxStringSet_t* output);
    wxString minimize_buffer(const wxString& filepath, int line, int character, const wxString& src_string,
                             CompletionHelper::eTruncateStyle flag = CompletionHelper::TRUNCATE_EXACT_POS);

    /**
     * @brief return set of files that exist in `a` but not in `b`
     */
    wxStringSet_t setdiff(const wxStringSet_t& a, const wxStringSet_t& b);

public:
    ProtocolHandler();
    ~ProtocolHandler();

    void on_initialize(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_initialized(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_unsupported_message(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_did_open(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_did_change(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_completion(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_did_close(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_did_save(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_semantic_tokens(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_document_symbol(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_document_signature_help(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_definition(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_declaration(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_hover(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);
    void on_workspace_symbol(std::unique_ptr<JSON>&& msg, Channel::ptr_t channel);

    /**
     * @brief send a "window/logMessage" message to the client
     */
    void send_log_message(const wxString& message, int level, Channel::ptr_t channel);
};

#endif // PROTOCOLHANDLER_HPP