Path: blob/master/modules/gdscript/language_server/gdscript_language_protocol.h
10278 views
/**************************************************************************/1/* gdscript_language_protocol.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "gdscript_text_document.h"33#include "gdscript_workspace.h"3435#include "core/io/stream_peer_tcp.h"36#include "core/io/tcp_server.h"3738#include "modules/jsonrpc/jsonrpc.h"3940#define LSP_MAX_BUFFER_SIZE 419430441#define LSP_MAX_CLIENTS 84243class GDScriptLanguageProtocol : public JSONRPC {44GDCLASS(GDScriptLanguageProtocol, JSONRPC)4546private:47struct LSPeer : RefCounted {48Ref<StreamPeerTCP> connection;4950uint8_t req_buf[LSP_MAX_BUFFER_SIZE];51int req_pos = 0;52bool has_header = false;53bool has_content = false;54int content_length = 0;55Vector<CharString> res_queue;56int res_sent = 0;5758Error handle_data();59Error send_data();60};6162enum LSPErrorCode {63RequestCancelled = -32800,64ContentModified = -32801,65};6667static GDScriptLanguageProtocol *singleton;6869HashMap<int, Ref<LSPeer>> clients;70Ref<TCPServer> server;71int latest_client_id = 0;72int next_client_id = 0;7374int next_server_id = 0;7576Ref<GDScriptTextDocument> text_document;77Ref<GDScriptWorkspace> workspace;7879Error on_client_connected();80void on_client_disconnected(const int &p_client_id);8182String process_message(const String &p_text);83String format_output(const String &p_text);8485bool _initialized = false;8687protected:88static void _bind_methods();8990Dictionary initialize(const Dictionary &p_params);91void initialized(const Variant &p_params);9293public:94_FORCE_INLINE_ static GDScriptLanguageProtocol *get_singleton() { return singleton; }95_FORCE_INLINE_ Ref<GDScriptWorkspace> get_workspace() { return workspace; }96_FORCE_INLINE_ Ref<GDScriptTextDocument> get_text_document() { return text_document; }97_FORCE_INLINE_ bool is_initialized() const { return _initialized; }9899void poll(int p_limit_usec);100Error start(int p_port, const IPAddress &p_bind_ip);101void stop();102103void notify_client(const String &p_method, const Variant &p_params = Variant(), int p_client_id = -1);104void request_client(const String &p_method, const Variant &p_params = Variant(), int p_client_id = -1);105106bool is_smart_resolve_enabled() const;107bool is_goto_native_symbols_enabled() const;108109GDScriptLanguageProtocol();110};111112113