diff options
Diffstat (limited to 'modules/gdscript/language_server')
9 files changed, 62 insertions, 53 deletions
| diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp index 15236d900d..b3469ec47c 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.cpp +++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp @@ -32,7 +32,6 @@  #include "../gdscript.h"  #include "../gdscript_analyzer.h" -#include "core/io/json.h"  #include "gdscript_language_protocol.h"  #include "gdscript_workspace.h" @@ -40,8 +39,7 @@ void ExtendGDScriptParser::update_diagnostics() {  	diagnostics.clear();  	const List<ParserError> &errors = get_errors(); -	for (const List<ParserError>::Element *E = errors.front(); E != nullptr; E = E->next()) { -		const ParserError &error = E->get(); +	for (const ParserError &error : errors) {  		lsp::Diagnostic diagnostic;  		diagnostic.severity = lsp::DiagnosticSeverity::Error;  		diagnostic.message = error.message; @@ -62,8 +60,7 @@ void ExtendGDScriptParser::update_diagnostics() {  	}  	const List<GDScriptWarning> &warnings = get_warnings(); -	for (const List<GDScriptWarning>::Element *E = warnings.front(); E; E = E->next()) { -		const GDScriptWarning &warning = E->get(); +	for (const GDScriptWarning &warning : warnings) {  		lsp::Diagnostic diagnostic;  		diagnostic.severity = lsp::DiagnosticSeverity::Warning;  		diagnostic.message = "(" + warning.get_name() + "): " + warning.get_message(); @@ -183,7 +180,7 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p  					symbol.detail += ": " + m.get_datatype().to_string();  				}  				if (m.variable->initializer != nullptr && m.variable->initializer->is_constant) { -					symbol.detail += " = " + JSON::print(m.variable->initializer->reduced_value); +					symbol.detail += " = " + m.variable->initializer->reduced_value.to_json_string();  				}  				symbol.documentation = parse_documentation(LINE_NUMBER_TO_INDEX(m.variable->start_line)); @@ -224,10 +221,10 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p  							}  						}  					} else { -						value_text = JSON::print(default_value); +						value_text = default_value.to_json_string();  					}  				} else { -					value_text = JSON::print(default_value); +					value_text = default_value.to_json_string();  				}  				if (!value_text.is_empty()) {  					symbol.detail += " = " + value_text; @@ -353,8 +350,7 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN  			parameters += ": " + parameter->get_datatype().to_string();  		}  		if (parameter->default_value != nullptr) { -			String value = JSON::print(parameter->default_value->reduced_value); -			parameters += " = " + value; +			parameters += " = " + parameter->default_value->reduced_value.to_json_string();  		}  	}  	r_symbol.detail += parameters + ")"; @@ -469,8 +465,8 @@ String ExtendGDScriptParser::parse_documentation(int p_line, bool p_docs_down) {  	}  	String doc; -	for (List<String>::Element *E = doc_lines.front(); E; E = E->next()) { -		doc += E->get() + "\n"; +	for (const String &E : doc_lines) { +		doc += E + "\n";  	}  	return doc;  } @@ -697,7 +693,9 @@ Dictionary ExtendGDScriptParser::dump_function_api(const GDScriptParser::Functio  	ERR_FAIL_NULL_V(p_func, func);  	func["name"] = p_func->identifier->name;  	func["return_type"] = p_func->get_datatype().to_string(); -	func["rpc_mode"] = p_func->rpc_mode; +	func["rpc_mode"] = p_func->rpc_config.rpc_mode; +	func["rpc_transfer_mode"] = p_func->rpc_config.transfer_mode; +	func["rpc_transfer_channel"] = p_func->rpc_config.channel;  	Array parameters;  	for (int i = 0; i < p_func->parameters.size(); i++) {  		Dictionary arg; diff --git a/modules/gdscript/language_server/gdscript_language_protocol.cpp b/modules/gdscript/language_server/gdscript_language_protocol.cpp index c16a7fa889..0d1f98778e 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.cpp +++ b/modules/gdscript/language_server/gdscript_language_protocol.cpp @@ -31,7 +31,6 @@  #include "gdscript_language_protocol.h"  #include "core/config/project_settings.h" -#include "core/io/json.h"  #include "editor/doc_tools.h"  #include "editor/editor_log.h"  #include "editor/editor_node.h" @@ -194,7 +193,7 @@ Dictionary GDScriptLanguageProtocol::initialize(const Dictionary &p_params) {  				vformat("GDScriptLanguageProtocol: Can't initialize invalid peer '%d'.", latest_client_id));  		Ref<LSPeer> peer = clients.get(latest_client_id);  		if (peer != nullptr) { -			String msg = JSON::print(request); +			String msg = Variant(request).to_json_string();  			msg = format_output(msg);  			(*peer)->res_queue.push_back(msg.utf8());  		} @@ -280,7 +279,7 @@ void GDScriptLanguageProtocol::notify_client(const String &p_method, const Varia  	ERR_FAIL_COND(peer == nullptr);  	Dictionary message = make_notification(p_method, p_params); -	String msg = JSON::print(message); +	String msg = Variant(message).to_json_string();  	msg = format_output(msg);  	peer->res_queue.push_back(msg.utf8());  } @@ -294,10 +293,10 @@ bool GDScriptLanguageProtocol::is_goto_native_symbols_enabled() const {  }  GDScriptLanguageProtocol::GDScriptLanguageProtocol() { -	server.instance(); +	server.instantiate();  	singleton = this; -	workspace.instance(); -	text_document.instance(); +	workspace.instantiate(); +	text_document.instantiate();  	set_scope("textDocument", text_document.ptr());  	set_scope("completionItem", text_document.ptr());  	set_scope("workspace", workspace.ptr()); diff --git a/modules/gdscript/language_server/gdscript_language_protocol.h b/modules/gdscript/language_server/gdscript_language_protocol.h index a5c5a233b1..5a2dd55c46 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.h +++ b/modules/gdscript/language_server/gdscript_language_protocol.h @@ -28,8 +28,8 @@  /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */  /*************************************************************************/ -#ifndef GDSCRIPT_PROTOCAL_SERVER_H -#define GDSCRIPT_PROTOCAL_SERVER_H +#ifndef GDSCRIPT_LANGUAGE_PROTOCOL_H +#define GDSCRIPT_LANGUAGE_PROTOCOL_H  #include "core/io/stream_peer.h"  #include "core/io/stream_peer_tcp.h" @@ -37,7 +37,13 @@  #include "gdscript_text_document.h"  #include "gdscript_workspace.h"  #include "lsp.hpp" + +#include "modules/modules_enabled.gen.h" +#ifdef MODULE_JSONRPC_ENABLED  #include "modules/jsonrpc/jsonrpc.h" +#else +#error "Can't build GDScript LSP without JSONRPC module." +#endif  #define LSP_MAX_BUFFER_SIZE 4194304  #define LSP_MAX_CLIENTS 8 @@ -46,7 +52,7 @@ class GDScriptLanguageProtocol : public JSONRPC {  	GDCLASS(GDScriptLanguageProtocol, JSONRPC)  private: -	struct LSPeer : Reference { +	struct LSPeer : RefCounted {  		Ref<StreamPeerTCP> connection;  		uint8_t req_buf[LSP_MAX_BUFFER_SIZE]; @@ -108,4 +114,4 @@ public:  	GDScriptLanguageProtocol();  }; -#endif +#endif // GDSCRIPT_LANGUAGE_PROTOCOL_H diff --git a/modules/gdscript/language_server/gdscript_language_server.cpp b/modules/gdscript/language_server/gdscript_language_server.cpp index 340a7b9343..c47164d95b 100644 --- a/modules/gdscript/language_server/gdscript_language_server.cpp +++ b/modules/gdscript/language_server/gdscript_language_server.cpp @@ -30,7 +30,7 @@  #include "gdscript_language_server.h" -#include "core/os/file_access.h" +#include "core/io/file_access.h"  #include "core/os/os.h"  #include "editor/editor_log.h"  #include "editor/editor_node.h" @@ -101,7 +101,7 @@ void GDScriptLanguageServer::stop() {  }  void register_lsp_types() { -	ClassDB::register_class<GDScriptLanguageProtocol>(); -	ClassDB::register_class<GDScriptTextDocument>(); -	ClassDB::register_class<GDScriptWorkspace>(); +	GDREGISTER_CLASS(GDScriptLanguageProtocol); +	GDREGISTER_CLASS(GDScriptTextDocument); +	GDREGISTER_CLASS(GDScriptWorkspace);  } diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp index 030633274c..69ddbe5d1e 100644 --- a/modules/gdscript/language_server/gdscript_text_document.cpp +++ b/modules/gdscript/language_server/gdscript_text_document.cpp @@ -40,6 +40,7 @@  void GDScriptTextDocument::_bind_methods() {  	ClassDB::bind_method(D_METHOD("didOpen"), &GDScriptTextDocument::didOpen); +	ClassDB::bind_method(D_METHOD("didClose"), &GDScriptTextDocument::didClose);  	ClassDB::bind_method(D_METHOD("didChange"), &GDScriptTextDocument::didChange);  	ClassDB::bind_method(D_METHOD("nativeSymbol"), &GDScriptTextDocument::nativeSymbol);  	ClassDB::bind_method(D_METHOD("documentSymbol"), &GDScriptTextDocument::documentSymbol); @@ -61,6 +62,11 @@ void GDScriptTextDocument::didOpen(const Variant &p_param) {  	sync_script_content(doc.uri, doc.text);  } +void GDScriptTextDocument::didClose(const Variant &p_param) { +	// Left empty on purpose. Godot does nothing special on closing a document, +	// but it satisfies LSP clients that require didClose be implemented. +} +  void GDScriptTextDocument::didChange(const Variant &p_param) {  	lsp::TextDocumentItem doc = load_document_item(p_param);  	Dictionary dict = p_param; @@ -151,8 +157,7 @@ Array GDScriptTextDocument::completion(const Dictionary &p_params) {  		int i = 0;  		arr.resize(options.size()); -		for (const List<ScriptCodeCompletionOption>::Element *E = options.front(); E; E = E->next()) { -			const ScriptCodeCompletionOption &option = E->get(); +		for (const ScriptCodeCompletionOption &option : options) {  			lsp::CompletionItem item;  			item.label = option.display;  			item.data = request_data; @@ -288,8 +293,8 @@ Array GDScriptTextDocument::documentLink(const Dictionary &p_params) {  	List<lsp::DocumentLink> links;  	GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_document_links(params.textDocument.uri, links); -	for (const List<lsp::DocumentLink>::Element *E = links.front(); E; E = E->next()) { -		ret.push_back(E->get().to_json()); +	for (const lsp::DocumentLink &E : links) { +		ret.push_back(E.to_json());  	}  	return ret;  } @@ -316,8 +321,8 @@ Variant GDScriptTextDocument::hover(const Dictionary &p_params) {  		Array contents;  		List<const lsp::DocumentSymbol *> list;  		GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(params, list); -		for (List<const lsp::DocumentSymbol *>::Element *E = list.front(); E; E = E->next()) { -			if (const lsp::DocumentSymbol *s = E->get()) { +		for (const lsp::DocumentSymbol *&E : list) { +			if (const lsp::DocumentSymbol *s = E) {  				contents.push_back(s->render().value);  			}  		} @@ -367,7 +372,7 @@ Variant GDScriptTextDocument::declaration(const Dictionary &p_params) {  					id = "class_global:" + symbol->native_class + ":" + symbol->name;  					break;  			} -			call_deferred("show_native_symbol_in_editor", id); +			call_deferred(SNAME("show_native_symbol_in_editor"), id);  		} else {  			notify_client_show_symbol(symbol);  		} @@ -404,7 +409,7 @@ void GDScriptTextDocument::sync_script_content(const String &p_path, const Strin  }  void GDScriptTextDocument::show_native_symbol_in_editor(const String &p_symbol_id) { -	ScriptEditor::get_singleton()->call_deferred("_help_class_goto", p_symbol_id); +	ScriptEditor::get_singleton()->call_deferred(SNAME("_help_class_goto"), p_symbol_id);  	DisplayServer::get_singleton()->window_move_to_foreground();  } @@ -424,8 +429,8 @@ Array GDScriptTextDocument::find_symbols(const lsp::TextDocumentPositionParams &  	} else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {  		List<const lsp::DocumentSymbol *> list;  		GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(p_location, list); -		for (List<const lsp::DocumentSymbol *>::Element *E = list.front(); E; E = E->next()) { -			if (const lsp::DocumentSymbol *s = E->get()) { +		for (const lsp::DocumentSymbol *&E : list) { +			if (const lsp::DocumentSymbol *s = E) {  				if (!s->uri.is_empty()) {  					lsp::Location location;  					location.uri = s->uri; diff --git a/modules/gdscript/language_server/gdscript_text_document.h b/modules/gdscript/language_server/gdscript_text_document.h index 792e601bc1..e2987f779c 100644 --- a/modules/gdscript/language_server/gdscript_text_document.h +++ b/modules/gdscript/language_server/gdscript_text_document.h @@ -31,18 +31,19 @@  #ifndef GDSCRIPT_TEXT_DOCUMENT_H  #define GDSCRIPT_TEXT_DOCUMENT_H -#include "core/object/reference.h" -#include "core/os/file_access.h" +#include "core/io/file_access.h" +#include "core/object/ref_counted.h"  #include "lsp.hpp" -class GDScriptTextDocument : public Reference { -	GDCLASS(GDScriptTextDocument, Reference) +class GDScriptTextDocument : public RefCounted { +	GDCLASS(GDScriptTextDocument, RefCounted)  protected:  	static void _bind_methods();  	FileAccess *file_checker;  	void didOpen(const Variant &p_param); +	void didClose(const Variant &p_param);  	void didChange(const Variant &p_param);  	void sync_script_content(const String &p_path, const String &p_content); diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index 9b7b2b36b4..e6c819b22f 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -119,8 +119,7 @@ const lsp::DocumentSymbol *GDScriptWorkspace::get_script_symbol(const String &p_  void GDScriptWorkspace::reload_all_workspace_scripts() {  	List<String> paths;  	list_script_files("res://", paths); -	for (List<String>::Element *E = paths.front(); E; E = E->next()) { -		const String &path = E->get(); +	for (const String &path : paths) {  		Error err;  		String content = FileAccess::get_file_as_string(path, &err);  		ERR_CONTINUE(err != OK); @@ -188,7 +187,9 @@ Array GDScriptWorkspace::symbol(const Dictionary &p_params) {  			E->get()->get_symbols().symbol_tree_as_list(E->key(), script_symbols);  			for (int i = 0; i < script_symbols.size(); ++i) {  				if (query.is_subsequence_ofi(script_symbols[i].name)) { -					arr.push_back(script_symbols[i].to_json()); +					lsp::DocumentedSymbolInformation symbol = script_symbols[i]; +					symbol.location.uri = get_file_uri(symbol.location.uri); +					arr.push_back(symbol.to_json());  				}  			}  		} @@ -424,7 +425,7 @@ Node *GDScriptWorkspace::_get_owner_scene_node(String p_path) {  		RES owner_res = ResourceLoader::load(owner_path);  		if (Object::cast_to<PackedScene>(owner_res.ptr())) {  			Ref<PackedScene> owner_packed_scene = Ref<PackedScene>(Object::cast_to<PackedScene>(*owner_res)); -			owner_scene_node = owner_packed_scene->instance(); +			owner_scene_node = owner_packed_scene->instantiate();  			break;  		}  	} @@ -557,8 +558,8 @@ const lsp::DocumentSymbol *GDScriptWorkspace::resolve_native_symbol(const lsp::N  void GDScriptWorkspace::resolve_document_links(const String &p_uri, List<lsp::DocumentLink> &r_list) {  	if (const ExtendGDScriptParser *parser = get_parse_successed_script(get_file_path(p_uri))) {  		const List<lsp::DocumentLink> &links = parser->get_document_links(); -		for (const List<lsp::DocumentLink>::Element *E = links.front(); E; E = E->next()) { -			r_list.push_back(E->get()); +		for (const lsp::DocumentLink &E : links) { +			r_list.push_back(E);  		}  	}  } @@ -585,8 +586,7 @@ Error GDScriptWorkspace::resolve_signature(const lsp::TextDocumentPositionParams  				GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(text_pos, symbols);  			} -			for (List<const lsp::DocumentSymbol *>::Element *E = symbols.front(); E; E = E->next()) { -				const lsp::DocumentSymbol *symbol = E->get(); +			for (const lsp::DocumentSymbol *const &symbol : symbols) {  				if (symbol->kind == lsp::SymbolKind::Method || symbol->kind == lsp::SymbolKind::Function) {  					lsp::SignatureInformation signature_info;  					signature_info.label = symbol->detail; diff --git a/modules/gdscript/language_server/gdscript_workspace.h b/modules/gdscript/language_server/gdscript_workspace.h index 27616a2989..8b166a873c 100644 --- a/modules/gdscript/language_server/gdscript_workspace.h +++ b/modules/gdscript/language_server/gdscript_workspace.h @@ -37,8 +37,8 @@  #include "gdscript_extend_parser.h"  #include "lsp.hpp" -class GDScriptWorkspace : public Reference { -	GDCLASS(GDScriptWorkspace, Reference); +class GDScriptWorkspace : public RefCounted { +	GDCLASS(GDScriptWorkspace, RefCounted);  private:  	void _get_owners(EditorFileSystemDirectory *efsd, String p_path, List<String> &owners); diff --git a/modules/gdscript/language_server/lsp.hpp b/modules/gdscript/language_server/lsp.hpp index 47bcfeaefc..a7dcfdb22d 100644 --- a/modules/gdscript/language_server/lsp.hpp +++ b/modules/gdscript/language_server/lsp.hpp @@ -766,7 +766,7 @@ struct MarkupContent {  // Use namespace instead of enumeration to follow the LSP specifications  // lsp::EnumName::EnumValue is OK but lsp::EnumValue is not -// And here C++ compilers are unhappy with our enumeration name like Color, File, Reference etc. +// And here C++ compilers are unhappy with our enumeration name like Color, File, RefCounted etc.  /**   * The kind of a completion entry.   */ @@ -788,7 +788,7 @@ static const int Keyword = 14;  static const int Snippet = 15;  static const int Color = 16;  static const int File = 17; -static const int Reference = 18; +static const int RefCounted = 18;  static const int Folder = 19;  static const int EnumMember = 20;  static const int Constant = 21; |