| 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 |
#pragma once |
| 32 |
|
| 33 |
#include "../gdscript_parser.h" |
| 34 |
#include "godot_lsp.h" |
| 35 |
|
| 36 |
#include "core/variant/variant.h" |
| 37 |
|
| 38 |
#ifndef LINE_NUMBER_TO_INDEX |
| 39 |
#define LINE_NUMBER_TO_INDEX(p_line) ((p_line) - 1) |
| 40 |
#endif |
| 41 |
#ifndef COLUMN_NUMBER_TO_INDEX |
| 42 |
#define COLUMN_NUMBER_TO_INDEX(p_column) ((p_column) - 1) |
| 43 |
#endif |
| 44 |
|
| 45 |
#ifndef SYMBOL_SEPARATOR |
| 46 |
#define SYMBOL_SEPARATOR "::" |
| 47 |
#endif |
| 48 |
|
| 49 |
#ifndef JOIN_SYMBOLS |
| 50 |
#define JOIN_SYMBOLS(p_path, name) ((p_path) + SYMBOL_SEPARATOR + (name)) |
| 51 |
#endif |
| 52 |
|
| 53 |
typedef HashMap<String, const LSP::DocumentSymbol *> ClassMembers; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
= 42 |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
struct GodotPosition { |
| 76 |
int line; |
| 77 |
int column; |
| 78 |
|
| 79 |
GodotPosition(int p_line, int p_column) : |
| 80 |
line(p_line), column(p_column) {} |
| 81 |
|
| 82 |
LSP::Position to_lsp(const Vector<String> &p_lines) const; |
| 83 |
static GodotPosition from_lsp(const LSP::Position p_pos, const Vector<String> &p_lines); |
| 84 |
|
| 85 |
bool operator==(const GodotPosition &p_other) const { |
| 86 |
return line == p_other.line && column == p_other.column; |
| 87 |
} |
| 88 |
|
| 89 |
String to_string() const { |
| 90 |
return vformat("(%d,%d)", line, column); |
| 91 |
} |
| 92 |
}; |
| 93 |
|
| 94 |
struct GodotRange { |
| 95 |
GodotPosition start; |
| 96 |
GodotPosition end; |
| 97 |
|
| 98 |
GodotRange(GodotPosition p_start, GodotPosition p_end) : |
| 99 |
start(p_start), end(p_end) {} |
| 100 |
|
| 101 |
LSP::Range to_lsp(const Vector<String> &p_lines) const; |
| 102 |
static GodotRange from_lsp(const LSP::Range &p_range, const Vector<String> &p_lines); |
| 103 |
|
| 104 |
bool operator==(const GodotRange &p_other) const { |
| 105 |
return start == p_other.start && end == p_other.end; |
| 106 |
} |
| 107 |
|
| 108 |
String to_string() const { |
| 109 |
return vformat("[%s:%s]", start.to_string(), end.to_string()); |
| 110 |
} |
| 111 |
}; |
| 112 |
|
| 113 |
class ExtendGDScriptParser : public GDScriptParser { |
| 114 |
String path; |
| 115 |
Vector<String> lines; |
| 116 |
|
| 117 |
LSP::DocumentSymbol class_symbol; |
| 118 |
Vector<LSP::Diagnostic> diagnostics; |
| 119 |
List<LSP::DocumentLink> document_links; |
| 120 |
ClassMembers members; |
| 121 |
HashMap<String, ClassMembers> inner_classes; |
| 122 |
|
| 123 |
LSP::Range range_of_node(const GDScriptParser::Node *p_node) const; |
| 124 |
|
| 125 |
void update_diagnostics(); |
| 126 |
|
| 127 |
void update_symbols(); |
| 128 |
void update_document_links(const String &p_code); |
| 129 |
void parse_class_symbol(const GDScriptParser::ClassNode *p_class, LSP::DocumentSymbol &r_symbol); |
| 130 |
void parse_function_symbol(const GDScriptParser::FunctionNode *p_func, LSP::DocumentSymbol &r_symbol); |
| 131 |
|
| 132 |
Dictionary dump_function_api(const GDScriptParser::FunctionNode *p_func) const; |
| 133 |
Dictionary dump_class_api(const GDScriptParser::ClassNode *p_class) const; |
| 134 |
|
| 135 |
const LSP::DocumentSymbol *search_symbol_defined_at_line(int p_line, const LSP::DocumentSymbol &p_parent, const String &p_symbol_name = "") const; |
| 136 |
|
| 137 |
Array member_completions; |
| 138 |
|
| 139 |
public: |
| 140 |
_FORCE_INLINE_ const String &get_path() const { return path; } |
| 141 |
_FORCE_INLINE_ const Vector<String> &get_lines() const { return lines; } |
| 142 |
_FORCE_INLINE_ const LSP::DocumentSymbol &get_symbols() const { return class_symbol; } |
| 143 |
_FORCE_INLINE_ const Vector<LSP::Diagnostic> &get_diagnostics() const { return diagnostics; } |
| 144 |
_FORCE_INLINE_ const ClassMembers &get_members() const { return members; } |
| 145 |
_FORCE_INLINE_ const HashMap<String, ClassMembers> &get_inner_classes() const { return inner_classes; } |
| 146 |
Error parse_result; |
| 147 |
|
| 148 |
Error get_left_function_call(const LSP::Position &p_position, LSP::Position &r_func_pos, int &r_arg_index) const; |
| 149 |
|
| 150 |
String get_text_for_completion(const LSP::Position &p_cursor) const; |
| 151 |
String get_text_for_lookup_symbol(const LSP::Position &p_cursor, const String &p_symbol = "", bool p_func_required = false) const; |
| 152 |
String get_identifier_under_position(const LSP::Position &p_position, LSP::Range &r_range) const; |
| 153 |
String get_uri() const; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
const LSP::DocumentSymbol *get_symbol_defined_at_line(int p_line, const String &p_symbol_name = "") const; |
| 164 |
const LSP::DocumentSymbol *get_member_symbol(const String &p_name, const String &p_subclass = "") const; |
| 165 |
const List<LSP::DocumentLink> &get_document_links() const; |
| 166 |
|
| 167 |
const Array &get_member_completions(); |
| 168 |
Dictionary generate_api() const; |
| 169 |
|
| 170 |
void parse(const String &p_code, const String &p_path); |
| 171 |
}; |