1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Style: Convert namespaces to PascalCase

This commit is contained in:
Thaddeus Crews
2025-03-12 12:47:08 -05:00
parent 0595bb8a42
commit 1cb3cfaa8e
40 changed files with 509 additions and 509 deletions

View File

@@ -44,8 +44,8 @@ int get_indent_size() {
}
}
lsp::Position GodotPosition::to_lsp(const Vector<String> &p_lines) const {
lsp::Position res;
LSP::Position GodotPosition::to_lsp(const Vector<String> &p_lines) const {
LSP::Position res;
// Special case: `line = 0` -> root class (range covers everything).
if (line <= 0) {
@@ -89,7 +89,7 @@ lsp::Position GodotPosition::to_lsp(const Vector<String> &p_lines) const {
return res;
}
GodotPosition GodotPosition::from_lsp(const lsp::Position p_pos, const Vector<String> &p_lines) {
GodotPosition GodotPosition::from_lsp(const LSP::Position p_pos, const Vector<String> &p_lines) {
GodotPosition res(p_pos.line + 1, p_pos.character + 1);
// Line outside of actual text is valid (-> pos/cursor at end of text).
@@ -113,14 +113,14 @@ GodotPosition GodotPosition::from_lsp(const lsp::Position p_pos, const Vector<St
return res;
}
lsp::Range GodotRange::to_lsp(const Vector<String> &p_lines) const {
lsp::Range res;
LSP::Range GodotRange::to_lsp(const Vector<String> &p_lines) const {
LSP::Range res;
res.start = start.to_lsp(p_lines);
res.end = end.to_lsp(p_lines);
return res;
}
GodotRange GodotRange::from_lsp(const lsp::Range &p_range, const Vector<String> &p_lines) {
GodotRange GodotRange::from_lsp(const LSP::Range &p_range, const Vector<String> &p_lines) {
GodotPosition start = GodotPosition::from_lsp(p_range.start, p_lines);
GodotPosition end = GodotPosition::from_lsp(p_range.end, p_lines);
return GodotRange(start, end);
@@ -131,13 +131,13 @@ void ExtendGDScriptParser::update_diagnostics() {
const List<ParserError> &parser_errors = get_errors();
for (const ParserError &error : parser_errors) {
lsp::Diagnostic diagnostic;
diagnostic.severity = lsp::DiagnosticSeverity::Error;
LSP::Diagnostic diagnostic;
diagnostic.severity = LSP::DiagnosticSeverity::Error;
diagnostic.message = error.message;
diagnostic.source = "gdscript";
diagnostic.code = -1;
lsp::Range range;
lsp::Position pos;
LSP::Range range;
LSP::Position pos;
const PackedStringArray line_array = get_lines();
int line = CLAMP(LINE_NUMBER_TO_INDEX(error.line), 0, line_array.size() - 1);
const String &line_text = line_array[line];
@@ -152,13 +152,13 @@ void ExtendGDScriptParser::update_diagnostics() {
const List<GDScriptWarning> &parser_warnings = get_warnings();
for (const GDScriptWarning &warning : parser_warnings) {
lsp::Diagnostic diagnostic;
diagnostic.severity = lsp::DiagnosticSeverity::Warning;
LSP::Diagnostic diagnostic;
diagnostic.severity = LSP::DiagnosticSeverity::Warning;
diagnostic.message = "(" + warning.get_name() + "): " + warning.get_message();
diagnostic.source = "gdscript";
diagnostic.code = warning.code;
lsp::Range range;
lsp::Position pos;
LSP::Range range;
LSP::Position pos;
int line = LINE_NUMBER_TO_INDEX(warning.start_line);
const String &line_text = get_lines()[line];
pos.line = line;
@@ -178,14 +178,14 @@ void ExtendGDScriptParser::update_symbols() {
parse_class_symbol(gdclass, class_symbol);
for (int i = 0; i < class_symbol.children.size(); i++) {
const lsp::DocumentSymbol &symbol = class_symbol.children[i];
const LSP::DocumentSymbol &symbol = class_symbol.children[i];
members.insert(symbol.name, &symbol);
// Cache level one inner classes.
if (symbol.kind == lsp::SymbolKind::Class) {
if (symbol.kind == LSP::SymbolKind::Class) {
ClassMembers inner_class;
for (int j = 0; j < symbol.children.size(); j++) {
const lsp::DocumentSymbol &s = symbol.children[j];
const LSP::DocumentSymbol &s = symbol.children[j];
inner_class.insert(s.name, &s);
}
inner_classes.insert(symbol.name, inner_class);
@@ -215,7 +215,7 @@ void ExtendGDScriptParser::update_document_links(const String &p_code) {
}
if (exists) {
String value = const_val;
lsp::DocumentLink link;
LSP::DocumentLink link;
link.target = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_uri(scr_path);
link.range = GodotRange(GodotPosition(token.start_line, token.start_column), GodotPosition(token.end_line, token.end_column)).to_lsp(lines);
document_links.push_back(link);
@@ -225,13 +225,13 @@ void ExtendGDScriptParser::update_document_links(const String &p_code) {
}
}
lsp::Range ExtendGDScriptParser::range_of_node(const GDScriptParser::Node *p_node) const {
LSP::Range ExtendGDScriptParser::range_of_node(const GDScriptParser::Node *p_node) const {
GodotPosition start(p_node->start_line, p_node->start_column);
GodotPosition end(p_node->end_line, p_node->end_column);
return GodotRange(start, end).to_lsp(lines);
}
void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p_class, lsp::DocumentSymbol &r_symbol) {
void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p_class, LSP::DocumentSymbol &r_symbol) {
const String uri = get_uri();
r_symbol.uri = uri;
@@ -241,7 +241,7 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
if (r_symbol.name.is_empty()) {
r_symbol.name = path.get_file();
}
r_symbol.kind = lsp::SymbolKind::Class;
r_symbol.kind = LSP::SymbolKind::Class;
r_symbol.deprecated = false;
r_symbol.range = range_of_node(p_class);
if (p_class->identifier) {
@@ -276,9 +276,9 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
switch (m.type) {
case ClassNode::Member::VARIABLE: {
lsp::DocumentSymbol symbol;
LSP::DocumentSymbol symbol;
symbol.name = m.variable->identifier->name;
symbol.kind = m.variable->property == VariableNode::PROP_NONE ? lsp::SymbolKind::Variable : lsp::SymbolKind::Property;
symbol.kind = m.variable->property == VariableNode::PROP_NONE ? LSP::SymbolKind::Variable : LSP::SymbolKind::Property;
symbol.deprecated = false;
symbol.range = range_of_node(m.variable);
symbol.selectionRange = range_of_node(m.variable->identifier);
@@ -299,20 +299,20 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
if (m.variable->initializer && m.variable->initializer->type == GDScriptParser::Node::LAMBDA) {
GDScriptParser::LambdaNode *lambda_node = (GDScriptParser::LambdaNode *)m.variable->initializer;
lsp::DocumentSymbol lambda;
LSP::DocumentSymbol lambda;
parse_function_symbol(lambda_node->function, lambda);
// Merge lambda into current variable.
symbol.children.append_array(lambda.children);
}
if (m.variable->getter && m.variable->getter->type == GDScriptParser::Node::FUNCTION) {
lsp::DocumentSymbol get_symbol;
LSP::DocumentSymbol get_symbol;
parse_function_symbol(m.variable->getter, get_symbol);
get_symbol.local = true;
symbol.children.push_back(get_symbol);
}
if (m.variable->setter && m.variable->setter->type == GDScriptParser::Node::FUNCTION) {
lsp::DocumentSymbol set_symbol;
LSP::DocumentSymbol set_symbol;
parse_function_symbol(m.variable->setter, set_symbol);
set_symbol.local = true;
symbol.children.push_back(set_symbol);
@@ -321,10 +321,10 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
r_symbol.children.push_back(symbol);
} break;
case ClassNode::Member::CONSTANT: {
lsp::DocumentSymbol symbol;
LSP::DocumentSymbol symbol;
symbol.name = m.constant->identifier->name;
symbol.kind = lsp::SymbolKind::Constant;
symbol.kind = LSP::SymbolKind::Constant;
symbol.deprecated = false;
symbol.range = range_of_node(m.constant);
symbol.selectionRange = range_of_node(m.constant->identifier);
@@ -361,9 +361,9 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
r_symbol.children.push_back(symbol);
} break;
case ClassNode::Member::SIGNAL: {
lsp::DocumentSymbol symbol;
LSP::DocumentSymbol symbol;
symbol.name = m.signal->identifier->name;
symbol.kind = lsp::SymbolKind::Event;
symbol.kind = LSP::SymbolKind::Event;
symbol.deprecated = false;
symbol.range = range_of_node(m.signal);
symbol.selectionRange = range_of_node(m.signal->identifier);
@@ -380,9 +380,9 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
symbol.detail += ")";
for (GDScriptParser::ParameterNode *param : m.signal->parameters) {
lsp::DocumentSymbol param_symbol;
LSP::DocumentSymbol param_symbol;
param_symbol.name = param->identifier->name;
param_symbol.kind = lsp::SymbolKind::Variable;
param_symbol.kind = LSP::SymbolKind::Variable;
param_symbol.deprecated = false;
param_symbol.local = true;
param_symbol.range = range_of_node(param);
@@ -398,10 +398,10 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
r_symbol.children.push_back(symbol);
} break;
case ClassNode::Member::ENUM_VALUE: {
lsp::DocumentSymbol symbol;
LSP::DocumentSymbol symbol;
symbol.name = m.enum_value.identifier->name;
symbol.kind = lsp::SymbolKind::EnumMember;
symbol.kind = LSP::SymbolKind::EnumMember;
symbol.deprecated = false;
symbol.range.start = GodotPosition(m.enum_value.line, m.enum_value.leftmost_column).to_lsp(lines);
symbol.range.end = GodotPosition(m.enum_value.line, m.enum_value.rightmost_column).to_lsp(lines);
@@ -415,9 +415,9 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
r_symbol.children.push_back(symbol);
} break;
case ClassNode::Member::ENUM: {
lsp::DocumentSymbol symbol;
LSP::DocumentSymbol symbol;
symbol.name = m.m_enum->identifier->name;
symbol.kind = lsp::SymbolKind::Enum;
symbol.kind = LSP::SymbolKind::Enum;
symbol.range = range_of_node(m.m_enum);
symbol.selectionRange = range_of_node(m.m_enum->identifier);
symbol.documentation = m.m_enum->doc_data.description;
@@ -434,10 +434,10 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
symbol.detail += "}";
for (GDScriptParser::EnumNode::Value value : m.m_enum->values) {
lsp::DocumentSymbol child;
LSP::DocumentSymbol child;
child.name = value.identifier->name;
child.kind = lsp::SymbolKind::EnumMember;
child.kind = LSP::SymbolKind::EnumMember;
child.deprecated = false;
child.range.start = GodotPosition(value.line, value.leftmost_column).to_lsp(lines);
child.range.end = GodotPosition(value.line, value.rightmost_column).to_lsp(lines);
@@ -454,12 +454,12 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
r_symbol.children.push_back(symbol);
} break;
case ClassNode::Member::FUNCTION: {
lsp::DocumentSymbol symbol;
LSP::DocumentSymbol symbol;
parse_function_symbol(m.function, symbol);
r_symbol.children.push_back(symbol);
} break;
case ClassNode::Member::CLASS: {
lsp::DocumentSymbol symbol;
LSP::DocumentSymbol symbol;
parse_class_symbol(m.m_class, symbol);
r_symbol.children.push_back(symbol);
} break;
@@ -471,13 +471,13 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
}
}
void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionNode *p_func, lsp::DocumentSymbol &r_symbol) {
void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionNode *p_func, LSP::DocumentSymbol &r_symbol) {
const String uri = get_uri();
bool is_named = p_func->identifier != nullptr;
r_symbol.name = is_named ? p_func->identifier->name : "";
r_symbol.kind = (p_func->is_static || p_func->source_lambda != nullptr) ? lsp::SymbolKind::Function : lsp::SymbolKind::Method;
r_symbol.kind = (p_func->is_static || p_func->source_lambda != nullptr) ? LSP::SymbolKind::Function : LSP::SymbolKind::Method;
r_symbol.detail = "func";
if (is_named) {
r_symbol.detail += " " + String(p_func->identifier->name);
@@ -570,9 +570,9 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN
const GDScriptParser::SuiteNode *suite_node = N->get();
for (int i = 0; i < suite_node->locals.size(); i++) {
const SuiteNode::Local &local = suite_node->locals[i];
lsp::DocumentSymbol symbol;
LSP::DocumentSymbol symbol;
symbol.name = local.name;
symbol.kind = local.type == SuiteNode::Local::CONSTANT ? lsp::SymbolKind::Constant : lsp::SymbolKind::Variable;
symbol.kind = local.type == SuiteNode::Local::CONSTANT ? LSP::SymbolKind::Constant : LSP::SymbolKind::Variable;
switch (local.type) {
case SuiteNode::Local::CONSTANT:
symbol.range = range_of_node(local.constant);
@@ -583,7 +583,7 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN
symbol.selectionRange = range_of_node(local.variable->identifier);
if (local.variable->initializer && local.variable->initializer->type == GDScriptParser::Node::LAMBDA) {
GDScriptParser::LambdaNode *lambda_node = (GDScriptParser::LambdaNode *)local.variable->initializer;
lsp::DocumentSymbol lambda;
LSP::DocumentSymbol lambda;
parse_function_symbol(lambda_node->function, lambda);
// Merge lambda into current variable.
// -> Only interested in new variables, not lambda itself.
@@ -629,7 +629,7 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN
}
}
String ExtendGDScriptParser::get_text_for_completion(const lsp::Position &p_cursor) const {
String ExtendGDScriptParser::get_text_for_completion(const LSP::Position &p_cursor) const {
String longthing;
int len = lines.size();
for (int i = 0; i < len; i++) {
@@ -649,7 +649,7 @@ String ExtendGDScriptParser::get_text_for_completion(const lsp::Position &p_curs
return longthing;
}
String ExtendGDScriptParser::get_text_for_lookup_symbol(const lsp::Position &p_cursor, const String &p_symbol, bool p_func_required) const {
String ExtendGDScriptParser::get_text_for_lookup_symbol(const LSP::Position &p_cursor, const String &p_symbol, bool p_func_required) const {
String longthing;
int len = lines.size();
for (int i = 0; i < len; i++) {
@@ -687,7 +687,7 @@ String ExtendGDScriptParser::get_text_for_lookup_symbol(const lsp::Position &p_c
return longthing;
}
String ExtendGDScriptParser::get_identifier_under_position(const lsp::Position &p_position, lsp::Range &r_range) const {
String ExtendGDScriptParser::get_identifier_under_position(const LSP::Position &p_position, LSP::Range &r_range) const {
ERR_FAIL_INDEX_V(p_position.line, lines.size(), "");
String line = lines[p_position.line];
if (line.is_empty()) {
@@ -709,7 +709,7 @@ String ExtendGDScriptParser::get_identifier_under_position(const lsp::Position &
// -> Move position to previous character if:
// * Position not on valid identifier char.
// * Prev position is valid identifier char.
lsp::Position pos = p_position;
LSP::Position pos = p_position;
if (
pos.character >= line.length() // Cursor at end of line.
|| (!is_ascii_identifier_char(line[pos.character]) // Not on valid identifier char.
@@ -753,8 +753,8 @@ String ExtendGDScriptParser::get_uri() const {
return GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_uri(path);
}
const lsp::DocumentSymbol *ExtendGDScriptParser::search_symbol_defined_at_line(int p_line, const lsp::DocumentSymbol &p_parent, const String &p_symbol_name) const {
const lsp::DocumentSymbol *ret = nullptr;
const LSP::DocumentSymbol *ExtendGDScriptParser::search_symbol_defined_at_line(int p_line, const LSP::DocumentSymbol &p_parent, const String &p_symbol_name) const {
const LSP::DocumentSymbol *ret = nullptr;
if (p_line < p_parent.range.start.line) {
return ret;
} else if (p_parent.range.start.line == p_line && (p_symbol_name.is_empty() || p_parent.name == p_symbol_name)) {
@@ -770,7 +770,7 @@ const lsp::DocumentSymbol *ExtendGDScriptParser::search_symbol_defined_at_line(i
return ret;
}
Error ExtendGDScriptParser::get_left_function_call(const lsp::Position &p_position, lsp::Position &r_func_pos, int &r_arg_index) const {
Error ExtendGDScriptParser::get_left_function_call(const LSP::Position &p_position, LSP::Position &r_func_pos, int &r_arg_index) const {
ERR_FAIL_INDEX_V(p_position.line, lines.size(), ERR_INVALID_PARAMETER);
int bracket_stack = 0;
@@ -814,22 +814,22 @@ Error ExtendGDScriptParser::get_left_function_call(const lsp::Position &p_positi
return ERR_METHOD_NOT_FOUND;
}
const lsp::DocumentSymbol *ExtendGDScriptParser::get_symbol_defined_at_line(int p_line, const String &p_symbol_name) const {
const LSP::DocumentSymbol *ExtendGDScriptParser::get_symbol_defined_at_line(int p_line, const String &p_symbol_name) const {
if (p_line <= 0) {
return &class_symbol;
}
return search_symbol_defined_at_line(p_line, class_symbol, p_symbol_name);
}
const lsp::DocumentSymbol *ExtendGDScriptParser::get_member_symbol(const String &p_name, const String &p_subclass) const {
const LSP::DocumentSymbol *ExtendGDScriptParser::get_member_symbol(const String &p_name, const String &p_subclass) const {
if (p_subclass.is_empty()) {
const lsp::DocumentSymbol *const *ptr = members.getptr(p_name);
const LSP::DocumentSymbol *const *ptr = members.getptr(p_name);
if (ptr) {
return *ptr;
}
} else {
if (const ClassMembers *_class = inner_classes.getptr(p_subclass)) {
const lsp::DocumentSymbol *const *ptr = _class->getptr(p_name);
const LSP::DocumentSymbol *const *ptr = _class->getptr(p_name);
if (ptr) {
return *ptr;
}
@@ -839,15 +839,15 @@ const lsp::DocumentSymbol *ExtendGDScriptParser::get_member_symbol(const String
return nullptr;
}
const List<lsp::DocumentLink> &ExtendGDScriptParser::get_document_links() const {
const List<LSP::DocumentLink> &ExtendGDScriptParser::get_document_links() const {
return document_links;
}
const Array &ExtendGDScriptParser::get_member_completions() {
if (member_completions.is_empty()) {
for (const KeyValue<String, const lsp::DocumentSymbol *> &E : members) {
const lsp::DocumentSymbol *symbol = E.value;
lsp::CompletionItem item = symbol->make_completion_item();
for (const KeyValue<String, const LSP::DocumentSymbol *> &E : members) {
const LSP::DocumentSymbol *symbol = E.value;
LSP::CompletionItem item = symbol->make_completion_item();
item.data = JOIN_SYMBOLS(path, E.key);
member_completions.push_back(item.to_json());
}
@@ -855,9 +855,9 @@ const Array &ExtendGDScriptParser::get_member_completions() {
for (const KeyValue<String, ClassMembers> &E : inner_classes) {
const ClassMembers *inner_class = &E.value;
for (const KeyValue<String, const lsp::DocumentSymbol *> &F : *inner_class) {
const lsp::DocumentSymbol *symbol = F.value;
lsp::CompletionItem item = symbol->make_completion_item();
for (const KeyValue<String, const LSP::DocumentSymbol *> &F : *inner_class) {
const LSP::DocumentSymbol *symbol = F.value;
LSP::CompletionItem item = symbol->make_completion_item();
item.data = JOIN_SYMBOLS(path, JOIN_SYMBOLS(E.key, F.key));
member_completions.push_back(item.to_json());
}
@@ -883,7 +883,7 @@ Dictionary ExtendGDScriptParser::dump_function_api(const GDScriptParser::Functio
}
parameters.push_back(arg);
}
if (const lsp::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(p_func->start_line))) {
if (const LSP::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(p_func->start_line))) {
func["signature"] = symbol->detail;
func["description"] = symbol->documentation;
}
@@ -906,7 +906,7 @@ Dictionary ExtendGDScriptParser::dump_class_api(const GDScriptParser::ClassNode
class_api["extends_file"] = String(p_class->extends_path);
class_api["icon"] = String(p_class->icon_path);
if (const lsp::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(p_class->start_line))) {
if (const LSP::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(p_class->start_line))) {
class_api["signature"] = symbol->detail;
class_api["description"] = symbol->documentation;
}
@@ -929,7 +929,7 @@ Dictionary ExtendGDScriptParser::dump_class_api(const GDScriptParser::ClassNode
api["name"] = m.constant->identifier->name;
api["value"] = m.constant->initializer->reduced_value;
api["data_type"] = m.constant->get_datatype().to_string();
if (const lsp::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m.constant->start_line))) {
if (const LSP::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m.constant->start_line))) {
api["signature"] = symbol->detail;
api["description"] = symbol->documentation;
}
@@ -940,7 +940,7 @@ Dictionary ExtendGDScriptParser::dump_class_api(const GDScriptParser::ClassNode
api["name"] = m.enum_value.identifier->name;
api["value"] = m.enum_value.value;
api["data_type"] = m.get_datatype().to_string();
if (const lsp::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m.enum_value.line))) {
if (const LSP::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m.enum_value.line))) {
api["signature"] = symbol->detail;
api["description"] = symbol->documentation;
}
@@ -956,7 +956,7 @@ Dictionary ExtendGDScriptParser::dump_class_api(const GDScriptParser::ClassNode
api["name"] = m.m_enum->identifier->name;
api["value"] = enum_dict;
api["data_type"] = m.get_datatype().to_string();
if (const lsp::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m.m_enum->start_line))) {
if (const LSP::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m.m_enum->start_line))) {
api["signature"] = symbol->detail;
api["description"] = symbol->documentation;
}
@@ -970,7 +970,7 @@ Dictionary ExtendGDScriptParser::dump_class_api(const GDScriptParser::ClassNode
api["setter"] = m.variable->setter ? ("@" + String(m.variable->identifier->name) + "_setter") : (m.variable->setter_pointer != nullptr ? String(m.variable->setter_pointer->name) : String());
api["getter"] = m.variable->getter ? ("@" + String(m.variable->identifier->name) + "_getter") : (m.variable->getter_pointer != nullptr ? String(m.variable->getter_pointer->name) : String());
api["export"] = m.variable->exported;
if (const lsp::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m.variable->start_line))) {
if (const LSP::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m.variable->start_line))) {
api["signature"] = symbol->detail;
api["description"] = symbol->documentation;
}
@@ -984,7 +984,7 @@ Dictionary ExtendGDScriptParser::dump_class_api(const GDScriptParser::ClassNode
pars.append(String(m.signal->parameters[j]->identifier->name));
}
api["arguments"] = pars;
if (const lsp::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m.signal->start_line))) {
if (const LSP::DocumentSymbol *symbol = get_symbol_defined_at_line(LINE_NUMBER_TO_INDEX(m.signal->start_line))) {
api["signature"] = symbol->detail;
api["description"] = symbol->documentation;
}

View File

@@ -50,12 +50,12 @@
#define JOIN_SYMBOLS(p_path, name) ((p_path) + SYMBOL_SEPARATOR + (name))
#endif
typedef HashMap<String, const lsp::DocumentSymbol *> ClassMembers;
typedef HashMap<String, const LSP::DocumentSymbol *> ClassMembers;
/**
* Represents a Position as used by GDScript Parser. Used for conversion to and from `lsp::Position`.
* Represents a Position as used by GDScript Parser. Used for conversion to and from `LSP::Position`.
*
* Difference to `lsp::Position`:
* Difference to `LSP::Position`:
* * Line & Char/column: 1-based
* * LSP: both 0-based
* * Tabs are expanded to columns using tab size (`text_editor/behavior/indent/size`).
@@ -79,8 +79,8 @@ struct GodotPosition {
GodotPosition(int p_line, int p_column) :
line(p_line), column(p_column) {}
lsp::Position to_lsp(const Vector<String> &p_lines) const;
static GodotPosition from_lsp(const lsp::Position p_pos, const Vector<String> &p_lines);
LSP::Position to_lsp(const Vector<String> &p_lines) const;
static GodotPosition from_lsp(const LSP::Position p_pos, const Vector<String> &p_lines);
bool operator==(const GodotPosition &p_other) const {
return line == p_other.line && column == p_other.column;
@@ -98,8 +98,8 @@ struct GodotRange {
GodotRange(GodotPosition p_start, GodotPosition p_end) :
start(p_start), end(p_end) {}
lsp::Range to_lsp(const Vector<String> &p_lines) const;
static GodotRange from_lsp(const lsp::Range &p_range, const Vector<String> &p_lines);
LSP::Range to_lsp(const Vector<String> &p_lines) const;
static GodotRange from_lsp(const LSP::Range &p_range, const Vector<String> &p_lines);
bool operator==(const GodotRange &p_other) const {
return start == p_other.start && end == p_other.end;
@@ -114,41 +114,41 @@ class ExtendGDScriptParser : public GDScriptParser {
String path;
Vector<String> lines;
lsp::DocumentSymbol class_symbol;
Vector<lsp::Diagnostic> diagnostics;
List<lsp::DocumentLink> document_links;
LSP::DocumentSymbol class_symbol;
Vector<LSP::Diagnostic> diagnostics;
List<LSP::DocumentLink> document_links;
ClassMembers members;
HashMap<String, ClassMembers> inner_classes;
lsp::Range range_of_node(const GDScriptParser::Node *p_node) const;
LSP::Range range_of_node(const GDScriptParser::Node *p_node) const;
void update_diagnostics();
void update_symbols();
void update_document_links(const String &p_code);
void parse_class_symbol(const GDScriptParser::ClassNode *p_class, lsp::DocumentSymbol &r_symbol);
void parse_function_symbol(const GDScriptParser::FunctionNode *p_func, lsp::DocumentSymbol &r_symbol);
void parse_class_symbol(const GDScriptParser::ClassNode *p_class, LSP::DocumentSymbol &r_symbol);
void parse_function_symbol(const GDScriptParser::FunctionNode *p_func, LSP::DocumentSymbol &r_symbol);
Dictionary dump_function_api(const GDScriptParser::FunctionNode *p_func) const;
Dictionary dump_class_api(const GDScriptParser::ClassNode *p_class) const;
const lsp::DocumentSymbol *search_symbol_defined_at_line(int p_line, const lsp::DocumentSymbol &p_parent, const String &p_symbol_name = "") const;
const LSP::DocumentSymbol *search_symbol_defined_at_line(int p_line, const LSP::DocumentSymbol &p_parent, const String &p_symbol_name = "") const;
Array member_completions;
public:
_FORCE_INLINE_ const String &get_path() const { return path; }
_FORCE_INLINE_ const Vector<String> &get_lines() const { return lines; }
_FORCE_INLINE_ const lsp::DocumentSymbol &get_symbols() const { return class_symbol; }
_FORCE_INLINE_ const Vector<lsp::Diagnostic> &get_diagnostics() const { return diagnostics; }
_FORCE_INLINE_ const LSP::DocumentSymbol &get_symbols() const { return class_symbol; }
_FORCE_INLINE_ const Vector<LSP::Diagnostic> &get_diagnostics() const { return diagnostics; }
_FORCE_INLINE_ const ClassMembers &get_members() const { return members; }
_FORCE_INLINE_ const HashMap<String, ClassMembers> &get_inner_classes() const { return inner_classes; }
Error get_left_function_call(const lsp::Position &p_position, lsp::Position &r_func_pos, int &r_arg_index) const;
Error get_left_function_call(const LSP::Position &p_position, LSP::Position &r_func_pos, int &r_arg_index) const;
String get_text_for_completion(const lsp::Position &p_cursor) const;
String get_text_for_lookup_symbol(const lsp::Position &p_cursor, const String &p_symbol = "", bool p_func_required = false) const;
String get_identifier_under_position(const lsp::Position &p_position, lsp::Range &r_range) const;
String get_text_for_completion(const LSP::Position &p_cursor) const;
String get_text_for_lookup_symbol(const LSP::Position &p_cursor, const String &p_symbol = "", bool p_func_required = false) const;
String get_identifier_under_position(const LSP::Position &p_position, LSP::Range &r_range) const;
String get_uri() const;
/**
@@ -159,9 +159,9 @@ public:
* -> Without `p_symbol_name`: returns `handle_arg`. Even if parameter (`arg`) is wanted.
* With `p_symbol_name`: symbol name MUST match `p_symbol_name`: returns `arg`.
*/
const lsp::DocumentSymbol *get_symbol_defined_at_line(int p_line, const String &p_symbol_name = "") const;
const lsp::DocumentSymbol *get_member_symbol(const String &p_name, const String &p_subclass = "") const;
const List<lsp::DocumentLink> &get_document_links() const;
const LSP::DocumentSymbol *get_symbol_defined_at_line(int p_line, const String &p_symbol_name = "") const;
const LSP::DocumentSymbol *get_member_symbol(const String &p_name, const String &p_subclass = "") const;
const List<LSP::DocumentLink> &get_document_links() const;
const Array &get_member_completions();
Dictionary generate_api() const;

View File

@@ -171,7 +171,7 @@ void GDScriptLanguageProtocol::_bind_methods() {
}
Dictionary GDScriptLanguageProtocol::initialize(const Dictionary &p_params) {
lsp::InitializeResult ret;
LSP::InitializeResult ret;
String root_uri = p_params["rootUri"];
String root = p_params["rootPath"];
@@ -213,11 +213,11 @@ Dictionary GDScriptLanguageProtocol::initialize(const Dictionary &p_params) {
}
void GDScriptLanguageProtocol::initialized(const Variant &p_params) {
lsp::GodotCapabilities capabilities;
LSP::GodotCapabilities capabilities;
DocTools *doc = EditorHelp::get_doc_data();
for (const KeyValue<String, DocData::ClassDoc> &E : doc->class_list) {
lsp::GodotNativeClassInfo gdclass;
LSP::GodotNativeClassInfo gdclass;
gdclass.name = E.value.name;
gdclass.class_doc = &(E.value);
if (ClassDB::ClassInfo *ptr = ClassDB::classes.getptr(StringName(E.value.name))) {

View File

@@ -63,7 +63,7 @@ void GDScriptTextDocument::_bind_methods() {
}
void GDScriptTextDocument::didOpen(const Variant &p_param) {
lsp::TextDocumentItem doc = load_document_item(p_param);
LSP::TextDocumentItem doc = load_document_item(p_param);
sync_script_content(doc.uri, doc.text);
}
@@ -73,11 +73,11 @@ void GDScriptTextDocument::didClose(const Variant &p_param) {
}
void GDScriptTextDocument::didChange(const Variant &p_param) {
lsp::TextDocumentItem doc = load_document_item(p_param);
LSP::TextDocumentItem doc = load_document_item(p_param);
Dictionary dict = p_param;
Array contentChanges = dict["contentChanges"];
for (int i = 0; i < contentChanges.size(); ++i) {
lsp::TextDocumentContentChangeEvent evt;
LSP::TextDocumentContentChangeEvent evt;
evt.load(contentChanges[i]);
doc.text = evt.text;
}
@@ -85,7 +85,7 @@ void GDScriptTextDocument::didChange(const Variant &p_param) {
}
void GDScriptTextDocument::willSaveWaitUntil(const Variant &p_param) {
lsp::TextDocumentItem doc = load_document_item(p_param);
LSP::TextDocumentItem doc = load_document_item(p_param);
String path = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_path(doc.uri);
Ref<Script> scr = ResourceLoader::load(path);
@@ -95,7 +95,7 @@ void GDScriptTextDocument::willSaveWaitUntil(const Variant &p_param) {
}
void GDScriptTextDocument::didSave(const Variant &p_param) {
lsp::TextDocumentItem doc = load_document_item(p_param);
LSP::TextDocumentItem doc = load_document_item(p_param);
Dictionary dict = p_param;
String text = dict["text"];
@@ -126,14 +126,14 @@ void GDScriptTextDocument::reload_script(Ref<GDScript> p_to_reload_script) {
ScriptEditor::get_singleton()->trigger_live_script_reload(p_to_reload_script->get_path());
}
lsp::TextDocumentItem GDScriptTextDocument::load_document_item(const Variant &p_param) {
lsp::TextDocumentItem doc;
LSP::TextDocumentItem GDScriptTextDocument::load_document_item(const Variant &p_param) {
LSP::TextDocumentItem doc;
Dictionary params = p_param;
doc.load(params["textDocument"]);
return doc;
}
void GDScriptTextDocument::notify_client_show_symbol(const lsp::DocumentSymbol *symbol) {
void GDScriptTextDocument::notify_client_show_symbol(const LSP::DocumentSymbol *symbol) {
ERR_FAIL_NULL(symbol);
GDScriptLanguageProtocol::get_singleton()->notify_client("gdscript/show_native_symbol", symbol->to_json(true));
}
@@ -143,9 +143,9 @@ void GDScriptTextDocument::initialize() {
for (const KeyValue<StringName, ClassMembers> &E : GDScriptLanguageProtocol::get_singleton()->get_workspace()->native_members) {
const ClassMembers &members = E.value;
for (const KeyValue<String, const lsp::DocumentSymbol *> &F : members) {
const lsp::DocumentSymbol *symbol = members.get(F.key);
lsp::CompletionItem item = symbol->make_completion_item();
for (const KeyValue<String, const LSP::DocumentSymbol *> &F : members) {
const LSP::DocumentSymbol *symbol = members.get(F.key);
LSP::CompletionItem item = symbol->make_completion_item();
item.data = JOIN_SYMBOLS(String(E.key), F.key);
native_member_completions.push_back(item.to_json());
}
@@ -156,10 +156,10 @@ void GDScriptTextDocument::initialize() {
Variant GDScriptTextDocument::nativeSymbol(const Dictionary &p_params) {
Variant ret;
lsp::NativeSymbolInspectParams params;
LSP::NativeSymbolInspectParams params;
params.load(p_params);
if (const lsp::DocumentSymbol *symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_native_symbol(params)) {
if (const LSP::DocumentSymbol *symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_native_symbol(params)) {
ret = symbol->to_json(true);
notify_client_show_symbol(symbol);
}
@@ -173,7 +173,7 @@ Array GDScriptTextDocument::documentSymbol(const Dictionary &p_params) {
String path = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_path(uri);
Array arr;
if (HashMap<String, ExtendGDScriptParser *>::ConstIterator parser = GDScriptLanguageProtocol::get_singleton()->get_workspace()->scripts.find(path)) {
lsp::DocumentSymbol symbol = parser->value->get_symbols();
LSP::DocumentSymbol symbol = parser->value->get_symbols();
arr.push_back(symbol.to_json(true));
}
return arr;
@@ -182,7 +182,7 @@ Array GDScriptTextDocument::documentSymbol(const Dictionary &p_params) {
Array GDScriptTextDocument::completion(const Dictionary &p_params) {
Array arr;
lsp::CompletionParams params;
LSP::CompletionParams params;
params.load(p_params);
Dictionary request_data = params.to_json();
@@ -194,41 +194,41 @@ Array GDScriptTextDocument::completion(const Dictionary &p_params) {
arr.resize(options.size());
for (const ScriptLanguage::CodeCompletionOption &option : options) {
lsp::CompletionItem item;
LSP::CompletionItem item;
item.label = option.display;
item.data = request_data;
item.insertText = option.insert_text;
switch (option.kind) {
case ScriptLanguage::CODE_COMPLETION_KIND_ENUM:
item.kind = lsp::CompletionItemKind::Enum;
item.kind = LSP::CompletionItemKind::Enum;
break;
case ScriptLanguage::CODE_COMPLETION_KIND_CLASS:
item.kind = lsp::CompletionItemKind::Class;
item.kind = LSP::CompletionItemKind::Class;
break;
case ScriptLanguage::CODE_COMPLETION_KIND_MEMBER:
item.kind = lsp::CompletionItemKind::Property;
item.kind = LSP::CompletionItemKind::Property;
break;
case ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION:
item.kind = lsp::CompletionItemKind::Method;
item.kind = LSP::CompletionItemKind::Method;
break;
case ScriptLanguage::CODE_COMPLETION_KIND_SIGNAL:
item.kind = lsp::CompletionItemKind::Event;
item.kind = LSP::CompletionItemKind::Event;
break;
case ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT:
item.kind = lsp::CompletionItemKind::Constant;
item.kind = LSP::CompletionItemKind::Constant;
break;
case ScriptLanguage::CODE_COMPLETION_KIND_VARIABLE:
item.kind = lsp::CompletionItemKind::Variable;
item.kind = LSP::CompletionItemKind::Variable;
break;
case ScriptLanguage::CODE_COMPLETION_KIND_FILE_PATH:
item.kind = lsp::CompletionItemKind::File;
item.kind = LSP::CompletionItemKind::File;
break;
case ScriptLanguage::CODE_COMPLETION_KIND_NODE_PATH:
item.kind = lsp::CompletionItemKind::Snippet;
item.kind = LSP::CompletionItemKind::Snippet;
break;
case ScriptLanguage::CODE_COMPLETION_KIND_PLAIN_TEXT:
item.kind = lsp::CompletionItemKind::Text;
item.kind = LSP::CompletionItemKind::Text;
break;
default: {
}
@@ -242,7 +242,7 @@ Array GDScriptTextDocument::completion(const Dictionary &p_params) {
}
Dictionary GDScriptTextDocument::rename(const Dictionary &p_params) {
lsp::TextDocumentPositionParams params;
LSP::TextDocumentPositionParams params;
params.load(p_params);
String new_name = p_params["newName"];
@@ -250,11 +250,11 @@ Dictionary GDScriptTextDocument::rename(const Dictionary &p_params) {
}
Variant GDScriptTextDocument::prepareRename(const Dictionary &p_params) {
lsp::TextDocumentPositionParams params;
LSP::TextDocumentPositionParams params;
params.load(p_params);
lsp::DocumentSymbol symbol;
lsp::Range range;
LSP::DocumentSymbol symbol;
LSP::Range range;
if (GDScriptLanguageProtocol::get_singleton()->get_workspace()->can_rename(params, symbol, range)) {
return Variant(range.to_json());
}
@@ -266,16 +266,16 @@ Variant GDScriptTextDocument::prepareRename(const Dictionary &p_params) {
Array GDScriptTextDocument::references(const Dictionary &p_params) {
Array res;
lsp::ReferenceParams params;
LSP::ReferenceParams params;
params.load(p_params);
const lsp::DocumentSymbol *symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_symbol(params);
const LSP::DocumentSymbol *symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_symbol(params);
if (symbol) {
Vector<lsp::Location> usages = GDScriptLanguageProtocol::get_singleton()->get_workspace()->find_all_usages(*symbol);
Vector<LSP::Location> usages = GDScriptLanguageProtocol::get_singleton()->get_workspace()->find_all_usages(*symbol);
res.resize(usages.size());
int declaration_adjustment = 0;
for (int i = 0; i < usages.size(); i++) {
lsp::Location usage = usages[i];
LSP::Location usage = usages[i];
if (!params.context.includeDeclaration && usage.range == symbol->range) {
declaration_adjustment++;
continue;
@@ -292,17 +292,17 @@ Array GDScriptTextDocument::references(const Dictionary &p_params) {
}
Dictionary GDScriptTextDocument::resolve(const Dictionary &p_params) {
lsp::CompletionItem item;
LSP::CompletionItem item;
item.load(p_params);
lsp::CompletionParams params;
LSP::CompletionParams params;
Variant data = p_params["data"];
const lsp::DocumentSymbol *symbol = nullptr;
const LSP::DocumentSymbol *symbol = nullptr;
if (data.get_type() == Variant::DICTIONARY) {
params.load(p_params["data"]);
symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_symbol(params, item.label, item.kind == lsp::CompletionItemKind::Method || item.kind == lsp::CompletionItemKind::Function);
symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_symbol(params, item.label, item.kind == LSP::CompletionItemKind::Method || item.kind == LSP::CompletionItemKind::Function);
} else if (data.is_string()) {
String query = data;
@@ -318,7 +318,7 @@ Dictionary GDScriptTextDocument::resolve(const Dictionary &p_params) {
}
if (const ClassMembers *members = GDScriptLanguageProtocol::get_singleton()->get_workspace()->native_members.getptr(class_name)) {
if (const lsp::DocumentSymbol *const *member = members->getptr(member_name)) {
if (const LSP::DocumentSymbol *const *member = members->getptr(member_name)) {
symbol = *member;
}
}
@@ -335,15 +335,15 @@ Dictionary GDScriptTextDocument::resolve(const Dictionary &p_params) {
item.documentation = symbol->render();
}
if (item.kind == lsp::CompletionItemKind::Event) {
if (params.context.triggerKind == lsp::CompletionTriggerKind::TriggerCharacter && (params.context.triggerCharacter == "(")) {
if (item.kind == LSP::CompletionItemKind::Event) {
if (params.context.triggerKind == LSP::CompletionTriggerKind::TriggerCharacter && (params.context.triggerCharacter == "(")) {
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
item.insertText = item.label.quote(quote_style);
}
}
if (item.kind == lsp::CompletionItemKind::Method) {
bool is_trigger_character = params.context.triggerKind == lsp::CompletionTriggerKind::TriggerCharacter;
if (item.kind == LSP::CompletionItemKind::Method) {
bool is_trigger_character = params.context.triggerKind == LSP::CompletionTriggerKind::TriggerCharacter;
bool is_quote_character = params.context.triggerCharacter == "\"" || params.context.triggerCharacter == "'";
if (is_trigger_character && is_quote_character && item.insertText.is_quoted()) {
@@ -367,12 +367,12 @@ Array GDScriptTextDocument::codeLens(const Dictionary &p_params) {
Array GDScriptTextDocument::documentLink(const Dictionary &p_params) {
Array ret;
lsp::DocumentLinkParams params;
LSP::DocumentLinkParams params;
params.load(p_params);
List<lsp::DocumentLink> links;
List<LSP::DocumentLink> links;
GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_document_links(params.textDocument.uri, links);
for (const lsp::DocumentLink &E : links) {
for (const LSP::DocumentLink &E : links) {
ret.push_back(E.to_json());
}
return ret;
@@ -384,12 +384,12 @@ Array GDScriptTextDocument::colorPresentation(const Dictionary &p_params) {
}
Variant GDScriptTextDocument::hover(const Dictionary &p_params) {
lsp::TextDocumentPositionParams params;
LSP::TextDocumentPositionParams params;
params.load(p_params);
const lsp::DocumentSymbol *symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_symbol(params);
const LSP::DocumentSymbol *symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_symbol(params);
if (symbol) {
lsp::Hover hover;
LSP::Hover hover;
hover.contents = symbol->render();
hover.range.start = params.position;
hover.range.end = params.position;
@@ -398,10 +398,10 @@ Variant GDScriptTextDocument::hover(const Dictionary &p_params) {
} else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
Dictionary ret;
Array contents;
List<const lsp::DocumentSymbol *> list;
List<const LSP::DocumentSymbol *> list;
GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(params, list);
for (const lsp::DocumentSymbol *&E : list) {
if (const lsp::DocumentSymbol *s = E) {
for (const LSP::DocumentSymbol *&E : list) {
if (const LSP::DocumentSymbol *s = E) {
contents.push_back(s->render().value);
}
}
@@ -413,38 +413,38 @@ Variant GDScriptTextDocument::hover(const Dictionary &p_params) {
}
Array GDScriptTextDocument::definition(const Dictionary &p_params) {
lsp::TextDocumentPositionParams params;
LSP::TextDocumentPositionParams params;
params.load(p_params);
List<const lsp::DocumentSymbol *> symbols;
List<const LSP::DocumentSymbol *> symbols;
Array arr = find_symbols(params, symbols);
return arr;
}
Variant GDScriptTextDocument::declaration(const Dictionary &p_params) {
lsp::TextDocumentPositionParams params;
LSP::TextDocumentPositionParams params;
params.load(p_params);
List<const lsp::DocumentSymbol *> symbols;
List<const LSP::DocumentSymbol *> symbols;
Array arr = find_symbols(params, symbols);
if (arr.is_empty() && !symbols.is_empty() && !symbols.front()->get()->native_class.is_empty()) { // Find a native symbol
const lsp::DocumentSymbol *symbol = symbols.front()->get();
const LSP::DocumentSymbol *symbol = symbols.front()->get();
if (GDScriptLanguageProtocol::get_singleton()->is_goto_native_symbols_enabled()) {
String id;
switch (symbol->kind) {
case lsp::SymbolKind::Class:
case LSP::SymbolKind::Class:
id = "class_name:" + symbol->name;
break;
case lsp::SymbolKind::Constant:
case LSP::SymbolKind::Constant:
id = "class_constant:" + symbol->native_class + ":" + symbol->name;
break;
case lsp::SymbolKind::Property:
case lsp::SymbolKind::Variable:
case LSP::SymbolKind::Property:
case LSP::SymbolKind::Variable:
id = "class_property:" + symbol->native_class + ":" + symbol->name;
break;
case lsp::SymbolKind::Enum:
case LSP::SymbolKind::Enum:
id = "class_enum:" + symbol->native_class + ":" + symbol->name;
break;
case lsp::SymbolKind::Method:
case lsp::SymbolKind::Function:
case LSP::SymbolKind::Method:
case LSP::SymbolKind::Function:
id = "class_method:" + symbol->native_class + ":" + symbol->name;
break;
default:
@@ -462,10 +462,10 @@ Variant GDScriptTextDocument::declaration(const Dictionary &p_params) {
Variant GDScriptTextDocument::signatureHelp(const Dictionary &p_params) {
Variant ret;
lsp::TextDocumentPositionParams params;
LSP::TextDocumentPositionParams params;
params.load(p_params);
lsp::SignatureHelp s;
LSP::SignatureHelp s;
if (OK == GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_signature(params, s)) {
ret = s.to_json();
}
@@ -488,11 +488,11 @@ void GDScriptTextDocument::show_native_symbol_in_editor(const String &p_symbol_i
DisplayServer::get_singleton()->window_move_to_foreground();
}
Array GDScriptTextDocument::find_symbols(const lsp::TextDocumentPositionParams &p_location, List<const lsp::DocumentSymbol *> &r_list) {
Array GDScriptTextDocument::find_symbols(const LSP::TextDocumentPositionParams &p_location, List<const LSP::DocumentSymbol *> &r_list) {
Array arr;
const lsp::DocumentSymbol *symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_symbol(p_location);
const LSP::DocumentSymbol *symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_symbol(p_location);
if (symbol) {
lsp::Location location;
LSP::Location location;
location.uri = symbol->uri;
location.range = symbol->selectionRange;
const String &path = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_path(symbol->uri);
@@ -501,12 +501,12 @@ Array GDScriptTextDocument::find_symbols(const lsp::TextDocumentPositionParams &
}
r_list.push_back(symbol);
} else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
List<const lsp::DocumentSymbol *> list;
List<const LSP::DocumentSymbol *> list;
GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(p_location, list);
for (const lsp::DocumentSymbol *&E : list) {
if (const lsp::DocumentSymbol *s = E) {
for (const LSP::DocumentSymbol *&E : list) {
if (const LSP::DocumentSymbol *s = E) {
if (!s->uri.is_empty()) {
lsp::Location location;
LSP::Location location;
location.uri = s->uri;
location.range = s->selectionRange;
arr.push_back(location.to_json());

View File

@@ -57,9 +57,9 @@ protected:
Array native_member_completions;
private:
Array find_symbols(const lsp::TextDocumentPositionParams &p_location, List<const lsp::DocumentSymbol *> &r_list);
lsp::TextDocumentItem load_document_item(const Variant &p_param);
void notify_client_show_symbol(const lsp::DocumentSymbol *symbol);
Array find_symbols(const LSP::TextDocumentPositionParams &p_location, List<const LSP::DocumentSymbol *> &r_list);
LSP::TextDocumentItem load_document_item(const Variant &p_param);
void notify_client_show_symbol(const LSP::DocumentSymbol *symbol);
public:
Variant nativeSymbol(const Dictionary &p_params);

View File

@@ -89,7 +89,7 @@ void GDScriptWorkspace::apply_new_signal(Object *obj, String function, PackedStr
}
function_body += ":\n\tpass # Replace with function body.\n";
lsp::TextEdit text_edit;
LSP::TextEdit text_edit;
if (first_class != -1) {
function_body += "\n\n";
@@ -100,7 +100,7 @@ void GDScriptWorkspace::apply_new_signal(Object *obj, String function, PackedStr
String uri = get_file_uri(scr->get_path());
lsp::ApplyWorkspaceEditParams params;
LSP::ApplyWorkspaceEditParams params;
params.edit.add_edit(uri, text_edit);
GDScriptLanguageProtocol::get_singleton()->request_client("workspace/applyEdit", params.to_json());
@@ -137,19 +137,19 @@ void GDScriptWorkspace::remove_cache_parser(const String &p_path) {
}
}
const lsp::DocumentSymbol *GDScriptWorkspace::get_native_symbol(const String &p_class, const String &p_member) const {
const LSP::DocumentSymbol *GDScriptWorkspace::get_native_symbol(const String &p_class, const String &p_member) const {
StringName class_name = p_class;
StringName empty;
while (class_name != empty) {
if (HashMap<StringName, lsp::DocumentSymbol>::ConstIterator E = native_symbols.find(class_name)) {
const lsp::DocumentSymbol &class_symbol = E->value;
if (HashMap<StringName, LSP::DocumentSymbol>::ConstIterator E = native_symbols.find(class_name)) {
const LSP::DocumentSymbol &class_symbol = E->value;
if (p_member.is_empty()) {
return &class_symbol;
} else {
for (int i = 0; i < class_symbol.children.size(); i++) {
const lsp::DocumentSymbol &symbol = class_symbol.children[i];
const LSP::DocumentSymbol &symbol = class_symbol.children[i];
if (symbol.name == p_member) {
return &symbol;
}
@@ -162,7 +162,7 @@ const lsp::DocumentSymbol *GDScriptWorkspace::get_native_symbol(const String &p_
return nullptr;
}
const lsp::DocumentSymbol *GDScriptWorkspace::get_script_symbol(const String &p_path) const {
const LSP::DocumentSymbol *GDScriptWorkspace::get_script_symbol(const String &p_path) const {
HashMap<String, ExtendGDScriptParser *>::ConstIterator S = scripts.find(p_path);
if (S) {
return &(S->value->get_symbols());
@@ -170,9 +170,9 @@ const lsp::DocumentSymbol *GDScriptWorkspace::get_script_symbol(const String &p_
return nullptr;
}
const lsp::DocumentSymbol *GDScriptWorkspace::get_parameter_symbol(const lsp::DocumentSymbol *p_parent, const String &symbol_identifier) {
const LSP::DocumentSymbol *GDScriptWorkspace::get_parameter_symbol(const LSP::DocumentSymbol *p_parent, const String &symbol_identifier) {
for (int i = 0; i < p_parent->children.size(); ++i) {
const lsp::DocumentSymbol *parameter_symbol = &p_parent->children[i];
const LSP::DocumentSymbol *parameter_symbol = &p_parent->children[i];
if (!parameter_symbol->detail.is_empty() && parameter_symbol->name == symbol_identifier) {
return parameter_symbol;
}
@@ -181,11 +181,11 @@ const lsp::DocumentSymbol *GDScriptWorkspace::get_parameter_symbol(const lsp::Do
return nullptr;
}
const lsp::DocumentSymbol *GDScriptWorkspace::get_local_symbol_at(const ExtendGDScriptParser *p_parser, const String &p_symbol_identifier, const lsp::Position p_position) {
const LSP::DocumentSymbol *GDScriptWorkspace::get_local_symbol_at(const ExtendGDScriptParser *p_parser, const String &p_symbol_identifier, const LSP::Position p_position) {
// Go down and pick closest `DocumentSymbol` with `p_symbol_identifier`.
const lsp::DocumentSymbol *current = &p_parser->get_symbols();
const lsp::DocumentSymbol *best_match = nullptr;
const LSP::DocumentSymbol *current = &p_parser->get_symbols();
const LSP::DocumentSymbol *best_match = nullptr;
while (current) {
if (current->name == p_symbol_identifier) {
@@ -197,9 +197,9 @@ const lsp::DocumentSymbol *GDScriptWorkspace::get_local_symbol_at(const ExtendGD
best_match = current;
}
const lsp::DocumentSymbol *parent = current;
const LSP::DocumentSymbol *parent = current;
current = nullptr;
for (const lsp::DocumentSymbol &child : parent->children) {
for (const LSP::DocumentSymbol &child : parent->children) {
if (child.range.contains(p_position)) {
current = &child;
break;
@@ -287,11 +287,11 @@ Error GDScriptWorkspace::initialize() {
DocTools *doc = EditorHelp::get_doc_data();
for (const KeyValue<String, DocData::ClassDoc> &E : doc->class_list) {
const DocData::ClassDoc &class_data = E.value;
lsp::DocumentSymbol class_symbol;
LSP::DocumentSymbol class_symbol;
String class_name = E.key;
class_symbol.name = class_name;
class_symbol.native_class = class_name;
class_symbol.kind = lsp::SymbolKind::Class;
class_symbol.kind = LSP::SymbolKind::Class;
class_symbol.detail = String("<Native> class ") + class_name;
if (!class_data.inherits.is_empty()) {
class_symbol.detail += " extends " + class_data.inherits;
@@ -300,10 +300,10 @@ Error GDScriptWorkspace::initialize() {
for (int i = 0; i < class_data.constants.size(); i++) {
const DocData::ConstantDoc &const_data = class_data.constants[i];
lsp::DocumentSymbol symbol;
LSP::DocumentSymbol symbol;
symbol.name = const_data.name;
symbol.native_class = class_name;
symbol.kind = lsp::SymbolKind::Constant;
symbol.kind = LSP::SymbolKind::Constant;
symbol.detail = "const " + class_name + "." + const_data.name;
if (const_data.enumeration.length()) {
symbol.detail += ": " + const_data.enumeration;
@@ -315,10 +315,10 @@ Error GDScriptWorkspace::initialize() {
for (int i = 0; i < class_data.properties.size(); i++) {
const DocData::PropertyDoc &data = class_data.properties[i];
lsp::DocumentSymbol symbol;
LSP::DocumentSymbol symbol;
symbol.name = data.name;
symbol.native_class = class_name;
symbol.kind = lsp::SymbolKind::Property;
symbol.kind = LSP::SymbolKind::Property;
symbol.detail = "var " + class_name + "." + data.name;
if (data.enumeration.length()) {
symbol.detail += ": " + data.enumeration;
@@ -331,10 +331,10 @@ Error GDScriptWorkspace::initialize() {
for (int i = 0; i < class_data.theme_properties.size(); i++) {
const DocData::ThemeItemDoc &data = class_data.theme_properties[i];
lsp::DocumentSymbol symbol;
LSP::DocumentSymbol symbol;
symbol.name = data.name;
symbol.native_class = class_name;
symbol.kind = lsp::SymbolKind::Property;
symbol.kind = LSP::SymbolKind::Property;
symbol.detail = "<Theme> var " + class_name + "." + data.name + ": " + data.type;
symbol.documentation = data.description;
class_symbol.children.push_back(symbol);
@@ -350,19 +350,19 @@ Error GDScriptWorkspace::initialize() {
for (int i = 0; i < methods_signals.size(); i++) {
const DocData::MethodDoc &data = methods_signals[i];
lsp::DocumentSymbol symbol;
LSP::DocumentSymbol symbol;
symbol.name = data.name;
symbol.native_class = class_name;
symbol.kind = i >= signal_start_idx ? lsp::SymbolKind::Event : lsp::SymbolKind::Method;
symbol.kind = i >= signal_start_idx ? LSP::SymbolKind::Event : LSP::SymbolKind::Method;
String params = "";
bool arg_default_value_started = false;
for (int j = 0; j < data.arguments.size(); j++) {
const DocData::ArgumentDoc &arg = data.arguments[j];
lsp::DocumentSymbol symbol_arg;
LSP::DocumentSymbol symbol_arg;
symbol_arg.name = arg.name;
symbol_arg.kind = lsp::SymbolKind::Variable;
symbol_arg.kind = LSP::SymbolKind::Variable;
symbol_arg.detail = arg.type;
if (!arg_default_value_started && !arg.default_value.is_empty()) {
@@ -398,11 +398,11 @@ Error GDScriptWorkspace::initialize() {
reload_all_workspace_scripts();
if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
for (const KeyValue<StringName, lsp::DocumentSymbol> &E : native_symbols) {
for (const KeyValue<StringName, LSP::DocumentSymbol> &E : native_symbols) {
ClassMembers members;
const lsp::DocumentSymbol &class_symbol = E.value;
const LSP::DocumentSymbol &class_symbol = E.value;
for (int i = 0; i < class_symbol.children.size(); i++) {
const lsp::DocumentSymbol &symbol = class_symbol.children[i];
const LSP::DocumentSymbol &symbol = class_symbol.children[i];
members.insert(symbol.name, &symbol);
}
native_members.insert(E.key, members);
@@ -443,7 +443,7 @@ Error GDScriptWorkspace::parse_script(const String &p_path, const String &p_cont
return err;
}
static bool is_valid_rename_target(const lsp::DocumentSymbol *p_symbol) {
static bool is_valid_rename_target(const LSP::DocumentSymbol *p_symbol) {
// Must be valid symbol.
if (!p_symbol) {
return false;
@@ -462,14 +462,14 @@ static bool is_valid_rename_target(const lsp::DocumentSymbol *p_symbol) {
return true;
}
Dictionary GDScriptWorkspace::rename(const lsp::TextDocumentPositionParams &p_doc_pos, const String &new_name) {
lsp::WorkspaceEdit edit;
Dictionary GDScriptWorkspace::rename(const LSP::TextDocumentPositionParams &p_doc_pos, const String &new_name) {
LSP::WorkspaceEdit edit;
const lsp::DocumentSymbol *reference_symbol = resolve_symbol(p_doc_pos);
const LSP::DocumentSymbol *reference_symbol = resolve_symbol(p_doc_pos);
if (is_valid_rename_target(reference_symbol)) {
Vector<lsp::Location> usages = find_all_usages(*reference_symbol);
Vector<LSP::Location> usages = find_all_usages(*reference_symbol);
for (int i = 0; i < usages.size(); ++i) {
lsp::Location loc = usages[i];
LSP::Location loc = usages[i];
edit.add_change(loc.uri, loc.range.start.line, loc.range.start.character, loc.range.end.character, new_name);
}
@@ -478,8 +478,8 @@ Dictionary GDScriptWorkspace::rename(const lsp::TextDocumentPositionParams &p_do
return edit.to_json();
}
bool GDScriptWorkspace::can_rename(const lsp::TextDocumentPositionParams &p_doc_pos, lsp::DocumentSymbol &r_symbol, lsp::Range &r_range) {
const lsp::DocumentSymbol *reference_symbol = resolve_symbol(p_doc_pos);
bool GDScriptWorkspace::can_rename(const LSP::TextDocumentPositionParams &p_doc_pos, LSP::DocumentSymbol &r_symbol, LSP::Range &r_range) {
const LSP::DocumentSymbol *reference_symbol = resolve_symbol(p_doc_pos);
if (!is_valid_rename_target(reference_symbol)) {
return false;
}
@@ -494,8 +494,8 @@ bool GDScriptWorkspace::can_rename(const lsp::TextDocumentPositionParams &p_doc_
return false;
}
Vector<lsp::Location> GDScriptWorkspace::find_usages_in_file(const lsp::DocumentSymbol &p_symbol, const String &p_file_path) {
Vector<lsp::Location> usages;
Vector<LSP::Location> GDScriptWorkspace::find_usages_in_file(const LSP::DocumentSymbol &p_symbol, const String &p_file_path) {
Vector<LSP::Location> usages;
String identifier = p_symbol.name;
if (const ExtendGDScriptParser *parser = get_parse_result(p_file_path)) {
@@ -505,19 +505,19 @@ Vector<lsp::Location> GDScriptWorkspace::find_usages_in_file(const lsp::Document
int character = line.find(identifier);
while (character > -1) {
lsp::TextDocumentPositionParams params;
LSP::TextDocumentPositionParams params;
lsp::TextDocumentIdentifier text_doc;
LSP::TextDocumentIdentifier text_doc;
text_doc.uri = get_file_uri(p_file_path);
params.textDocument = text_doc;
params.position.line = i;
params.position.character = character;
const lsp::DocumentSymbol *other_symbol = resolve_symbol(params);
const LSP::DocumentSymbol *other_symbol = resolve_symbol(params);
if (other_symbol == &p_symbol) {
lsp::Location loc;
LSP::Location loc;
loc.uri = text_doc.uri;
loc.range.start = params.position;
loc.range.end.line = params.position.line;
@@ -533,7 +533,7 @@ Vector<lsp::Location> GDScriptWorkspace::find_usages_in_file(const lsp::Document
return usages;
}
Vector<lsp::Location> GDScriptWorkspace::find_all_usages(const lsp::DocumentSymbol &p_symbol) {
Vector<LSP::Location> GDScriptWorkspace::find_all_usages(const LSP::DocumentSymbol &p_symbol) {
if (p_symbol.local) {
// Only search in current document.
return find_usages_in_file(p_symbol, p_symbol.script_path);
@@ -542,7 +542,7 @@ Vector<lsp::Location> GDScriptWorkspace::find_all_usages(const lsp::DocumentSymb
List<String> paths;
list_script_files("res://", paths);
Vector<lsp::Location> usages;
Vector<LSP::Location> usages;
for (List<String>::Element *PE = paths.front(); PE; PE = PE->next()) {
usages.append_array(find_usages_in_file(p_symbol, PE->get()));
}
@@ -576,7 +576,7 @@ void GDScriptWorkspace::publish_diagnostics(const String &p_path) {
Array errors;
HashMap<String, ExtendGDScriptParser *>::ConstIterator ele = parse_results.find(p_path);
if (ele) {
const Vector<lsp::Diagnostic> &list = ele->value->get_diagnostics();
const Vector<LSP::Diagnostic> &list = ele->value->get_diagnostics();
errors.resize(list.size());
for (int i = 0; i < list.size(); ++i) {
errors[i] = list[i].to_json();
@@ -632,7 +632,7 @@ Node *GDScriptWorkspace::_get_owner_scene_node(String p_path) {
return owner_scene_node;
}
void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<ScriptLanguage::CodeCompletionOption> *r_options) {
void GDScriptWorkspace::completion(const LSP::CompletionParams &p_params, List<ScriptLanguage::CodeCompletionOption> *r_options) {
String path = get_file_path(p_params.textDocument.uri);
String call_hint;
bool forced = false;
@@ -670,8 +670,8 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
}
}
const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocumentPositionParams &p_doc_pos, const String &p_symbol_name, bool p_func_required) {
const lsp::DocumentSymbol *symbol = nullptr;
const LSP::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const LSP::TextDocumentPositionParams &p_doc_pos, const String &p_symbol_name, bool p_func_required) {
const LSP::DocumentSymbol *symbol = nullptr;
String path = get_file_path(p_doc_pos.textDocument.uri);
if (const ExtendGDScriptParser *parser = get_parse_result(path)) {
@@ -681,9 +681,9 @@ const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocu
symbol_identifier = identifier_parts[0];
}
lsp::Position pos = p_doc_pos.position;
LSP::Position pos = p_doc_pos.position;
if (symbol_identifier.is_empty()) {
lsp::Range range;
LSP::Range range;
symbol_identifier = parser->get_identifier_under_position(p_doc_pos.position, range);
pos.character = range.end.character;
}
@@ -712,7 +712,7 @@ const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocu
if (symbol) {
switch (symbol->kind) {
case lsp::SymbolKind::Function: {
case LSP::SymbolKind::Function: {
if (symbol->name != symbol_identifier) {
symbol = get_parameter_symbol(symbol, symbol_identifier);
}
@@ -740,16 +740,16 @@ const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocu
return symbol;
}
void GDScriptWorkspace::resolve_related_symbols(const lsp::TextDocumentPositionParams &p_doc_pos, List<const lsp::DocumentSymbol *> &r_list) {
void GDScriptWorkspace::resolve_related_symbols(const LSP::TextDocumentPositionParams &p_doc_pos, List<const LSP::DocumentSymbol *> &r_list) {
String path = get_file_path(p_doc_pos.textDocument.uri);
if (const ExtendGDScriptParser *parser = get_parse_result(path)) {
String symbol_identifier;
lsp::Range range;
LSP::Range range;
symbol_identifier = parser->get_identifier_under_position(p_doc_pos.position, range);
for (const KeyValue<StringName, ClassMembers> &E : native_members) {
const ClassMembers &members = native_members.get(E.key);
if (const lsp::DocumentSymbol *const *symbol = members.getptr(symbol_identifier)) {
if (const LSP::DocumentSymbol *const *symbol = members.getptr(symbol_identifier)) {
r_list.push_back(*symbol);
}
}
@@ -757,13 +757,13 @@ void GDScriptWorkspace::resolve_related_symbols(const lsp::TextDocumentPositionP
for (const KeyValue<String, ExtendGDScriptParser *> &E : scripts) {
const ExtendGDScriptParser *scr = E.value;
const ClassMembers &members = scr->get_members();
if (const lsp::DocumentSymbol *const *symbol = members.getptr(symbol_identifier)) {
if (const LSP::DocumentSymbol *const *symbol = members.getptr(symbol_identifier)) {
r_list.push_back(*symbol);
}
for (const KeyValue<String, ClassMembers> &F : scr->get_inner_classes()) {
const ClassMembers *inner_class = &F.value;
if (const lsp::DocumentSymbol *const *symbol = inner_class->getptr(symbol_identifier)) {
if (const LSP::DocumentSymbol *const *symbol = inner_class->getptr(symbol_identifier)) {
r_list.push_back(*symbol);
}
}
@@ -771,9 +771,9 @@ void GDScriptWorkspace::resolve_related_symbols(const lsp::TextDocumentPositionP
}
}
const lsp::DocumentSymbol *GDScriptWorkspace::resolve_native_symbol(const lsp::NativeSymbolInspectParams &p_params) {
if (HashMap<StringName, lsp::DocumentSymbol>::Iterator E = native_symbols.find(p_params.native_class)) {
const lsp::DocumentSymbol &symbol = E->value;
const LSP::DocumentSymbol *GDScriptWorkspace::resolve_native_symbol(const LSP::NativeSymbolInspectParams &p_params) {
if (HashMap<StringName, LSP::DocumentSymbol>::Iterator E = native_symbols.find(p_params.native_class)) {
const LSP::DocumentSymbol &symbol = E->value;
if (p_params.symbol_name.is_empty() || p_params.symbol_name == symbol.name) {
return &symbol;
}
@@ -788,10 +788,10 @@ const lsp::DocumentSymbol *GDScriptWorkspace::resolve_native_symbol(const lsp::N
return nullptr;
}
void GDScriptWorkspace::resolve_document_links(const String &p_uri, List<lsp::DocumentLink> &r_list) {
void GDScriptWorkspace::resolve_document_links(const String &p_uri, List<LSP::DocumentLink> &r_list) {
if (const ExtendGDScriptParser *parser = get_parse_successed_script(get_file_path(p_uri))) {
const List<lsp::DocumentLink> &links = parser->get_document_links();
for (const lsp::DocumentLink &E : links) {
const List<LSP::DocumentLink> &links = parser->get_document_links();
for (const LSP::DocumentLink &E : links) {
r_list.push_back(E);
}
}
@@ -805,29 +805,29 @@ Dictionary GDScriptWorkspace::generate_script_api(const String &p_path) {
return api;
}
Error GDScriptWorkspace::resolve_signature(const lsp::TextDocumentPositionParams &p_doc_pos, lsp::SignatureHelp &r_signature) {
Error GDScriptWorkspace::resolve_signature(const LSP::TextDocumentPositionParams &p_doc_pos, LSP::SignatureHelp &r_signature) {
if (const ExtendGDScriptParser *parser = get_parse_result(get_file_path(p_doc_pos.textDocument.uri))) {
lsp::TextDocumentPositionParams text_pos;
LSP::TextDocumentPositionParams text_pos;
text_pos.textDocument = p_doc_pos.textDocument;
if (parser->get_left_function_call(p_doc_pos.position, text_pos.position, r_signature.activeParameter) == OK) {
List<const lsp::DocumentSymbol *> symbols;
List<const LSP::DocumentSymbol *> symbols;
if (const lsp::DocumentSymbol *symbol = resolve_symbol(text_pos)) {
if (const LSP::DocumentSymbol *symbol = resolve_symbol(text_pos)) {
symbols.push_back(symbol);
} else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(text_pos, symbols);
}
for (const lsp::DocumentSymbol *const &symbol : symbols) {
if (symbol->kind == lsp::SymbolKind::Method || symbol->kind == lsp::SymbolKind::Function) {
lsp::SignatureInformation signature_info;
for (const LSP::DocumentSymbol *const &symbol : symbols) {
if (symbol->kind == LSP::SymbolKind::Method || symbol->kind == LSP::SymbolKind::Function) {
LSP::SignatureInformation signature_info;
signature_info.label = symbol->detail;
signature_info.documentation = symbol->render();
for (int i = 0; i < symbol->children.size(); i++) {
const lsp::DocumentSymbol &arg = symbol->children[i];
lsp::ParameterInformation arg_info;
const LSP::DocumentSymbol &arg = symbol->children[i];
LSP::ParameterInformation arg_info;
arg_info.label = arg.name;
signature_info.parameters.push_back(arg_info);
}

View File

@@ -48,12 +48,12 @@ protected:
static void _bind_methods();
void remove_cache_parser(const String &p_path);
bool initialized = false;
HashMap<StringName, lsp::DocumentSymbol> native_symbols;
HashMap<StringName, LSP::DocumentSymbol> native_symbols;
const lsp::DocumentSymbol *get_native_symbol(const String &p_class, const String &p_member = "") const;
const lsp::DocumentSymbol *get_script_symbol(const String &p_path) const;
const lsp::DocumentSymbol *get_parameter_symbol(const lsp::DocumentSymbol *p_parent, const String &symbol_identifier);
const lsp::DocumentSymbol *get_local_symbol_at(const ExtendGDScriptParser *p_parser, const String &p_symbol_identifier, const lsp::Position p_position);
const LSP::DocumentSymbol *get_native_symbol(const String &p_class, const String &p_member = "") const;
const LSP::DocumentSymbol *get_script_symbol(const String &p_path) const;
const LSP::DocumentSymbol *get_parameter_symbol(const LSP::DocumentSymbol *p_parent, const String &symbol_identifier);
const LSP::DocumentSymbol *get_local_symbol_at(const ExtendGDScriptParser *p_parser, const String &p_symbol_identifier, const LSP::Position p_position);
void reload_all_workspace_scripts();
@@ -82,19 +82,19 @@ public:
String get_file_uri(const String &p_path) const;
void publish_diagnostics(const String &p_path);
void completion(const lsp::CompletionParams &p_params, List<ScriptLanguage::CodeCompletionOption> *r_options);
void completion(const LSP::CompletionParams &p_params, List<ScriptLanguage::CodeCompletionOption> *r_options);
const lsp::DocumentSymbol *resolve_symbol(const lsp::TextDocumentPositionParams &p_doc_pos, const String &p_symbol_name = "", bool p_func_required = false);
void resolve_related_symbols(const lsp::TextDocumentPositionParams &p_doc_pos, List<const lsp::DocumentSymbol *> &r_list);
const lsp::DocumentSymbol *resolve_native_symbol(const lsp::NativeSymbolInspectParams &p_params);
void resolve_document_links(const String &p_uri, List<lsp::DocumentLink> &r_list);
const LSP::DocumentSymbol *resolve_symbol(const LSP::TextDocumentPositionParams &p_doc_pos, const String &p_symbol_name = "", bool p_func_required = false);
void resolve_related_symbols(const LSP::TextDocumentPositionParams &p_doc_pos, List<const LSP::DocumentSymbol *> &r_list);
const LSP::DocumentSymbol *resolve_native_symbol(const LSP::NativeSymbolInspectParams &p_params);
void resolve_document_links(const String &p_uri, List<LSP::DocumentLink> &r_list);
Dictionary generate_script_api(const String &p_path);
Error resolve_signature(const lsp::TextDocumentPositionParams &p_doc_pos, lsp::SignatureHelp &r_signature);
Error resolve_signature(const LSP::TextDocumentPositionParams &p_doc_pos, LSP::SignatureHelp &r_signature);
void did_delete_files(const Dictionary &p_params);
Dictionary rename(const lsp::TextDocumentPositionParams &p_doc_pos, const String &new_name);
bool can_rename(const lsp::TextDocumentPositionParams &p_doc_pos, lsp::DocumentSymbol &r_symbol, lsp::Range &r_range);
Vector<lsp::Location> find_usages_in_file(const lsp::DocumentSymbol &p_symbol, const String &p_file_path);
Vector<lsp::Location> find_all_usages(const lsp::DocumentSymbol &p_symbol);
Dictionary rename(const LSP::TextDocumentPositionParams &p_doc_pos, const String &new_name);
bool can_rename(const LSP::TextDocumentPositionParams &p_doc_pos, LSP::DocumentSymbol &r_symbol, LSP::Range &r_range);
Vector<LSP::Location> find_usages_in_file(const LSP::DocumentSymbol &p_symbol, const String &p_file_path);
Vector<LSP::Location> find_all_usages(const LSP::DocumentSymbol &p_symbol);
GDScriptWorkspace();
~GDScriptWorkspace();

View File

@@ -34,7 +34,7 @@
#include "core/object/class_db.h"
#include "core/templates/list.h"
namespace lsp {
namespace LSP {
typedef String DocumentUri;
@@ -383,7 +383,7 @@ struct Command {
};
// Use namespace instead of enumeration to follow the LSP specifications.
// `lsp::EnumName::EnumValue` is OK but `lsp::EnumValue` is not.
// `LSP::EnumName::EnumValue` is OK but `LSP::EnumValue` is not.
namespace TextDocumentSyncKind {
/**
@@ -860,7 +860,7 @@ struct MarkupContent {
};
// Use namespace instead of enumeration to follow the LSP specifications
// `lsp::EnumName::EnumValue` is OK but `lsp::EnumValue` is not.
// `LSP::EnumName::EnumValue` is OK but `LSP::EnumValue` is not.
// And here C++ compilers are unhappy with our enumeration name like `Color`, `File`, `RefCounted` etc.
/**
* The kind of a completion entry.
@@ -1117,7 +1117,7 @@ struct CompletionList {
};
// Use namespace instead of enumeration to follow the LSP specifications
// `lsp::EnumName::EnumValue` is OK but `lsp::EnumValue` is not
// `LSP::EnumName::EnumValue` is OK but `LSP::EnumValue` is not
// And here C++ compilers are unhappy with our enumeration name like `String`, `Array`, `Object` etc
/**
* A symbol kind.
@@ -1258,7 +1258,7 @@ struct DocumentSymbol {
}
_FORCE_INLINE_ CompletionItem make_completion_item(bool resolved = false) const {
lsp::CompletionItem item;
LSP::CompletionItem item;
item.label = name;
if (resolved) {
@@ -1266,33 +1266,33 @@ struct DocumentSymbol {
}
switch (kind) {
case lsp::SymbolKind::Enum:
item.kind = lsp::CompletionItemKind::Enum;
case LSP::SymbolKind::Enum:
item.kind = LSP::CompletionItemKind::Enum;
break;
case lsp::SymbolKind::Class:
item.kind = lsp::CompletionItemKind::Class;
case LSP::SymbolKind::Class:
item.kind = LSP::CompletionItemKind::Class;
break;
case lsp::SymbolKind::Property:
item.kind = lsp::CompletionItemKind::Property;
case LSP::SymbolKind::Property:
item.kind = LSP::CompletionItemKind::Property;
break;
case lsp::SymbolKind::Method:
case lsp::SymbolKind::Function:
item.kind = lsp::CompletionItemKind::Method;
case LSP::SymbolKind::Method:
case LSP::SymbolKind::Function:
item.kind = LSP::CompletionItemKind::Method;
break;
case lsp::SymbolKind::Event:
item.kind = lsp::CompletionItemKind::Event;
case LSP::SymbolKind::Event:
item.kind = LSP::CompletionItemKind::Event;
break;
case lsp::SymbolKind::Constant:
item.kind = lsp::CompletionItemKind::Constant;
case LSP::SymbolKind::Constant:
item.kind = LSP::CompletionItemKind::Constant;
break;
case lsp::SymbolKind::Variable:
item.kind = lsp::CompletionItemKind::Variable;
case LSP::SymbolKind::Variable:
item.kind = LSP::CompletionItemKind::Variable;
break;
case lsp::SymbolKind::File:
item.kind = lsp::CompletionItemKind::File;
case LSP::SymbolKind::File:
item.kind = LSP::CompletionItemKind::File;
break;
default:
item.kind = lsp::CompletionItemKind::Text;
item.kind = LSP::CompletionItemKind::Text;
break;
}
@@ -1952,4 +1952,4 @@ static String marked_documentation(const String &p_bbcode) {
}
return markdown;
}
} // namespace lsp
} // namespace LSP

View File

@@ -55,15 +55,15 @@
#include "thirdparty/doctest/doctest.h"
template <>
struct doctest::StringMaker<lsp::Position> {
static doctest::String convert(const lsp::Position &p_val) {
struct doctest::StringMaker<LSP::Position> {
static doctest::String convert(const LSP::Position &p_val) {
return p_val.to_string().utf8().get_data();
}
};
template <>
struct doctest::StringMaker<lsp::Range> {
static doctest::String convert(const lsp::Range &p_val) {
struct doctest::StringMaker<LSP::Range> {
static doctest::String convert(const LSP::Range &p_val) {
return p_val.to_string().utf8().get_data();
}
};
@@ -105,32 +105,32 @@ GDScriptLanguageProtocol *initialize(const String &p_root) {
return proto;
}
lsp::Position pos(const int p_line, const int p_character) {
lsp::Position p;
LSP::Position pos(const int p_line, const int p_character) {
LSP::Position p;
p.line = p_line;
p.character = p_character;
return p;
}
lsp::Range range(const lsp::Position p_start, const lsp::Position p_end) {
lsp::Range r;
LSP::Range range(const LSP::Position p_start, const LSP::Position p_end) {
LSP::Range r;
r.start = p_start;
r.end = p_end;
return r;
}
lsp::TextDocumentPositionParams pos_in(const lsp::DocumentUri &p_uri, const lsp::Position p_pos) {
lsp::TextDocumentPositionParams params;
LSP::TextDocumentPositionParams pos_in(const LSP::DocumentUri &p_uri, const LSP::Position p_pos) {
LSP::TextDocumentPositionParams params;
params.textDocument.uri = p_uri;
params.position = p_pos;
return params;
}
const lsp::DocumentSymbol *test_resolve_symbol_at(const String &p_uri, const lsp::Position p_pos, const String &p_expected_uri, const String &p_expected_name, const lsp::Range &p_expected_range) {
const LSP::DocumentSymbol *test_resolve_symbol_at(const String &p_uri, const LSP::Position p_pos, const String &p_expected_uri, const String &p_expected_name, const LSP::Range &p_expected_range) {
Ref<GDScriptWorkspace> workspace = GDScriptLanguageProtocol::get_singleton()->get_workspace();
lsp::TextDocumentPositionParams params = pos_in(p_uri, p_pos);
const lsp::DocumentSymbol *symbol = workspace->resolve_symbol(params);
LSP::TextDocumentPositionParams params = pos_in(p_uri, p_pos);
const LSP::DocumentSymbol *symbol = workspace->resolve_symbol(params);
CHECK(symbol);
if (symbol) {
@@ -143,7 +143,7 @@ const lsp::DocumentSymbol *test_resolve_symbol_at(const String &p_uri, const lsp
}
struct InlineTestData {
lsp::Range range;
LSP::Range range;
String text;
String name;
String ref;
@@ -260,7 +260,7 @@ void test_resolve_symbol(const String &p_uri, const InlineTestData &p_test_data,
REQUIRE_MESSAGE(target, vformat("No target for ref '%s'", p_test_data.ref));
Ref<GDScriptWorkspace> workspace = GDScriptLanguageProtocol::get_singleton()->get_workspace();
lsp::Position pos = p_test_data.range.start;
LSP::Position pos = p_test_data.range.start;
SUBCASE("start of identifier") {
pos.character = p_test_data.range.start.character;
@@ -311,17 +311,17 @@ void assert_no_errors_in(const String &p_path) {
REQUIRE_MESSAGE(err == OK, vformat("Errors while analyzing '%s'", p_path));
}
inline lsp::Position lsp_pos(int line, int character) {
lsp::Position p;
inline LSP::Position lsp_pos(int line, int character) {
LSP::Position p;
p.line = line;
p.character = character;
return p;
}
void test_position_roundtrip(lsp::Position p_lsp, GodotPosition p_gd, const PackedStringArray &p_lines) {
void test_position_roundtrip(LSP::Position p_lsp, GodotPosition p_gd, const PackedStringArray &p_lines) {
GodotPosition actual_gd = GodotPosition::from_lsp(p_lsp, p_lines);
CHECK_EQ(p_gd, actual_gd);
lsp::Position actual_lsp = p_gd.to_lsp(p_lines);
LSP::Position actual_lsp = p_gd.to_lsp(p_lines);
CHECK_EQ(p_lsp, actual_lsp);
}
@@ -346,25 +346,25 @@ func f():
PackedStringArray lines = code.split("\n");
SUBCASE("line after end") {
lsp::Position lsp = lsp_pos(7, 0);
LSP::Position lsp = lsp_pos(7, 0);
GodotPosition gd(8, 1);
test_position_roundtrip(lsp, gd, lines);
}
SUBCASE("first char in first line") {
lsp::Position lsp = lsp_pos(0, 0);
LSP::Position lsp = lsp_pos(0, 0);
GodotPosition gd(1, 1);
test_position_roundtrip(lsp, gd, lines);
}
SUBCASE("with tabs") {
// On `v` in `value` in `var value := ...`.
lsp::Position lsp = lsp_pos(5, 6);
LSP::Position lsp = lsp_pos(5, 6);
GodotPosition gd(6, 13);
test_position_roundtrip(lsp, gd, lines);
}
SUBCASE("doesn't fail with column outside of character length") {
lsp::Position lsp = lsp_pos(2, 100);
LSP::Position lsp = lsp_pos(2, 100);
GodotPosition::from_lsp(lsp, lines);
GodotPosition gd(3, 100);
@@ -372,7 +372,7 @@ func f():
}
SUBCASE("doesn't fail with line outside of line length") {
lsp::Position lsp = lsp_pos(200, 100);
LSP::Position lsp = lsp_pos(200, 100);
GodotPosition::from_lsp(lsp, lines);
GodotPosition gd(300, 100);
@@ -381,26 +381,26 @@ func f():
SUBCASE("special case: zero column for root class") {
GodotPosition gd(1, 0);
lsp::Position expected = lsp_pos(0, 0);
lsp::Position actual = gd.to_lsp(lines);
LSP::Position expected = lsp_pos(0, 0);
LSP::Position actual = gd.to_lsp(lines);
CHECK_EQ(actual, expected);
}
SUBCASE("special case: zero line and column for root class") {
GodotPosition gd(0, 0);
lsp::Position expected = lsp_pos(0, 0);
lsp::Position actual = gd.to_lsp(lines);
LSP::Position expected = lsp_pos(0, 0);
LSP::Position actual = gd.to_lsp(lines);
CHECK_EQ(actual, expected);
}
SUBCASE("special case: negative line for root class") {
GodotPosition gd(-1, 0);
lsp::Position expected = lsp_pos(0, 0);
lsp::Position actual = gd.to_lsp(lines);
LSP::Position expected = lsp_pos(0, 0);
LSP::Position actual = gd.to_lsp(lines);
CHECK_EQ(actual, expected);
}
SUBCASE("special case: lines.length() + 1 for root class") {
GodotPosition gd(lines.size() + 1, 0);
lsp::Position expected = lsp_pos(lines.size(), 0);
lsp::Position actual = gd.to_lsp(lines);
LSP::Position expected = lsp_pos(lines.size(), 0);
LSP::Position actual = gd.to_lsp(lines);
CHECK_EQ(actual, expected);
}
}
@@ -502,7 +502,7 @@ func f():
GDScriptLanguageProtocol::get_singleton()->get_workspace()->parse_local_script(path);
ExtendGDScriptParser *parser = GDScriptLanguageProtocol::get_singleton()->get_workspace()->parse_results[path];
REQUIRE(parser);
lsp::DocumentSymbol cls = parser->get_symbols();
LSP::DocumentSymbol cls = parser->get_symbols();
REQUIRE(((cls.range.start.line == cls.selectionRange.start.line && cls.range.start.character <= cls.selectionRange.start.character) || (cls.range.start.line < cls.selectionRange.start.line)));
REQUIRE(((cls.range.end.line == cls.selectionRange.end.line && cls.range.end.character >= cls.selectionRange.end.character) || (cls.range.end.line > cls.selectionRange.end.line)));