Removed JSONRPC module.

This commit is contained in:
Relintai 2023-12-14 23:32:45 +01:00
parent 0a384513e8
commit ddf2447835
10 changed files with 1 additions and 487 deletions

View File

@ -91,12 +91,6 @@
#include "editor_code_editor/editor_script_editor.h"
#endif
#ifdef MODULE_GDSCRIPT_ENABLED
#if defined(TOOLS_ENABLED) && !defined(GDSCRIPT_NO_LSP)
#include "modules/gdscript/language_server/gdscript_language_server.h"
#endif // TOOLS_ENABLED && !GDSCRIPT_NO_LSP
#endif // MODULE_GDSCRIPT_ENABLED
/* Static members */
// Singletons
@ -334,9 +328,6 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" -e, --editor Start the editor instead of running the scene.\n");
OS::get_singleton()->print(" -p, --project-manager Start the project manager, even if a project is auto-detected.\n");
OS::get_singleton()->print(" --debug-server <address> Start the editor debug server (<IP>:<port>, e.g. 127.0.0.1:6007)\n");
#if defined(MODULE_GDSCRIPT_ENABLED) && !defined(GDSCRIPT_NO_LSP)
OS::get_singleton()->print(" --lsp-port <port> Use the specified port for the language server protocol. The port must be between 0 to 65535.\n");
#endif // MODULE_GDSCRIPT_ENABLED && !GDSCRIPT_NO_LSP
#endif
OS::get_singleton()->print(" -q, --quit Quit after the first iteration.\n");
OS::get_singleton()->print(" -l, --language <locale> Use a specific locale (<locale> being a two-letter code).\n");
@ -981,21 +972,6 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->print("Missing <path> argument for --benchmark-file <path>.\n");
goto error;
}
#if defined(TOOLS_ENABLED) && !defined(GDSCRIPT_NO_LSP)
} else if (I->get() == "--lsp-port") {
if (I->next()) {
int port_override = I->next()->get().to_int();
if (port_override < 0 || port_override > 65535) {
OS::get_singleton()->print("<port> argument for --lsp-port <port> must be between 0 and 65535.\n");
goto error;
}
GDScriptLanguageServer::port_override = port_override;
N = I->next()->next();
} else {
OS::get_singleton()->print("Missing <port> argument for --lsp-port <port>.\n");
goto error;
}
#endif // TOOLS_ENABLED && !GDSCRIPT_NO_LSP
} else {
main_args.push_back(I->get());
}

View File

@ -9,11 +9,4 @@ env_gdscript.add_source_files(env.modules_sources, "*.cpp")
if env["tools"]:
env_gdscript.add_source_files(env.modules_sources, "./editor/*.cpp")
# Those two modules are required for the language server protocol
if env["module_jsonrpc_enabled"] and env["module_websocket_enabled"]:
env_gdscript.add_source_files(env.modules_sources, "./language_server/*.cpp")
else:
# Using a define in the disabled case, to avoid having an extra define
# in regular builds where all modules are enabled.
env_gdscript.Append(CPPDEFINES=["GDSCRIPT_NO_LSP"])

View File

@ -49,11 +49,6 @@ Ref<ResourceFormatSaverGDScript> resource_saver_gd;
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#ifndef GDSCRIPT_NO_LSP
#include "core/config/engine.h"
#include "language_server/gdscript_language_server.h"
#endif // !GDSCRIPT_NO_LSP
class EditorExportGDScript : public EditorExportPlugin {
GDCLASS(EditorExportGDScript, EditorExportPlugin);
@ -138,13 +133,6 @@ 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
}
#endif // TOOLS_ENABLED

View File

@ -1,7 +0,0 @@
#!/usr/bin/env python
Import("env")
Import("env_modules")
env_jsonrpc = env_modules.Clone()
env_jsonrpc.add_source_files(env.modules_sources, "*.cpp")

View File

@ -1,14 +0,0 @@
def can_build(env, platform):
return True
def configure(env):
pass
def get_doc_classes():
return [
"JSONRPC",
]
def get_doc_path():
return "doc_classes"

View File

@ -1,93 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="JSONRPC" inherits="Object" version="4.2">
<brief_description>
A helper to handle dictionaries which look like JSONRPC documents.
</brief_description>
<description>
[url=https://www.jsonrpc.org/]JSON-RPC[/url] is a standard which wraps a method call in a [JSON] object. The object has a particular structure and identifies which method is called, the parameters to that function, and carries an ID to keep track of responses. This class implements that standard on top of [Dictionary]; you will have to convert between a [Dictionary] and [JSON] with other functions.
</description>
<tutorials>
</tutorials>
<methods>
<method name="make_notification">
<return type="Dictionary" />
<argument index="0" name="method" type="String" />
<argument index="1" name="params" type="Variant" />
<description>
Returns a dictionary in the form of a JSON-RPC notification. Notifications are one-shot messages which do not expect a response.
- [code]method[/code]: Name of the method being called.
- [code]params[/code]: An array or dictionary of parameters being passed to the method.
</description>
</method>
<method name="make_request">
<return type="Dictionary" />
<argument index="0" name="method" type="String" />
<argument index="1" name="params" type="Variant" />
<argument index="2" name="id" type="Variant" />
<description>
Returns a dictionary in the form of a JSON-RPC request. Requests are sent to a server with the expectation of a response. The ID field is used for the server to specify which exact request it is responding to.
- [code]method[/code]: Name of the method being called.
- [code]params[/code]: An array or dictionary of parameters being passed to the method.
- [code]id[/code]: Uniquely identifies this request. The server is expected to send a response with the same ID.
</description>
</method>
<method name="make_response">
<return type="Dictionary" />
<argument index="0" name="result" type="Variant" />
<argument index="1" name="id" type="Variant" />
<description>
When a server has received and processed a request, it is expected to send a response. If you did not want a response then you need to have sent a Notification instead.
- [code]result[/code]: The return value of the function which was called.
- [code]id[/code]: The ID of the request this response is targeted to.
</description>
</method>
<method name="make_response_error" qualifiers="const">
<return type="Dictionary" />
<argument index="0" name="code" type="int" />
<argument index="1" name="message" type="String" />
<argument index="2" name="id" type="Variant" default="null" />
<description>
Creates a response which indicates a previous reply has failed in some way.
- [code]code[/code]: The error code corresponding to what kind of error this is. See the [enum ErrorCode] constants.
- [code]message[/code]: A custom message about this error.
- [code]id[/code]: The request this error is a response to.
</description>
</method>
<method name="process_action">
<return type="Variant" />
<argument index="0" name="action" type="Variant" />
<argument index="1" name="recurse" type="bool" default="false" />
<description>
Given a Dictionary which takes the form of a JSON-RPC request: unpack the request and run it. Methods are resolved by looking at the field called "method" and looking for an equivalently named function in the JSONRPC object. If one is found that method is called.
To add new supported methods extend the JSONRPC class and call [method process_action] on your subclass.
[code]action[/code]: The action to be run, as a Dictionary in the form of a JSON-RPC request or notification.
</description>
</method>
<method name="process_string">
<return type="String" />
<argument index="0" name="action" type="String" />
<description>
</description>
</method>
<method name="set_scope">
<return type="void" />
<argument index="0" name="scope" type="String" />
<argument index="1" name="target" type="Object" />
<description>
</description>
</method>
</methods>
<constants>
<constant name="PARSE_ERROR" value="-32700" enum="ErrorCode">
</constant>
<constant name="INVALID_REQUEST" value="-32600" enum="ErrorCode">
</constant>
<constant name="METHOD_NOT_FOUND" value="-32601" enum="ErrorCode">
A method call was requested but no function of that name existed in the JSONRPC subclass.
</constant>
<constant name="INVALID_PARAMS" value="-32602" enum="ErrorCode">
</constant>
<constant name="INTERNAL_ERROR" value="-32603" enum="ErrorCode">
</constant>
</constants>
</class>

View File

@ -1,176 +0,0 @@
/**************************************************************************/
/* jsonrpc.cpp */
/**************************************************************************/
/* 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. */
/**************************************************************************/
#include "jsonrpc.h"
#include "core/io/json.h"
JSONRPC::JSONRPC() {
}
JSONRPC::~JSONRPC() {
}
void JSONRPC::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_scope", "scope", "target"), &JSONRPC::set_scope);
ClassDB::bind_method(D_METHOD("process_action", "action", "recurse"), &JSONRPC::process_action, DEFVAL(false));
ClassDB::bind_method(D_METHOD("process_string", "action"), &JSONRPC::process_string);
ClassDB::bind_method(D_METHOD("make_request", "method", "params", "id"), &JSONRPC::make_request);
ClassDB::bind_method(D_METHOD("make_response", "result", "id"), &JSONRPC::make_response);
ClassDB::bind_method(D_METHOD("make_notification", "method", "params"), &JSONRPC::make_notification);
ClassDB::bind_method(D_METHOD("make_response_error", "code", "message", "id"), &JSONRPC::make_response_error, DEFVAL(Variant()));
BIND_ENUM_CONSTANT(PARSE_ERROR);
BIND_ENUM_CONSTANT(INVALID_REQUEST);
BIND_ENUM_CONSTANT(METHOD_NOT_FOUND);
BIND_ENUM_CONSTANT(INVALID_PARAMS);
BIND_ENUM_CONSTANT(INTERNAL_ERROR);
}
Dictionary JSONRPC::make_response_error(int p_code, const String &p_message, const Variant &p_id) const {
Dictionary dict;
dict["jsonrpc"] = "2.0";
Dictionary err;
err["code"] = p_code;
err["message"] = p_message;
dict["error"] = err;
dict["id"] = p_id;
return dict;
}
Dictionary JSONRPC::make_response(const Variant &p_value, const Variant &p_id) {
Dictionary dict;
dict["jsonrpc"] = "2.0";
dict["id"] = p_id;
dict["result"] = p_value;
return dict;
}
Dictionary JSONRPC::make_notification(const String &p_method, const Variant &p_params) {
Dictionary dict;
dict["jsonrpc"] = "2.0";
dict["method"] = p_method;
dict["params"] = p_params;
return dict;
}
Dictionary JSONRPC::make_request(const String &p_method, const Variant &p_params, const Variant &p_id) {
Dictionary dict;
dict["jsonrpc"] = "2.0";
dict["method"] = p_method;
dict["params"] = p_params;
dict["id"] = p_id;
return dict;
}
Variant JSONRPC::process_action(const Variant &p_action, bool p_process_arr_elements) {
Variant ret;
if (p_action.get_type() == Variant::DICTIONARY) {
Dictionary dict = p_action;
String method = dict.get("method", "");
if (method.begins_with("$/")) {
return ret;
}
Array args;
if (dict.has("params")) {
Variant params = dict.get("params", Variant());
if (params.get_type() == Variant::ARRAY) {
args = params;
} else {
args.push_back(params);
}
}
Object *object = this;
if (method_scopes.has(method.get_base_dir())) {
object = method_scopes[method.get_base_dir()];
method = method.get_file();
}
Variant id;
if (dict.has("id")) {
id = dict["id"];
}
if (object == nullptr || !object->has_method(method)) {
ret = make_response_error(JSONRPC::METHOD_NOT_FOUND, "Method not found: " + method, id);
} else {
Variant call_ret = object->callv(method, args);
if (id.get_type() != Variant::NIL) {
ret = make_response(call_ret, id);
}
}
} else if (p_action.get_type() == Variant::ARRAY && p_process_arr_elements) {
Array arr = p_action;
int size = arr.size();
if (size) {
Array arr_ret;
for (int i = 0; i < size; i++) {
const Variant &var = arr.get(i);
arr_ret.push_back(process_action(var));
}
ret = arr_ret;
} else {
ret = make_response_error(JSONRPC::INVALID_REQUEST, "Invalid Request");
}
} else {
ret = make_response_error(JSONRPC::INVALID_REQUEST, "Invalid Request");
}
return ret;
}
String JSONRPC::process_string(const String &p_input) {
if (p_input.empty()) {
return String();
}
Variant ret;
Variant input;
String err_message;
int err_line;
if (OK != JSON::parse(p_input, input, err_message, err_line)) {
ret = make_response_error(JSONRPC::PARSE_ERROR, "Parse error");
} else {
ret = process_action(input, true);
}
if (ret.get_type() == Variant::NIL) {
return "";
}
return JSON::print(ret);
}
void JSONRPC::set_scope(const String &p_scope, Object *p_obj) {
method_scopes[p_scope] = p_obj;
}

View File

@ -1,70 +0,0 @@
/**************************************************************************/
/* jsonrpc.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. */
/**************************************************************************/
#ifndef JSONRPC_H
#define JSONRPC_H
#include "core/object/object.h"
#include "core/variant/variant.h"
class JSONRPC : public Object {
GDCLASS(JSONRPC, Object)
RBMap<String, Object *> method_scopes;
protected:
static void _bind_methods();
public:
JSONRPC();
~JSONRPC();
enum ErrorCode {
PARSE_ERROR = -32700,
INVALID_REQUEST = -32600,
METHOD_NOT_FOUND = -32601,
INVALID_PARAMS = -32602,
INTERNAL_ERROR = -32603,
};
Dictionary make_response_error(int p_code, const String &p_message, const Variant &p_id = Variant()) const;
Dictionary make_response(const Variant &p_value, const Variant &p_id);
Dictionary make_notification(const String &p_method, const Variant &p_params);
Dictionary make_request(const String &p_method, const Variant &p_params, const Variant &p_id);
Variant process_action(const Variant &p_action, bool p_process_arr_elements = false);
String process_string(const String &p_input);
void set_scope(const String &p_scope, Object *p_obj);
};
VARIANT_ENUM_CAST(JSONRPC::ErrorCode);
#endif // JSONRPC_H

View File

@ -1,44 +0,0 @@
/**************************************************************************/
/* register_types.cpp */
/**************************************************************************/
/* 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. */
/**************************************************************************/
#include "register_types.h"
#include "core/object/class_db.h"
#include "jsonrpc.h"
void register_jsonrpc_types(ModuleRegistrationLevel p_level) {
if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) {
ClassDB::register_class<JSONRPC>();
}
}
void unregister_jsonrpc_types(ModuleRegistrationLevel p_level) {
}

View File

@ -1,39 +0,0 @@
/**************************************************************************/
/* register_types.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. */
/**************************************************************************/
#ifndef JSONRPC_REGISTER_TYPES_H
#define JSONRPC_REGISTER_TYPES_H
#include "modules/register_module_types.h"
void register_jsonrpc_types(ModuleRegistrationLevel p_level);
void unregister_jsonrpc_types(ModuleRegistrationLevel p_level);
#endif // JSONRPC_REGISTER_TYPES_H