Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ jobs:
- name: Install VSCE
shell: bash
run: |
npm install -g patch-package
npm install ./chat_package_fixed/*.tgz
npm install -g @vscode/vsce
rm -rf ./chat_package ./chat_package_fixed
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ jobs:
- name: Install VSCE
shell: bash
run: |
npm install -g patch-package
npm install ./chat_package_fixed/*.tgz
npm install -g @vscode/vsce
rm -rf ./chat_package ./chat_package_fixed
Expand Down
8 changes: 4 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,12 @@ export async function ask_and_save_intent(): Promise<boolean>
// }


export async function deactivate(context: vscode.ExtensionContext)
export async function deactivate()
{
// global.global_context = undefined;
if (global.rust_binary_blob) {
await global.rust_binary_blob.terminate();
if (global.rust_binary_blob !== undefined) {
let rust_binary_blob = global.rust_binary_blob;
global.rust_binary_blob = undefined;
return rust_binary_blob.terminate();
}
}

Expand Down
75 changes: 49 additions & 26 deletions src/launchRust.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import * as vscode from 'vscode';
import * as fetchH2 from 'fetch-h2';
import * as cp from 'child_process';
import * as userLogin from './userLogin';
import * as fetchAPI from "./fetchAPI";
import { join } from 'path';
Expand Down Expand Up @@ -76,7 +77,8 @@ export class RustBinaryBlob {
}

public async settings_changed() {
for (let i = 0; i < 5; i++) {
const attempts_num = 5;
for (let i = 0; i < attempts_num; i++) {
console.log(`RUST settings changed, attempt to restart ${i + 1}`);
let xdebug = this.x_debug();
let api_key: string = userLogin.secret_api_key();
Expand Down Expand Up @@ -160,7 +162,10 @@ export class RustBinaryBlob {
this.cmdline = new_cmdline;
this.port = port;
this.ping_response = ping_response;
await this.launch();
const timeout = (i < (attempts_num - 1))
? 10000 * (2 ** i)
: 10000 * 99999;
await this.launch(timeout);
}
if (this.lsp_disposable !== undefined) {
break;
Expand All @@ -169,22 +174,48 @@ export class RustBinaryBlob {
global.side_panel?.handleSettingsChange();
}

public async launch() {
public async launch(timeout: number) {
await this.terminate();
let xdebug = this.x_debug();
if (xdebug) {
await this.start_lsp_socket();
} else {
await this.start_lsp_stdin_stdout();
await this.start_lsp_stdin_stdout(timeout);
}
}

public stop_lsp() {
let my_lsp_client_copy = this.lsp_client;
if (my_lsp_client_copy) {
console.log("RUST STOP");
let ts = Date.now();
my_lsp_client_copy.stop() // will complete in the background, otherwise it might die inside stop() such that execution never reaches even finally() and we don't know how to restart the process :/
public lsp_dispose() {
if (this.lsp_disposable) {
this.lsp_disposable.dispose();
this.lsp_disposable = undefined;
}
this.lsp_client = undefined;
this.lsp_socket = undefined;
}

private killServerProcess() {
if (!this.lsp_client) return;

const serverProcess = (this.lsp_client as any)._serverProcess;
if (serverProcess && !serverProcess.killed) {
try {
console.log(`${logts()} Forcefully terminating RUST process with PID ${serverProcess.pid}`);
if (process.platform === 'win32') {
cp.execSync(`taskkill /F /PID ${serverProcess.pid}`);
} else {
serverProcess.kill('SIGKILL');
}
} catch (e) {
console.log(`${logts()} Failed to kill RUST process: ${e}`);
}
}
}

public async terminate() {
console.log("RUST STOP");
let ts = Date.now();
if (this.lsp_client) {
await this.lsp_client.stop()
.then(() => {
console.log(`RUST /STOP completed in ${Date.now() - ts}ms`);
})
Expand All @@ -195,20 +226,10 @@ export class RustBinaryBlob {
console.log("RUST STOP FINALLY");
});
}
this.lsp_dispose();
}

public lsp_dispose() {
if (this.lsp_disposable) {
this.lsp_disposable.dispose();
this.lsp_disposable = undefined;
}
this.lsp_client = undefined;
this.lsp_socket = undefined;
}
this.killServerProcess();
this.lsp_dispose();

public async terminate() {
this.stop_lsp();
await fetchH2.disconnectAll();
global.have_caps = false;
global.status_bar.choose_color();
Expand Down Expand Up @@ -285,7 +306,7 @@ export class RustBinaryBlob {
return false;
}

public async start_lsp_stdin_stdout() {
public async start_lsp_stdin_stdout(timeout: number) {
console.log("RUST start_lsp_stdint_stdout");
let path = this.cmdline[0];
let serverOptions: lspClient.ServerOptions;
Expand All @@ -311,7 +332,7 @@ export class RustBinaryBlob {
this.lsp_disposable = this.lsp_client.start();

console.log(`${logts()} RUST START`);
const somethings_wrong_timeout = 10000;

const startTime = Date.now();
let started_okay = false;

Expand All @@ -326,21 +347,23 @@ export class RustBinaryBlob {
console.log(`${logts()} RUST /START after ${elapsedTime}ms`);
break;
}
if (elapsedTime >= somethings_wrong_timeout) {
if (elapsedTime >= timeout) {
throw new Error("timeout");
}
console.log(`${logts()} RUST waiting...`);
await new Promise(resolve => setTimeout(resolve, 100));
await new Promise(resolve => setTimeout(resolve, 500));
}
} catch (e) {
console.log(`${logts()} RUST START PROBLEM e=${e}`);
this.killServerProcess();
this.lsp_dispose();
return;
}

let success = await this.ping();
if (!success) {
console.log("RUST ping failed");
this.killServerProcess();
this.lsp_dispose();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1091,4 +1091,4 @@ export class PanelWebview implements vscode.WebviewViewProvider {
}


export default PanelWebview;
export default PanelWebview;
Loading