|
@@ -8,7 +8,7 @@ const CONFIG_CONTAINER = "godot_tools";
|
|
const TOOL_NAME = "GodotTools";
|
|
const TOOL_NAME = "GodotTools";
|
|
|
|
|
|
export class GodotTools {
|
|
export class GodotTools {
|
|
-
|
|
|
|
|
|
+ private reconnection_attempts = 0;
|
|
private context: vscode.ExtensionContext;
|
|
private context: vscode.ExtensionContext;
|
|
private client: GDScriptLanguageClient = null;
|
|
private client: GDScriptLanguageClient = null;
|
|
private workspace_dir = vscode.workspace.rootPath;
|
|
private workspace_dir = vscode.workspace.rootPath;
|
|
@@ -20,6 +20,10 @@ export class GodotTools {
|
|
this.client = new GDScriptLanguageClient(p_context);
|
|
this.client = new GDScriptLanguageClient(p_context);
|
|
this.client.watch_status(this.on_client_status_changed.bind(this));
|
|
this.client.watch_status(this.on_client_status_changed.bind(this));
|
|
this.connection_status = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
|
|
this.connection_status = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
|
|
|
|
+
|
|
|
|
+ setInterval(() => {
|
|
|
|
+ this.retry_callback();
|
|
|
|
+ }, get_configuration("reconnect_cooldown", 3000));
|
|
}
|
|
}
|
|
|
|
|
|
public activate() {
|
|
public activate() {
|
|
@@ -35,16 +39,15 @@ export class GodotTools {
|
|
this.connection_status.text = "$(sync) Initializing";
|
|
this.connection_status.text = "$(sync) Initializing";
|
|
this.connection_status.command = "godot-tool.check_status";
|
|
this.connection_status.command = "godot-tool.check_status";
|
|
this.connection_status.show();
|
|
this.connection_status.show();
|
|
|
|
+
|
|
|
|
+ this.reconnection_attempts = 0;
|
|
this.client.connect_to_server();
|
|
this.client.connect_to_server();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
public deactivate() {
|
|
public deactivate() {
|
|
this.client.stop();
|
|
this.client.stop();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
private open_workspace_with_editor(params = "") {
|
|
private open_workspace_with_editor(params = "") {
|
|
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
return new Promise<void>((resolve, reject) => {
|
|
@@ -76,7 +79,6 @@ export class GodotTools {
|
|
set_configuration("scene_file_config", scene_config);
|
|
set_configuration("scene_file_config", scene_config);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
private run_editor(params = "") {
|
|
private run_editor(params = "") {
|
|
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
return new Promise<void>((resolve, reject) => {
|
|
@@ -188,6 +190,7 @@ export class GodotTools {
|
|
this.connection_status.tooltip = `Connecting to the GDScript language server at ${host}:${port}`;
|
|
this.connection_status.tooltip = `Connecting to the GDScript language server at ${host}:${port}`;
|
|
break;
|
|
break;
|
|
case ClientStatus.CONNECTED:
|
|
case ClientStatus.CONNECTED:
|
|
|
|
+ this.retry = false;
|
|
this.connection_status.text = `$(check) Connected`;
|
|
this.connection_status.text = `$(check) Connected`;
|
|
this.connection_status.tooltip = `Connected to the GDScript language server.`;
|
|
this.connection_status.tooltip = `Connected to the GDScript language server.`;
|
|
if (!this.client.started) {
|
|
if (!this.client.started) {
|
|
@@ -195,26 +198,55 @@ export class GodotTools {
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case ClientStatus.DISCONNECTED:
|
|
case ClientStatus.DISCONNECTED:
|
|
- this.connection_status.text = `$(x) Disconnected`;
|
|
|
|
- this.connection_status.tooltip = `Disconnected from the GDScript language server.`;
|
|
|
|
- // retry
|
|
|
|
- this.retry_connect_client();
|
|
|
|
|
|
+ if (this.retry) {
|
|
|
|
+ this.connection_status.text = `$(sync) Connecting ` + this.reconnection_attempts;
|
|
|
|
+ this.connection_status.tooltip = `Connecting to the GDScript language server...`;
|
|
|
|
+ } else {
|
|
|
|
+ this.connection_status.text = `$(x) Disconnected`;
|
|
|
|
+ this.connection_status.tooltip = `Disconnected from the GDScript language server.`;
|
|
|
|
+ }
|
|
|
|
+ this.retry = true;
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private retry = false;
|
|
|
|
+
|
|
|
|
+ private retry_callback() {
|
|
|
|
+ if (this.retry) {
|
|
|
|
+ this.retry_connect_client();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private retry_connect_client() {
|
|
private retry_connect_client() {
|
|
|
|
+ const auto_retry = get_configuration("reconnect_automatically", true);
|
|
|
|
+ const max_attempts = get_configuration("reconnect_attempts", 10);
|
|
|
|
+ if (auto_retry && this.reconnection_attempts <= max_attempts) {
|
|
|
|
+ this.reconnection_attempts++;
|
|
|
|
+ this.client.connect_to_server();
|
|
|
|
+ this.connection_status.text = `Connecting ` + this.reconnection_attempts;
|
|
|
|
+ this.retry = true;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.retry = false
|
|
|
|
+ this.connection_status.text = `$(x) Disconnected`;
|
|
|
|
+ this.connection_status.tooltip = `Disconnected from the GDScript language server.`;
|
|
|
|
+
|
|
let host = get_configuration("gdscript_lsp_server_host", "localhost");
|
|
let host = get_configuration("gdscript_lsp_server_host", "localhost");
|
|
let port = get_configuration("gdscript_lsp_server_port", 6008);
|
|
let port = get_configuration("gdscript_lsp_server_port", 6008);
|
|
- vscode.window.showErrorMessage(`Couldn't connect to the GDScript language server at ${host}:${port}`, 'Open Godot Editor', 'Retry', 'Ignore').then(item=>{
|
|
|
|
|
|
+ let message = `Couldn't connect to the GDScript language server at ${host}:${port}`;
|
|
|
|
+ vscode.window.showErrorMessage(message, 'Open Godot Editor', 'Retry', 'Ignore').then(item => {
|
|
if (item == 'Retry') {
|
|
if (item == 'Retry') {
|
|
|
|
+ this.reconnection_attempts = 0;
|
|
this.client.connect_to_server();
|
|
this.client.connect_to_server();
|
|
} else if (item == 'Open Godot Editor') {
|
|
} else if (item == 'Open Godot Editor') {
|
|
this.client.status = ClientStatus.PENDING;
|
|
this.client.status = ClientStatus.PENDING;
|
|
this.open_workspace_with_editor("-e").then(()=>{
|
|
this.open_workspace_with_editor("-e").then(()=>{
|
|
- setTimeout(()=>{
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ this.reconnection_attempts = 0;
|
|
this.client.connect_to_server();
|
|
this.client.connect_to_server();
|
|
}, 10 * 1000);
|
|
}, 10 * 1000);
|
|
});
|
|
});
|