From 15025a4c93e5961f80609a562d4c4ef7f9f1b3f1 Mon Sep 17 00:00:00 2001 From: Francois Belair Date: Sun, 26 Sep 2021 13:15:24 -0400 Subject: [PATCH] Makes LSP report new() as _init; fixes docstrings (cherry picked from commit ae3aec1dbc3c12e0b46b52746e15cbfc6d7e9995) Fix LSP crash parsing scripts of temp size 0 (cherry picked from commit 679ce6fd0bfc53076de9fdb9a9103d0fb08fcfee) --- .../gdscript/language_server/gdscript_extend_parser.cpp | 6 ++++++ modules/gdscript/language_server/gdscript_workspace.cpp | 8 +++++--- modules/gdscript/language_server/gdscript_workspace.h | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp index b7310dbc7d2..2eb38b718c8 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.cpp +++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp @@ -413,6 +413,12 @@ String ExtendGDScriptParser::parse_documentation(int p_line, bool p_docs_down) { doc_lines.push_front(line_comment); } } else { + if (i > 0 && i < lines.size() - 1) { + String next_line = lines[i + step].strip_edges(true, false); + if (next_line.begins_with("#")) { + continue; + } + } break; } } diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index 8f56d41f03c..56f1bca7b5c 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -473,7 +473,7 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, Listlookup_code(parser->get_text_for_lookup_symbol(pos, symbol_identifier, p_func_requred), symbol_identifier, path, NULL, ret)) { - + if (symbol_identifier == "new" && parser->get_lines()[p_doc_pos.position.line].replace(" ", "").replace("\t", "").find("new(") > -1) { + symbol_identifier = "_init"; + } + if (OK == GDScriptLanguage::get_singleton()->lookup_code(parser->get_text_for_lookup_symbol(pos, symbol_identifier, p_func_required), symbol_identifier, path, NULL, ret)) { if (ret.type == ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION) { String target_script_path = path; diff --git a/modules/gdscript/language_server/gdscript_workspace.h b/modules/gdscript/language_server/gdscript_workspace.h index 205b0bc8c66..c46fee3c08e 100644 --- a/modules/gdscript/language_server/gdscript_workspace.h +++ b/modules/gdscript/language_server/gdscript_workspace.h @@ -83,7 +83,7 @@ public: void publish_diagnostics(const String &p_path); void completion(const lsp::CompletionParams &p_params, List *r_options); - const lsp::DocumentSymbol *resolve_symbol(const lsp::TextDocumentPositionParams &p_doc_pos, const String &p_symbol_name = "", bool p_func_requred = false); + 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 &r_list); const lsp::DocumentSymbol *resolve_native_symbol(const lsp::NativeSymbolInspectParams &p_params); void resolve_document_links(const String &p_uri, List &r_list);