You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
JSONRPC: Require manual method registration
This commit is contained in:
@@ -69,11 +69,14 @@
|
|||||||
<description>
|
<description>
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="set_scope">
|
<method name="set_method">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<param index="0" name="scope" type="String" />
|
<param index="0" name="name" type="String" />
|
||||||
<param index="1" name="target" type="Object" />
|
<param index="1" name="callback" type="Callable" />
|
||||||
<description>
|
<description>
|
||||||
|
Registers a callback for the given method name.
|
||||||
|
- [param name] The name that clients can use to access the callback.
|
||||||
|
- [param callback] The callback which will handle the specific method.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
</methods>
|
</methods>
|
||||||
|
|||||||
@@ -24,3 +24,10 @@ Validate extension JSON: Error: Field 'classes/OpenXRAPIExtension/methods/regist
|
|||||||
Validate extension JSON: Error: Field 'classes/OpenXRAPIExtension/methods/unregister_projection_views_extension/arguments/0': type changed value in new API, from "OpenXRExtensionWrapperExtension" to "OpenXRExtensionWrapper".
|
Validate extension JSON: Error: Field 'classes/OpenXRAPIExtension/methods/unregister_projection_views_extension/arguments/0': type changed value in new API, from "OpenXRExtensionWrapperExtension" to "OpenXRExtensionWrapper".
|
||||||
|
|
||||||
Switched from `OpenXRExtensionWrapperExtension` to parent `OpenXRExtensionWrapper`. Compatibility methods registered.
|
Switched from `OpenXRExtensionWrapperExtension` to parent `OpenXRExtensionWrapper`. Compatibility methods registered.
|
||||||
|
|
||||||
|
|
||||||
|
GH-104890
|
||||||
|
---------
|
||||||
|
Validate extension JSON: API was removed: classes/JSONRPC/methods/set_scope
|
||||||
|
|
||||||
|
Replaced `set_scope` with `set_method`. Compatibility method registered for binary compatibility. Manual upgrade required by users to retain functionality.
|
||||||
|
|||||||
@@ -334,13 +334,50 @@ bool GDScriptLanguageProtocol::is_goto_native_symbols_enabled() const {
|
|||||||
return bool(_EDITOR_GET("network/language_server/show_native_symbols_in_editor"));
|
return bool(_EDITOR_GET("network/language_server/show_native_symbols_in_editor"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
#define SET_DOCUMENT_METHOD(m_method) set_method(_STR(textDocument/m_method), callable_mp(text_document.ptr(), &GDScriptTextDocument::m_method))
|
||||||
|
#define SET_COMPLETION_METHOD(m_method) set_method(_STR(completionItem/m_method), callable_mp(text_document.ptr(), &GDScriptTextDocument::m_method))
|
||||||
|
#define SET_WORKSPACE_METHOD(m_method) set_method(_STR(workspace/m_method), callable_mp(workspace.ptr(), &GDScriptWorkspace::m_method))
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
GDScriptLanguageProtocol::GDScriptLanguageProtocol() {
|
GDScriptLanguageProtocol::GDScriptLanguageProtocol() {
|
||||||
server.instantiate();
|
server.instantiate();
|
||||||
singleton = this;
|
singleton = this;
|
||||||
workspace.instantiate();
|
workspace.instantiate();
|
||||||
text_document.instantiate();
|
text_document.instantiate();
|
||||||
set_scope("textDocument", text_document.ptr());
|
|
||||||
set_scope("completionItem", text_document.ptr());
|
SET_DOCUMENT_METHOD(didOpen);
|
||||||
set_scope("workspace", workspace.ptr());
|
SET_DOCUMENT_METHOD(didClose);
|
||||||
|
SET_DOCUMENT_METHOD(didChange);
|
||||||
|
SET_DOCUMENT_METHOD(willSaveWaitUntil);
|
||||||
|
SET_DOCUMENT_METHOD(didSave);
|
||||||
|
|
||||||
|
SET_DOCUMENT_METHOD(documentSymbol);
|
||||||
|
SET_DOCUMENT_METHOD(completion);
|
||||||
|
SET_DOCUMENT_METHOD(rename);
|
||||||
|
SET_DOCUMENT_METHOD(prepareRename);
|
||||||
|
SET_DOCUMENT_METHOD(references);
|
||||||
|
SET_DOCUMENT_METHOD(foldingRange);
|
||||||
|
SET_DOCUMENT_METHOD(codeLens);
|
||||||
|
SET_DOCUMENT_METHOD(documentLink);
|
||||||
|
SET_DOCUMENT_METHOD(colorPresentation);
|
||||||
|
SET_DOCUMENT_METHOD(hover);
|
||||||
|
SET_DOCUMENT_METHOD(definition);
|
||||||
|
SET_DOCUMENT_METHOD(declaration);
|
||||||
|
SET_DOCUMENT_METHOD(signatureHelp);
|
||||||
|
|
||||||
|
SET_DOCUMENT_METHOD(nativeSymbol); // Custom method.
|
||||||
|
|
||||||
|
SET_COMPLETION_METHOD(resolve);
|
||||||
|
|
||||||
|
SET_WORKSPACE_METHOD(didDeleteFiles);
|
||||||
|
|
||||||
|
set_method("initialize", callable_mp(this, &GDScriptLanguageProtocol::initialize));
|
||||||
|
set_method("initialized", callable_mp(this, &GDScriptLanguageProtocol::initialized));
|
||||||
|
|
||||||
workspace->root = ProjectSettings::get_singleton()->get_resource_path();
|
workspace->root = ProjectSettings::get_singleton()->get_resource_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef SET_DOCUMENT_METHOD
|
||||||
|
#undef SET_COMPLETION_METHOD
|
||||||
|
#undef SET_WORKSPACE_METHOD
|
||||||
|
|||||||
@@ -44,6 +44,14 @@ protected:
|
|||||||
|
|
||||||
Ref<FileAccess> file_checker;
|
Ref<FileAccess> file_checker;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
public:
|
||||||
void didOpen(const Variant &p_param);
|
void didOpen(const Variant &p_param);
|
||||||
void didClose(const Variant &p_param);
|
void didClose(const Variant &p_param);
|
||||||
void didChange(const Variant &p_param);
|
void didChange(const Variant &p_param);
|
||||||
@@ -54,14 +62,6 @@ protected:
|
|||||||
void sync_script_content(const String &p_path, const String &p_content);
|
void sync_script_content(const String &p_path, const String &p_content);
|
||||||
void show_native_symbol_in_editor(const String &p_symbol_id);
|
void show_native_symbol_in_editor(const String &p_symbol_id);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
public:
|
|
||||||
Variant nativeSymbol(const Dictionary &p_params);
|
Variant nativeSymbol(const Dictionary &p_params);
|
||||||
Array documentSymbol(const Dictionary &p_params);
|
Array documentSymbol(const Dictionary &p_params);
|
||||||
Array completion(const Dictionary &p_params);
|
Array completion(const Dictionary &p_params);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
void GDScriptWorkspace::_bind_methods() {
|
void GDScriptWorkspace::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("apply_new_signal"), &GDScriptWorkspace::apply_new_signal);
|
ClassDB::bind_method(D_METHOD("apply_new_signal"), &GDScriptWorkspace::apply_new_signal);
|
||||||
ClassDB::bind_method(D_METHOD("didDeleteFiles"), &GDScriptWorkspace::did_delete_files);
|
ClassDB::bind_method(D_METHOD("didDeleteFiles"), &GDScriptWorkspace::didDeleteFiles);
|
||||||
ClassDB::bind_method(D_METHOD("parse_script", "path", "content"), &GDScriptWorkspace::parse_script);
|
ClassDB::bind_method(D_METHOD("parse_script", "path", "content"), &GDScriptWorkspace::parse_script);
|
||||||
ClassDB::bind_method(D_METHOD("parse_local_script", "path"), &GDScriptWorkspace::parse_local_script);
|
ClassDB::bind_method(D_METHOD("parse_local_script", "path"), &GDScriptWorkspace::parse_local_script);
|
||||||
ClassDB::bind_method(D_METHOD("get_file_path", "uri"), &GDScriptWorkspace::get_file_path);
|
ClassDB::bind_method(D_METHOD("get_file_path", "uri"), &GDScriptWorkspace::get_file_path);
|
||||||
@@ -106,7 +106,7 @@ void GDScriptWorkspace::apply_new_signal(Object *obj, String function, PackedStr
|
|||||||
GDScriptLanguageProtocol::get_singleton()->request_client("workspace/applyEdit", params.to_json());
|
GDScriptLanguageProtocol::get_singleton()->request_client("workspace/applyEdit", params.to_json());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDScriptWorkspace::did_delete_files(const Dictionary &p_params) {
|
void GDScriptWorkspace::didDeleteFiles(const Dictionary &p_params) {
|
||||||
Array files = p_params["files"];
|
Array files = p_params["files"];
|
||||||
for (int i = 0; i < files.size(); ++i) {
|
for (int i = 0; i < files.size(); ++i) {
|
||||||
Dictionary file = files[i];
|
Dictionary file = files[i];
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public:
|
|||||||
void resolve_document_links(const String &p_uri, List<LSP::DocumentLink> &r_list);
|
void resolve_document_links(const String &p_uri, List<LSP::DocumentLink> &r_list);
|
||||||
Dictionary generate_script_api(const String &p_path);
|
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);
|
void didDeleteFiles(const Dictionary &p_params);
|
||||||
Dictionary rename(const LSP::TextDocumentPositionParams &p_doc_pos, const String &new_name);
|
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);
|
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_usages_in_file(const LSP::DocumentSymbol &p_symbol, const String &p_file_path);
|
||||||
|
|||||||
41
modules/jsonrpc/jsonrpc.compat.inc
Normal file
41
modules/jsonrpc/jsonrpc.compat.inc
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* jsonrpc.compat.inc */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* 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 DISABLE_DEPRECATED
|
||||||
|
|
||||||
|
void JSONRPC::_set_scope_bind_compat_104890(const String &p_scope, Object *p_obj) {
|
||||||
|
ERR_PRINT("JSONRPC::set_scope is not supported anymore. Upgrade to JSONRPC::set_method.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void JSONRPC::_bind_compatibility_methods() {
|
||||||
|
ClassDB::bind_compatibility_method(D_METHOD("set_scope", "scope", "target"), &JSONRPC::_set_scope_bind_compat_104890);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -29,6 +29,7 @@
|
|||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
#include "jsonrpc.h"
|
#include "jsonrpc.h"
|
||||||
|
#include "jsonrpc.compat.inc"
|
||||||
|
|
||||||
#include "core/io/json.h"
|
#include "core/io/json.h"
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ JSONRPC::~JSONRPC() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void JSONRPC::_bind_methods() {
|
void JSONRPC::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_scope", "scope", "target"), &JSONRPC::set_scope);
|
ClassDB::bind_method(D_METHOD("set_method", "name", "callback"), &JSONRPC::set_method);
|
||||||
ClassDB::bind_method(D_METHOD("process_action", "action", "recurse"), &JSONRPC::process_action, DEFVAL(false));
|
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("process_string", "action"), &JSONRPC::process_string);
|
||||||
|
|
||||||
@@ -113,12 +114,6 @@ Variant JSONRPC::process_action(const Variant &p_action, bool p_process_arr_elem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *object = this;
|
|
||||||
if (method_scopes.has(method.get_base_dir())) {
|
|
||||||
object = method_scopes[method.get_base_dir()];
|
|
||||||
method = method.get_file();
|
|
||||||
}
|
|
||||||
|
|
||||||
Variant id;
|
Variant id;
|
||||||
if (dict.has("id")) {
|
if (dict.has("id")) {
|
||||||
id = dict["id"];
|
id = dict["id"];
|
||||||
@@ -129,13 +124,13 @@ Variant JSONRPC::process_action(const Variant &p_action, bool p_process_arr_elem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object == nullptr || !object->has_method(method)) {
|
if (methods.has(method)) {
|
||||||
ret = make_response_error(JSONRPC::METHOD_NOT_FOUND, "Method not found: " + method, id);
|
Variant call_ret = methods[method].callv(args);
|
||||||
} else {
|
|
||||||
Variant call_ret = object->callv(method, args);
|
|
||||||
if (id.get_type() != Variant::NIL) {
|
if (id.get_type() != Variant::NIL) {
|
||||||
ret = make_response(call_ret, id);
|
ret = make_response(call_ret, id);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ret = make_response_error(JSONRPC::METHOD_NOT_FOUND, "Method not found: " + method, id);
|
||||||
}
|
}
|
||||||
} else if (p_action.get_type() == Variant::ARRAY && p_process_arr_elements) {
|
} else if (p_action.get_type() == Variant::ARRAY && p_process_arr_elements) {
|
||||||
Array arr = p_action;
|
Array arr = p_action;
|
||||||
@@ -175,6 +170,6 @@ String JSONRPC::process_string(const String &p_input) {
|
|||||||
return ret.to_json_string();
|
return ret.to_json_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSONRPC::set_scope(const String &p_scope, Object *p_obj) {
|
void JSONRPC::set_method(const String &p_name, const Callable &p_callback) {
|
||||||
method_scopes[p_scope] = p_obj;
|
methods[p_name] = p_callback;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,11 +36,16 @@
|
|||||||
class JSONRPC : public Object {
|
class JSONRPC : public Object {
|
||||||
GDCLASS(JSONRPC, Object)
|
GDCLASS(JSONRPC, Object)
|
||||||
|
|
||||||
HashMap<String, Object *> method_scopes;
|
HashMap<String, Callable> methods;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
|
#ifndef DISABLE_DEPRECATED
|
||||||
|
void _set_scope_bind_compat_104890(const String &p_scope, Object *p_obj);
|
||||||
|
static void _bind_compatibility_methods();
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JSONRPC();
|
JSONRPC();
|
||||||
~JSONRPC();
|
~JSONRPC();
|
||||||
@@ -61,7 +66,7 @@ public:
|
|||||||
Variant process_action(const Variant &p_action, bool p_process_arr_elements = false);
|
Variant process_action(const Variant &p_action, bool p_process_arr_elements = false);
|
||||||
String process_string(const String &p_input);
|
String process_string(const String &p_input);
|
||||||
|
|
||||||
void set_scope(const String &p_scope, Object *p_obj);
|
void set_method(const String &p_name, const Callable &p_callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
VARIANT_ENUM_CAST(JSONRPC::ErrorCode);
|
VARIANT_ENUM_CAST(JSONRPC::ErrorCode);
|
||||||
|
|||||||
@@ -57,10 +57,6 @@ String TestClassJSONRPC::something(const String &p_in) {
|
|||||||
return p_in + ", please";
|
return p_in + ", please";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestClassJSONRPC::_bind_methods() {
|
|
||||||
ClassDB::bind_method(D_METHOD("something", "in"), &TestClassJSONRPC::something);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_process_action(const Variant &p_in, const Variant &p_expected, bool p_process_array_elements) {
|
void test_process_action(const Variant &p_in, const Variant &p_expected, bool p_process_array_elements) {
|
||||||
TestClassJSONRPC json_rpc = TestClassJSONRPC();
|
TestClassJSONRPC json_rpc = TestClassJSONRPC();
|
||||||
const Variant &observed = json_rpc.process_action(p_in, p_process_array_elements);
|
const Variant &observed = json_rpc.process_action(p_in, p_process_array_elements);
|
||||||
|
|||||||
@@ -60,20 +60,17 @@ TEST_CASE("[JSONRPC] process_string invalid") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TestClassJSONRPC : public JSONRPC {
|
class TestClassJSONRPC : public JSONRPC {
|
||||||
GDCLASS(TestClassJSONRPC, JSONRPC)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
String something(const String &p_in);
|
TestClassJSONRPC() {
|
||||||
|
set_method("something", callable_mp(this, &TestClassJSONRPC::something));
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
String something(const String &p_in);
|
||||||
static void _bind_methods();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void test_process_action(const Variant &p_in, const Variant &p_expected, bool p_process_array_elements = false);
|
void test_process_action(const Variant &p_in, const Variant &p_expected, bool p_process_array_elements = false);
|
||||||
|
|
||||||
TEST_CASE("[JSONRPC] process_action Dictionary") {
|
TEST_CASE("[JSONRPC] process_action Dictionary") {
|
||||||
ClassDB::register_class<TestClassJSONRPC>();
|
|
||||||
|
|
||||||
Dictionary in_dict = Dictionary();
|
Dictionary in_dict = Dictionary();
|
||||||
in_dict["method"] = "something";
|
in_dict["method"] = "something";
|
||||||
in_dict["id"] = "ID";
|
in_dict["id"] = "ID";
|
||||||
|
|||||||
Reference in New Issue
Block a user