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

Commit 3ff6c53

Browse files
YarnXanewok
authored andcommitted
Add start and stop commands for rls, add auto start rls config value
1 parent eb5cdf7 commit 3ff6c53

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@
9494
"title": "Restart the RLS",
9595
"description": "Sometimes, it's just best to try turning it off and on again",
9696
"category": "Rust"
97+
},
98+
{
99+
"command": "rls.start",
100+
"title": "Start the RLS",
101+
"description": "Start the RLS (when rust-client.autoStartRls is false or when manually stopped)",
102+
"category": "Rust"
103+
},
104+
{
105+
"command": "rls.stop",
106+
"title": "Stop the RLS",
107+
"description": "Stop the RLS for a workspace until manually started again",
108+
"category": "Rust"
97109
}
98110
],
99111
"taskDefinitions": [
@@ -187,6 +199,12 @@
187199
"default": false,
188200
"description": "Update the RLS whenever the extension starts up."
189201
},
202+
"rust-client.autoStartRls": {
203+
"type": "boolean",
204+
"default": true,
205+
"description": "Start RLS automatically when opening a file or project.",
206+
"scope": "resource"
207+
},
190208
"rust-client.disableRustup": {
191209
"type": "boolean",
192210
"default": false,

src/configuration.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ export class RLSConfiguration {
118118
return this.configuration.get<string>('rust-client.rlsPath');
119119
}
120120

121+
/**
122+
* Whether RLS should be automaticallystarted when opening a relevant Rust project.
123+
*/
124+
public get autoStartRls(): boolean {
125+
return this.configuration.get<boolean>('rust-client.autoStartRls', true);
126+
}
127+
121128
// Added ignoreChannel for readChannel function. Otherwise we end in an infinite loop.
122129
public rustupConfig(ignoreChannel: boolean = false): RustupConfig {
123130
return {

src/extension.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ function clientWorkspaceForUri(
160160
if (!existing && options && options.startIfMissing) {
161161
const workspace = new ClientWorkspace(folder);
162162
workspaces.set(folder.uri.toString(), workspace);
163-
workspace.start();
163+
workspace.auto_start();
164164
}
165165

166166
return workspaces.get(folder.uri.toString());
@@ -188,6 +188,12 @@ class ClientWorkspace {
188188
this._progress = new Observable<{ message: string } | null>(null);
189189
}
190190

191+
public auto_start() {
192+
if (this.config.autoStartRls) {
193+
this.start();
194+
}
195+
}
196+
191197
public async start() {
192198
this._progress.value = { message: 'Starting' };
193199

@@ -265,6 +271,7 @@ class ClientWorkspace {
265271
public async stop() {
266272
if (this.lc) {
267273
await this.lc.stop();
274+
this.lc = null;
268275
}
269276

270277
this.disposables.forEach(d => d.dispose());
@@ -466,6 +473,14 @@ function registerCommands(): Disposable[] {
466473
'rls.run',
467474
(cmd: Execution) => activeWorkspace && activeWorkspace.runRlsCommand(cmd),
468475
),
476+
commands.registerCommand(
477+
'rls.start',
478+
() => activeWorkspace && activeWorkspace.start(),
479+
),
480+
commands.registerCommand(
481+
'rls.stop',
482+
() => activeWorkspace && activeWorkspace.stop(),
483+
),
469484
];
470485
}
471486

0 commit comments

Comments
 (0)