Merge pull request #117946 from HolonProduction/editor-language-kickoff
Introduce `EditorLanguage` and move `ScriptLanguage::complete_code` into it.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/**************************************************************************/
|
||||
/* gdscript_editor_language.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/object/editor_language.h"
|
||||
|
||||
class GDScriptEditorLanguage final : public EditorLanguage {
|
||||
static GDScriptEditorLanguage *singleton;
|
||||
|
||||
public:
|
||||
_FORCE_INLINE_ static GDScriptEditorLanguage *get_singleton() { return singleton; }
|
||||
|
||||
virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_force, String &r_call_hint) override;
|
||||
|
||||
GDScriptEditorLanguage() {
|
||||
ERR_FAIL_COND(singleton != nullptr);
|
||||
singleton = this;
|
||||
}
|
||||
~GDScriptEditorLanguage() {
|
||||
if (singleton == this) {
|
||||
singleton = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -590,6 +590,10 @@ public:
|
||||
virtual void finish() override;
|
||||
|
||||
/* EDITOR FUNCTIONS */
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual EditorLanguage *get_editor_language() override;
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
virtual Vector<String> get_reserved_words() const override;
|
||||
virtual bool is_control_flow_keyword(const String &p_keywords) const override;
|
||||
virtual Vector<String> get_comment_delimiters() const override;
|
||||
@@ -604,7 +608,6 @@ public:
|
||||
virtual bool can_inherit_from_file() const override { return true; }
|
||||
virtual int find_function(const String &p_function, const String &p_code) const override;
|
||||
virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const override;
|
||||
virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) override;
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) override;
|
||||
#endif
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "editor/gdscript_docgen.h"
|
||||
#include "editor/gdscript_editor_language.h"
|
||||
#include "editor/script_templates/templates.gen.h"
|
||||
#endif
|
||||
|
||||
@@ -55,6 +56,14 @@
|
||||
#include "editor/settings/editor_settings.h"
|
||||
#endif
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
GDScriptEditorLanguage *GDScriptEditorLanguage::singleton = nullptr;
|
||||
|
||||
EditorLanguage *GDScriptLanguage::get_editor_language() {
|
||||
return GDScriptEditorLanguage::get_singleton();
|
||||
}
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
Vector<String> GDScriptLanguage::get_comment_delimiters() const {
|
||||
static const Vector<String> delimiters = { "#" };
|
||||
return delimiters;
|
||||
@@ -3430,7 +3439,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
|
||||
r_forced = r_result.size() > 0;
|
||||
}
|
||||
|
||||
::Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) {
|
||||
::Error GDScriptEditorLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) {
|
||||
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
|
||||
|
||||
GDScriptParser parser;
|
||||
@@ -3621,7 +3630,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
|
||||
|
||||
HashMap<String, ScriptLanguage::CodeCompletionOption> opt;
|
||||
_find_identifiers_in_base(base, false, false, false, opt, 0);
|
||||
for (const KeyValue<String, CodeCompletionOption> &E : opt) {
|
||||
for (const KeyValue<String, ScriptLanguage::CodeCompletionOption> &E : opt) {
|
||||
ScriptLanguage::CodeCompletionOption option = _calculate_string_insertion(existing_index, E.value.insert_text);
|
||||
option.kind = E.value.kind;
|
||||
option.location = E.value.location;
|
||||
@@ -3856,13 +3865,6 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#else // !TOOLS_ENABLED
|
||||
|
||||
Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
//////// END COMPLETION //////////
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "gdscript_workspace.h"
|
||||
|
||||
#include "../editor/gdscript_editor_language.h"
|
||||
#include "../gdscript.h"
|
||||
#include "../gdscript_parser.h"
|
||||
#include "gdscript_language_protocol.h"
|
||||
@@ -637,7 +638,7 @@ void GDScriptWorkspace::completion(const LSP::CompletionParams &p_params, List<S
|
||||
}
|
||||
|
||||
String code = parser->get_text_for_completion(p_params.position);
|
||||
GDScriptLanguage::get_singleton()->complete_code(code, path, current, r_options, forced, call_hint);
|
||||
GDScriptEditorLanguage::get_singleton()->complete_code(code, path, current, r_options, forced, call_hint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "gdscript_utility_functions.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "editor/gdscript_editor_language.h"
|
||||
#include "editor/gdscript_highlighter.h"
|
||||
#include "editor/gdscript_translation_parser_plugin.h"
|
||||
#include "editor/script/script_editor_plugin.h"
|
||||
@@ -160,6 +161,8 @@ void initialize_gdscript_module(ModuleInitializationLevel p_level) {
|
||||
gdscript_translation_parser_plugin.instantiate();
|
||||
EditorTranslationParser::get_singleton()->add_parser(gdscript_translation_parser_plugin, EditorTranslationParser::STANDARD);
|
||||
} else if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
|
||||
memnew(GDScriptEditorLanguage);
|
||||
|
||||
GDREGISTER_CLASS(GDScriptSyntaxHighlighter);
|
||||
#ifndef GDSCRIPT_NO_LSP
|
||||
register_lsp_types();
|
||||
@@ -203,6 +206,7 @@ void uninitialize_gdscript_module(ModuleInitializationLevel p_level) {
|
||||
#ifndef GDSCRIPT_NO_LSP
|
||||
memdelete(GDScriptLanguageProtocol::get_singleton());
|
||||
#endif // GDSCRIPT_NO_LSP
|
||||
memdelete(GDScriptEditorLanguage::get_singleton());
|
||||
}
|
||||
#endif // TOOLS_ENABLED
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "../editor/gdscript_editor_language.h"
|
||||
#include "../gdscript.h"
|
||||
#include "gdscript_test_runner.h"
|
||||
|
||||
@@ -184,7 +185,7 @@ static void test_directory(const String &p_dir) {
|
||||
owner->set_script(scr);
|
||||
}
|
||||
|
||||
GDScriptLanguage::get_singleton()->complete_code(code, res_path, owner, &options, forced, call_hint);
|
||||
GDScriptEditorLanguage::get_singleton()->complete_code(code, res_path, owner, &options, forced, call_hint);
|
||||
ERR_PRINT_ON;
|
||||
|
||||
String contains_excluded;
|
||||
|
||||
Reference in New Issue
Block a user