Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit 39d2d66

Browse files
committed
Fix stop/start support for Rust Analyzer
1 parent 360de06 commit 39d2d66

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

src/extension.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ export class ClientWorkspace {
200200
}
201201

202202
public async start() {
203-
this._progress.value = { state: 'progress', message: 'Starting' };
204-
205203
const { createLanguageClient, setupClient, setupProgress } =
206204
this.config.engine === 'rls' ? rls : rustAnalyzer;
207205

@@ -218,6 +216,15 @@ export class ClientWorkspace {
218216
rustAnalyzer: { releaseTag: '2020-05-04' },
219217
});
220218

219+
client.onDidChangeState(({ newState }) => {
220+
if (newState === lc.State.Starting) {
221+
this._progress.value = { state: 'progress', message: 'Starting' };
222+
}
223+
if (newState === lc.State.Stopped) {
224+
this._progress.value = { state: 'standby' };
225+
}
226+
});
227+
221228
setupProgress(client, this._progress);
222229

223230
this.disposables.push(activateTaskProvider(this.folder));
@@ -230,8 +237,6 @@ export class ClientWorkspace {
230237
public async stop() {
231238
if (this.lc) {
232239
await this.lc.stop();
233-
this.lc = null;
234-
this._progress.value = { state: 'standby' };
235240
}
236241

237242
this.disposables.forEach(d => d.dispose());

src/rustAnalyzer.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -226,30 +226,28 @@ export async function createLanguageClient(
226226
}
227227

228228
async function setupGlobalProgress(client: lc.LanguageClient) {
229-
client.onDidChangeState(({ newState }) => {
229+
client.onDidChangeState(async ({ newState }) => {
230230
if (newState === lc.State.Starting) {
231-
PROGRESS.value = { state: 'progress', message: 'Starting' };
231+
await client.onReady();
232+
233+
const RUST_ANALYZER_PROGRESS = 'rustAnalyzer/startup';
234+
client.onProgress(
235+
new lc.ProgressType<{
236+
kind: 'begin' | 'report' | 'end';
237+
message?: string;
238+
}>(),
239+
RUST_ANALYZER_PROGRESS,
240+
({ kind, message: msg }) => {
241+
if (kind === 'report') {
242+
PROGRESS.value = { state: 'progress', message: msg || '' };
243+
}
244+
if (kind === 'end') {
245+
PROGRESS.value = { state: 'ready' };
246+
}
247+
},
248+
);
232249
}
233250
});
234-
235-
await client.onReady();
236-
237-
const RUST_ANALYZER_PROGRESS = 'rustAnalyzer/startup';
238-
client.onProgress(
239-
new lc.ProgressType<{
240-
kind: 'begin' | 'report' | 'end';
241-
message?: string;
242-
}>(),
243-
RUST_ANALYZER_PROGRESS,
244-
({ kind, message: msg }) => {
245-
if (kind === 'report') {
246-
PROGRESS.value = { state: 'progress', message: msg || '' };
247-
}
248-
if (kind === 'end') {
249-
PROGRESS.value = { state: 'ready' };
250-
}
251-
},
252-
);
253251
}
254252

255253
export function setupClient(

0 commit comments

Comments
 (0)