Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDScriptLanguageProtocol singleton not properly recognized as identifier #52162

Open
Gallilus opened this issue Aug 27, 2021 · 4 comments
Open

Comments

@Gallilus
Copy link
Contributor

Godot version

3.4.beta3

System information

Windows 10

Issue description

NavigationMeshGenerator singleton is not displayed green.
GDScriptLanguageProtocol singleton Identifier not found: GDScriptLanguageProtocol
image

Steps to reproduce

var engine_singletons := [
		Performance,
		ProjectSettings,
		IP,
		Geometry,
		ResourceFormatLoader,
		ResourceFormatSaver,
		OS,
		Engine,
		ClassDB,
		Marshalls,
		TranslationServer,
		Input,
		InputMap,
		JSON,
		JavaClassWrapper,
		JavaScript,
		NavigationMeshGenerator,
		VisualScriptEditor,
		VisualServer,
		PhysicsServer,
		Physics2DServer,
		ARVRServer,
		CameraServer,
		#GDScriptLanguageProtocol,
]
#	print(Engine.has_singleton("NavigationMeshGenerator")) # prints True
#	print(Engine.has_singleton("GDScriptLanguageProtocol")) # prints True

Minimal reproduction project

N-A

@Calinou Calinou added this to the 3.4 milestone Aug 27, 2021
@akien-mga akien-mga changed the title GDscript Singletons recognitions GDscript Singletons NavigationMeshGenerator and GDScriptLanguageProtocol not properly recognized Sep 14, 2021
@akien-mga
Copy link
Member

NavigationMeshGenerator singleton is not displayed green.

This is because NavigationMeshGenerator is not a class name, as the class of that singleton property is actually EditorNavigationMeshGenerator. That's the only case of a discrepancy between the singleton name and the class name, which is why it's the only one not displayed correctly.

The syntax highlighter should likely have custom code to handle singletons specifically, and not just classes.

GDScriptLanguageProtocol singleton Identifier not found: GDScriptLanguageProtocol

That one is weird as it seems to be properly registered as singleton. It's registered in the Core API when it should likely be in the Editor API only (only available in tool scripts), which can be fixed with this patch:

diff --git a/modules/gdscript/language_server/gdscript_language_server.cpp b/modules/gdscript/language_server/gdscript_language_server.cpp
index 12ed56a568..63b305ad82 100644
--- a/modules/gdscript/language_server/gdscript_language_server.cpp
+++ b/modules/gdscript/language_server/gdscript_language_server.cpp
@@ -106,7 +106,9 @@ void GDScriptLanguageServer::stop() {
 }
 
 void register_lsp_types() {
+       ClassDB::set_current_api(ClassDB::API_EDITOR);
        ClassDB::register_class<GDScriptLanguageProtocol>();
        ClassDB::register_class<GDScriptTextDocument>();
        ClassDB::register_class<GDScriptWorkspace>();
+       ClassDB::set_current_api(ClassDB::API_CORE);
 }

But that doesn't solve the GDScript error when trying to use the identifier in a tool script. Maybe the registration happens too late? CC @vnen

@akien-mga
Copy link
Member

The GDScriptLanguageProtocol issue is valid in master too.

The NavigationMeshGenerator highlighting seems solved in master (the class was renamed) and should thus likely not be fixed in 3.4 which would break compat.

There's now an issue with VisualScriptEditor similar to NavigationMeshGenerator, because the class was renamed and not the singleton (see #51916 and follow-ups, CC @mhilbrunner).

@akien-mga akien-mga modified the milestones: 3.4, 4.0 Sep 14, 2021
@akien-mga akien-mga changed the title GDscript Singletons NavigationMeshGenerator and GDScriptLanguageProtocol not properly recognized GDScriptLanguageProtocol singleton not properly recognized as identifier Sep 14, 2021
akien-mga added a commit to akien-mga/godot that referenced this issue Sep 14, 2021
Follow-up to godotengine#51916, fixes inconsistency between singleton name and class
as documented in godotengine#52162 (comment).
@akien-mga
Copy link
Member

There's now an issue with VisualScriptEditor similar to NavigationMeshGenerator, because the class was renamed and not the singleton (see #51916 and follow-ups, CC @mhilbrunner).

This is fixed by #52656, so I repurposed this issue to focus only on the GDScriptLanguageProtocol issue.

@vnen
Copy link
Member

vnen commented Sep 14, 2021

It seems the issue is that this class and its singleton are registered in the _editor_init() callback:

static void _editor_init() {
Ref<EditorExportGDScript> gd_export;
gd_export.instance();
EditorExport::get_singleton()->add_export_plugin(gd_export);
#ifndef GDSCRIPT_NO_LSP
register_lsp_types();
GDScriptLanguageServer *lsp_plugin = memnew(GDScriptLanguageServer);
EditorNode::get_singleton()->add_editor_plugin(lsp_plugin);
Engine::get_singleton()->add_singleton(Engine::Singleton("GDScriptLanguageProtocol", GDScriptLanguageProtocol::get_singleton()));
#endif // !GDSCRIPT_NO_LSP
}

But this is called quite late, which makes it doesn't appear on the editor help for instance. When running the project this is never called so the class don't get registered all, hence the error.

This registration code should probably be moved to the register_gdscript_types() function.

akien-mga added a commit to godotengine/godot-visual-script that referenced this issue Aug 23, 2022
Follow-up to #51916, fixes inconsistency between singleton name and class
as documented in godotengine/godot#52162 (comment).
@YuriSizov YuriSizov modified the milestones: 4.0, 4.1 Feb 27, 2023
@adamscott adamscott modified the milestones: 4.1, 4.2 Jun 14, 2023
@YuriSizov YuriSizov removed this from the 4.2 milestone Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants