Skip to content
This repository was archived by the owner on Dec 8, 2020. It is now read-only.

Commit b03b857

Browse files
authored
"rust.rls" object has been split into multiple parameters (#344)
1 parent 4d3022c commit b03b857

File tree

5 files changed

+293
-182
lines changed

5 files changed

+293
-182
lines changed

doc/rls_mode/main.md

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,74 @@
11
# Rust Language Server Mode Page
22

3-
The extension supports integration with [Rust Language Server](https://github.com/rust-lang-nursery/rls).
3+
The extension supports integration with [Rust Language Server].
44

55
## Configuration
66

7-
The `"rust.rls"` configuration parameter specifies how to run RLS if it is requested.
7+
There are configuration parameters which names start with `"rust.rls"`.
8+
The RLS mode can be configured by changing the parameters.
89

9-
The type of the parameter is an object with the following fields:
10+
### Parameters
1011

11-
* `"executable"` - a string. The path to an executable to execute
12-
* `"args"` - an array of strings. Arguments to pass to the executable
13-
* `"env"` - an environment to append to the current environment to execute the executable
14-
* `"revealOutputChannelOn"` - a string. Specifies the condition when the output channel should be revealed
15-
* `"useRustfmt"` - either a boolean or `null`. Specifies whether [rustfmt] should be used for formatting
12+
#### rust.rls.executable
1613

17-
By default, it is `null`.
14+
Using the parameter it is possible to specify either absolute path to RLS or name of RLS.
1815

19-
### More about configuration parameter
16+
The default value is `"rls"`.
2017

21-
#### revealOutputChannelOn
18+
It can be useful when:
2219

23-
This determines when the Output channel is revealed.
20+
* There is a need in running RLS built from its source
21+
* There is a need in running RLS through some proxy (see [rust.rls.args](#rust.rls.executable]))
2422

25-
The possible values are:
23+
#### rust.rls.args
2624

27-
* `"info"` - revealed on each info line
28-
* `"warn"` - revealed on each warn line
29-
* `"error"` - revealed on each error line (default)
30-
* `"never"` - the output channel never reveals automatically
25+
Using the parameter it is possible to specify what arguments to run the RLS executable with.
3126

32-
#### useRustfmt
27+
The default value is `null`.
3328

34-
The possible values are:
29+
It can be useful when:
3530

36-
* `null` - the extension will ask whether [rustfmt] should be used for formatting
37-
* `false` - the extension will not use [rustfmt] for formatting
38-
* `true` - the extension will use [rustfmt] for formatting
31+
* There is a need in running RLS through some proxy, i.e., rustup
32+
33+
#### rust.rls.env
34+
35+
Using the parameter it is possible to specify what environment to run the RLS executable in.
36+
37+
The default value is `null`.
38+
39+
It can be useful when:
40+
41+
* There is a need to pass some environment variables to the RLS executable, i.e., `RUST_LOG`, `RUST_BACKTRACE`
42+
43+
#### rust.rls.revealOutputChannelOn
44+
45+
Using the parameter it is possible to specify on what kind of message received from the RLS the output channel is revealed.
46+
47+
It supports one of the following values:
48+
49+
* `"info"` - the output channel is revealed on literally all messages
50+
* `"warn"` - the output channel is revealed on warnings
51+
* `"error"` - the output channel is revealed on errors (default)
52+
* `"never"` - the output channel is never revealed automatically (it can be revealed manually through *View->Output*)
53+
54+
The default value is `error`.
55+
56+
It can be useful when:
57+
58+
* There is some problem with RLS and it sometimes sends error messages on which the output channel is revealed and it is annoying
59+
* There is a need in revealing the output channel on other kinds of message
60+
61+
#### rust.rls.useRustfmt
62+
63+
Using the parameter it is possible to specify if the standalone [rustfmt] is used to format code instead of the [rustfmt] embedded into RLS.
64+
65+
It supports one of the following values:
66+
67+
* `null` - the extension will ask if [rustfmt] is used to format code
68+
* `false` - the extension will not use [rustfmt] to format code
69+
* `true` - the extension will use [rustfmt] to format code
70+
71+
The default value is `null`.
3972

4073
## Setting up
4174

@@ -80,21 +113,17 @@ rustup run nightly cargo install
80113
Because at the moment RLS links to the compiler and it assumes the compiler to be globally installed, one has to use rustup to start the `rls` (rustup will configure the environment accordingly):
81114

82115
```json
83-
"rust.rls": {
84-
"executable": "rustup",
85-
"args": ["run", "nightly", "rls"]
86-
}
116+
"rust.rls.executable": "rustup",
117+
"rust.rls.args": ["run", "nightly", "rls"]
87118
```
88119

89120
--
90121

91122
You can also run from source by passing `+nightly` to rustup's cargo proxy:
92123

93124
```json
94-
"rust.rls": {
95-
"executable": "cargo",
96-
"args": ["+nightly", "run", "--manifest-path=/path/to/rls/Cargo.toml", "--release"]
97-
}
125+
"rust.rls.executable": "cargo",
126+
"rust.rls.args": ["+nightly", "run", "--manifest-path=/path/to/rls/Cargo.toml", "--release"]
98127
```
99128

100129
#### Without rustup
@@ -113,20 +142,16 @@ cargo install
113142
and set `"executable"` to `"rls"`:
114143

115144
```json
116-
"rust.rls": {
117-
"executable": "rls"
118-
}
145+
"rust.rls.executable": "rls"
119146
```
120147

121148
--
122149

123150
If you don't want to have it installed you can also run it from sources:
124151

125152
```json
126-
"rust.rls": {
127-
"executable": "cargo",
128-
"args": ["run", "--manifest-path=/path/to/rls/Cargo.toml", "--release"]
129-
}
153+
"rust.rls.executable": "cargo",
154+
"rust.rls.args": ["run", "--manifest-path=/path/to/rls/Cargo.toml", "--release"]
130155
```
131156

132157
## Debugging
@@ -140,14 +165,11 @@ To open it, perform the following steps:
140165
* Click on the listbox which is to the right of the shown panel
141166
* Choose "Rust Language Server"
142167

143-
For making RLS print more data, you have to add the following lines to your `"rust.rls"` configuration:
168+
For making RLS print more data, you have to add the following lines to your [RLS] configuration:
144169

145170
```json
146-
"rust.rls": {
147-
...
148-
"env": {
149-
"RUST_LOG": "rls=debug"
150-
}
171+
"rust.rls.env": {
172+
"RUST_LOG": "rls=debug"
151173
}
152174
```
153175

@@ -170,3 +192,5 @@ Clicking on the indicator restarts RLS.
170192
Create a `rls.toml` file in your project's root and add `unstable_features = true` and RLS will be able to auto format on save and renaming.
171193

172194
[rustfmt]: https://github.com/rust-lang-nursery/rustfmt
195+
[Rust Language Server]: https://github.com/rust-lang-nursery/rls
196+
[RLS]: https://github.com/rust-lang-nursery/rls

package.json

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -488,54 +488,51 @@
488488
}
489489
}
490490
},
491-
"rust.rls": {
491+
"rust.rls.executable": {
492492
"default": null,
493-
"description": "Rust Language Server configuration",
494-
"properties": {
495-
"executable": {
496-
"default": "rls",
497-
"description": "An executable to run as a language server",
498-
"type": "string"
499-
},
500-
"args": {
501-
"default": null,
502-
"description": "Arguments to pass to the executable",
503-
"items": {
504-
"type": "string"
505-
},
506-
"type": [
507-
"array",
508-
"null"
509-
]
510-
},
511-
"env": {
512-
"default": null,
513-
"description": "An environment to run the executable in",
514-
"type": [
515-
"object",
516-
"null"
517-
]
518-
},
519-
"revealOutputChannelOn": {
520-
"default": "error",
521-
"description": "Specifies when the output channel should be revealed",
522-
"enum": [
523-
"info",
524-
"warn",
525-
"error",
526-
"never"
527-
],
528-
"type": "string"
529-
},
530-
"useRustfmt": {
531-
"default": null,
532-
"description": "Specified whether rustfmt should be used for formatting",
533-
"type": [
534-
"boolean",
535-
"null"
536-
]
537-
}
538-
}
493+
"description": "An executable (absolute path or name if it's available through PATH) to run as a language server",
494+
"type": [
495+
"null",
496+
"string"
497+
]
498+
},
499+
"rust.rls.args": {
500+
"default": null,
501+
"description": "Arguments to run the language server with",
502+
"items": {
503+
"type": "string"
504+
},
505+
"type": [
506+
"array",
507+
"null"
508+
]
509+
},
510+
"rust.rls.env": {
511+
"default": null,
512+
"description": "An environment to run the language server in",
513+
"type": [
514+
"object",
515+
"null"
516+
]
517+
},
518+
"rust.rls.revealOutputChannelOn": {
519+
"default": "error",
520+
"description": "Specifies on what kind of message received from the language server the output channel is revealed",
521+
"enum": [
522+
"info",
523+
"warn",
524+
"error",
525+
"never"
526+
],
527+
"type": "string"
528+
},
529+
"rust.rls.useRustfmt": {
530+
"default": null,
531+
"description": "Specified whether rustfmt should be used for formatting when the RLS mode is active",
532+
"type": [
533+
"boolean",
534+
"null"
535+
]
539536
},
540537
"rust.shell.kind.windows": {
541538
"default": "null",

src/ConfigurationParameter.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import { WorkspaceConfiguration, workspace } from 'vscode';
55
* the value of the parameter
66
*/
77
export class ConfigurationParameter {
8+
private _sectionName: string;
89
private _parameterName: string;
910

10-
public constructor(parameterName: string) {
11+
public constructor(sectionName: string, parameterName: string) {
12+
this._sectionName = sectionName;
1113
this._parameterName = parameterName;
1214
}
1315

@@ -22,10 +24,16 @@ export class ConfigurationParameter {
2224
* of the workspace settings
2325
*/
2426
public async setValue(value: any, setToUserConfiguration: boolean): Promise<void> {
25-
await this.getConfiguration().update(this._parameterName, value, setToUserConfiguration);
27+
// The configuration doesn't support `undefined`. We must convert it to `null`
28+
const convertedValue = value === undefined ? null : value;
29+
await this.getConfiguration().update(
30+
this._parameterName,
31+
convertedValue,
32+
setToUserConfiguration
33+
);
2634
}
2735

2836
private getConfiguration(): WorkspaceConfiguration {
29-
return workspace.getConfiguration('');
37+
return workspace.getConfiguration(this._sectionName);
3038
}
3139
}

src/WindowsShellProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export class WindowsShellProvider implements IShellProvider {
2727
*/
2828
public constructor(logger: ILogger) {
2929
this._logger = logger.createChildLogger('WindowsShellProvider: ');
30-
this._specialConfigurationParameter = new ConfigurationParameter('rust.shell.kind.windows');
30+
this._specialConfigurationParameter = new ConfigurationParameter('rust.shell.kind', 'windows');
3131
this._gettingValueFromSpecialConfigurationParameter = new GettingValueFromSpecialConfigurationParameter(this._specialConfigurationParameter);
3232
this._determiningValueFromTerminalExecutable = new DeterminingValueFromTerminalExecutable(
33-
new ConfigurationParameter('terminal.integrated.shell.windows')
33+
new ConfigurationParameter('terminal.integrated.shell', 'windows')
3434
);
3535
this._askingUserToChooseValue = new AskingUserToChooseValue(logger);
3636
}

0 commit comments

Comments
 (0)