You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Migrating language server from Websockets to raw TCP
This commit is contained in:
@@ -31,16 +31,36 @@
|
||||
#ifndef GDSCRIPT_PROTOCAL_SERVER_H
|
||||
#define GDSCRIPT_PROTOCAL_SERVER_H
|
||||
|
||||
#include "core/io/stream_peer.h"
|
||||
#include "core/io/stream_peer_tcp.h"
|
||||
#include "core/io/tcp_server.h"
|
||||
#include "gdscript_text_document.h"
|
||||
#include "gdscript_workspace.h"
|
||||
#include "lsp.hpp"
|
||||
#include "modules/jsonrpc/jsonrpc.h"
|
||||
#include "modules/websocket/websocket_peer.h"
|
||||
#include "modules/websocket/websocket_server.h"
|
||||
|
||||
#define LSP_MAX_BUFFER_SIZE 4194304
|
||||
#define LSP_MAX_CLIENTS 8
|
||||
|
||||
class GDScriptLanguageProtocol : public JSONRPC {
|
||||
GDCLASS(GDScriptLanguageProtocol, JSONRPC)
|
||||
|
||||
private:
|
||||
struct LSPeer : Reference {
|
||||
Ref<StreamPeerTCP> connection;
|
||||
|
||||
uint8_t req_buf[LSP_MAX_BUFFER_SIZE];
|
||||
int req_pos = 0;
|
||||
bool has_header = false;
|
||||
bool has_content = false;
|
||||
int content_length = 0;
|
||||
Vector<CharString> res_queue;
|
||||
int res_sent = 0;
|
||||
|
||||
Error handle_data();
|
||||
Error send_data();
|
||||
};
|
||||
|
||||
enum LSPErrorCode {
|
||||
RequestCancelled = -32800,
|
||||
ContentModified = -32801,
|
||||
@@ -48,16 +68,16 @@ class GDScriptLanguageProtocol : public JSONRPC {
|
||||
|
||||
static GDScriptLanguageProtocol *singleton;
|
||||
|
||||
HashMap<int, Ref<WebSocketPeer> > clients;
|
||||
WebSocketServer *server;
|
||||
int lastest_client_id;
|
||||
HashMap<int, Ref<LSPeer> > clients;
|
||||
Ref<TCP_Server> server;
|
||||
int latest_client_id;
|
||||
int next_client_id;
|
||||
|
||||
Ref<GDScriptTextDocument> text_document;
|
||||
Ref<GDScriptWorkspace> workspace;
|
||||
|
||||
void on_data_received(int p_id);
|
||||
void on_client_connected(int p_id, const String &p_protocal);
|
||||
void on_client_disconnected(int p_id, bool p_was_clean_close);
|
||||
Error on_client_connected();
|
||||
void on_client_disconnected(int p_client_id);
|
||||
|
||||
String process_message(const String &p_text);
|
||||
String format_output(const String &p_text);
|
||||
@@ -80,14 +100,12 @@ public:
|
||||
Error start(int p_port, const IP_Address &p_bind_ip);
|
||||
void stop();
|
||||
|
||||
void notify_all_clients(const String &p_method, const Variant &p_params = Variant());
|
||||
void notify_client(const String &p_method, const Variant &p_params = Variant(), int p_client = -1);
|
||||
void notify_client(const String &p_method, const Variant &p_params = Variant(), int p_client_id = -1);
|
||||
|
||||
bool is_smart_resolve_enabled() const;
|
||||
bool is_goto_native_symbols_enabled() const;
|
||||
|
||||
GDScriptLanguageProtocol();
|
||||
~GDScriptLanguageProtocol();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user