mirror of
https://github.com/godotengine/godot.git
synced 2024-11-27 09:16:35 +08:00
Merge pull request #35015 from GodotExplorer/lsp-configs
Improvements for GDScript LSP server
This commit is contained in:
commit
f118bd6861
@ -36,10 +36,15 @@
|
|||||||
|
|
||||||
GDScriptLanguageServer::GDScriptLanguageServer() {
|
GDScriptLanguageServer::GDScriptLanguageServer() {
|
||||||
thread = NULL;
|
thread = NULL;
|
||||||
thread_exit = false;
|
thread_running = false;
|
||||||
_EDITOR_DEF("network/language_server/remote_port", 6008);
|
started = false;
|
||||||
|
|
||||||
|
use_thread = false;
|
||||||
|
port = 6008;
|
||||||
|
_EDITOR_DEF("network/language_server/remote_port", port);
|
||||||
_EDITOR_DEF("network/language_server/enable_smart_resolve", true);
|
_EDITOR_DEF("network/language_server/enable_smart_resolve", true);
|
||||||
_EDITOR_DEF("network/language_server/show_native_symbols_in_editor", false);
|
_EDITOR_DEF("network/language_server/show_native_symbols_in_editor", false);
|
||||||
|
_EDITOR_DEF("network/language_server/use_thread", use_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDScriptLanguageServer::_notification(int p_what) {
|
void GDScriptLanguageServer::_notification(int p_what) {
|
||||||
@ -51,12 +56,25 @@ void GDScriptLanguageServer::_notification(int p_what) {
|
|||||||
case NOTIFICATION_EXIT_TREE:
|
case NOTIFICATION_EXIT_TREE:
|
||||||
stop();
|
stop();
|
||||||
break;
|
break;
|
||||||
|
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||||
|
if (started && !use_thread) {
|
||||||
|
protocol.poll();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
||||||
|
int port = (int)_EDITOR_GET("network/language_server/remote_port");
|
||||||
|
bool use_thread = (bool)_EDITOR_GET("network/language_server/use_thread");
|
||||||
|
if (port != this->port || use_thread != this->use_thread) {
|
||||||
|
this->stop();
|
||||||
|
this->start();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDScriptLanguageServer::thread_main(void *p_userdata) {
|
void GDScriptLanguageServer::thread_main(void *p_userdata) {
|
||||||
GDScriptLanguageServer *self = static_cast<GDScriptLanguageServer *>(p_userdata);
|
GDScriptLanguageServer *self = static_cast<GDScriptLanguageServer *>(p_userdata);
|
||||||
while (!self->thread_exit) {
|
while (self->thread_running) {
|
||||||
// Poll 20 times per second
|
// Poll 20 times per second
|
||||||
self->protocol.poll();
|
self->protocol.poll();
|
||||||
OS::get_singleton()->delay_usec(50000);
|
OS::get_singleton()->delay_usec(50000);
|
||||||
@ -64,22 +82,30 @@ void GDScriptLanguageServer::thread_main(void *p_userdata) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GDScriptLanguageServer::start() {
|
void GDScriptLanguageServer::start() {
|
||||||
int port = (int)_EDITOR_GET("network/language_server/remote_port");
|
port = (int)_EDITOR_GET("network/language_server/remote_port");
|
||||||
|
use_thread = (bool)_EDITOR_GET("network/language_server/use_thread");
|
||||||
if (protocol.start(port) == OK) {
|
if (protocol.start(port) == OK) {
|
||||||
EditorNode::get_log()->add_message("--- GDScript language server started ---", EditorLog::MSG_TYPE_EDITOR);
|
EditorNode::get_log()->add_message("--- GDScript language server started ---", EditorLog::MSG_TYPE_EDITOR);
|
||||||
ERR_FAIL_COND(thread != NULL || thread_exit);
|
if (use_thread) {
|
||||||
thread_exit = false;
|
ERR_FAIL_COND(thread != NULL);
|
||||||
thread = Thread::create(GDScriptLanguageServer::thread_main, this);
|
thread_running = true;
|
||||||
|
thread = Thread::create(GDScriptLanguageServer::thread_main, this);
|
||||||
|
}
|
||||||
|
set_process_internal(!use_thread);
|
||||||
|
started = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDScriptLanguageServer::stop() {
|
void GDScriptLanguageServer::stop() {
|
||||||
ERR_FAIL_COND(NULL == thread || thread_exit);
|
if (use_thread) {
|
||||||
thread_exit = true;
|
ERR_FAIL_COND(NULL == thread);
|
||||||
Thread::wait_to_finish(thread);
|
thread_running = false;
|
||||||
memdelete(thread);
|
Thread::wait_to_finish(thread);
|
||||||
thread = NULL;
|
memdelete(thread);
|
||||||
|
thread = NULL;
|
||||||
|
}
|
||||||
protocol.stop();
|
protocol.stop();
|
||||||
|
started = false;
|
||||||
EditorNode::get_log()->add_message("--- GDScript language server stopped ---", EditorLog::MSG_TYPE_EDITOR);
|
EditorNode::get_log()->add_message("--- GDScript language server stopped ---", EditorLog::MSG_TYPE_EDITOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,10 @@ class GDScriptLanguageServer : public EditorPlugin {
|
|||||||
GDScriptLanguageProtocol protocol;
|
GDScriptLanguageProtocol protocol;
|
||||||
|
|
||||||
Thread *thread;
|
Thread *thread;
|
||||||
bool thread_exit;
|
bool thread_running;
|
||||||
|
bool started;
|
||||||
|
bool use_thread;
|
||||||
|
int port;
|
||||||
static void thread_main(void *p_userdata);
|
static void thread_main(void *p_userdata);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -330,8 +330,6 @@ struct CompletionOptions {
|
|||||||
triggerCharacters.push_back("$");
|
triggerCharacters.push_back("$");
|
||||||
triggerCharacters.push_back("'");
|
triggerCharacters.push_back("'");
|
||||||
triggerCharacters.push_back("\"");
|
triggerCharacters.push_back("\"");
|
||||||
triggerCharacters.push_back("(");
|
|
||||||
triggerCharacters.push_back(",");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary to_json() const {
|
Dictionary to_json() const {
|
||||||
|
Loading…
Reference in New Issue
Block a user