Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Dec 8, 2020. It is now read-only.

Commit e05e66b

Browse filesBrowse files
authored
Use rustfmt when run rls mode (#257)
1 parent 9bab179 commit e05e66b
Copy full SHA for e05e66b

File tree

6 files changed

+340
-154
lines changed
Filter options

6 files changed

+340
-154
lines changed

‎doc/main.md

Copy file name to clipboardExpand all lines: doc/main.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ The second one is recommended and at some point the first one will be removed.
1616

1717
But Legacy Mode should work just fine and if it doesn't, open an issue.
1818

19-
Unfortunately, sometimes RLS does not work as one can expect.
20-
In this situation one can set `"rust.forceLegacyMode"` to `true` and the extension will function in Legacy Mode.
19+
When the extension starts the first time, it asks to choose one of the modes.
20+
The chosen mode is stored in `"rust.mode"` and it can be changed by users.
2121

2222
Each mode is described in detail on its own page.
2323

‎doc/rls_mode/main.md

Copy file name to clipboardExpand all lines: doc/rls_mode/main.md
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ The type of the parameter is an object with the following fields:
1212
* `"args"` - an array of strings. Arguments to pass to the executable
1313
* `"env"` - an environment to append to the current environment to execute the executable
1414
* `"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
1516

1617
By default, it is `null`.
1718

18-
### The revealOutputChannelOn configuration parameter
19+
### More about configuration parameter
20+
21+
#### revealOutputChannelOn
1922

2023
This determines when the Output channel is revealed.
2124

@@ -26,6 +29,14 @@ The possible values are:
2629
* `"error"` - revealed on each error line (default)
2730
* `"never"` - the output channel never reveals automatically
2831

32+
#### useRustfmt
33+
34+
The possible values are:
35+
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
39+
2940
## Setting up
3041

3142
The recommended way to set RLS up is using rustup. You should use rustup unless rustup does not suit you.
@@ -157,3 +168,5 @@ Clicking on the indicator restarts RLS.
157168

158169
## Enabling formatting and renaming
159170
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.
171+
172+
[rustfmt]: https://github.com/rust-lang-nursery/rustfmt

‎package.json

Copy file name to clipboardExpand all lines: package.json
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,14 @@
504504
"never"
505505
],
506506
"type": "string"
507+
},
508+
"useRustfmt": {
509+
"default": null,
510+
"description": "Specified whether rustfmt should be used for formatting",
511+
"type": [
512+
"boolean",
513+
"null"
514+
]
507515
}
508516
}
509517
}

‎src/components/configuration/RlsConfiguration.ts

Copy file name to clipboardExpand all lines: src/components/configuration/RlsConfiguration.ts
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class RlsConfiguration {
1515
private _userArgs: string[];
1616
private _userEnv: object;
1717
private _revealOutputChannelOn: RevealOutputChannelOn;
18+
private _useRustfmt: boolean | undefined;
1819

1920
/**
2021
* Creates a new instance of the class
@@ -71,20 +72,50 @@ export class RlsConfiguration {
7172
return this._revealOutputChannelOn;
7273
}
7374

75+
/**
76+
* Returns whether rustfmt should be used for formatting
77+
*/
78+
public getUseRustfmt(): boolean | undefined {
79+
return this._useRustfmt;
80+
}
81+
82+
/**
83+
* Updates the property "useRustfmt" in the user configuration
84+
* @param value The new value
85+
*/
86+
public setUseRustfmt(value: boolean | undefined): void {
87+
if (this._useRustfmt === value) {
88+
return;
89+
}
90+
this._useRustfmt = value;
91+
const suitableValue = typeof value === 'boolean' ? value : null;
92+
updateUserConfigurationParameter(c => { c.useRustfmt = suitableValue; });
93+
}
94+
7495
private constructor(rustup: Rustup | undefined, rustSource: RustSource, executableUserPath: string | undefined) {
7596
this._rustup = rustup;
7697
this._rustSource = rustSource;
7798
this._executableUserPath = executableUserPath;
7899
this._userArgs = getUserArgs();
79100
this._userEnv = getUserEnv();
80101
this._revealOutputChannelOn = getUserRevealOutputChannelOn();
102+
this._useRustfmt = getUserUseRustfmt();
81103
}
82104
}
83105

84106
function getUserConfiguration(): any {
85107
return Configuration.getConfiguration()['rls'];
86108
}
87109

110+
function updateUserConfigurationParameter(updateParameter: (c: any) => void): void {
111+
let configuration = getUserConfiguration();
112+
if (!configuration) {
113+
configuration = {};
114+
}
115+
updateParameter(configuration);
116+
Configuration.getConfiguration().update('rls', configuration, true);
117+
}
118+
88119
function getExecutableUserPath(): string | undefined {
89120
const configuration = getUserConfiguration();
90121
if (!configuration) {
@@ -140,6 +171,18 @@ function getUserRevealOutputChannelOn(): RevealOutputChannelOn {
140171
}
141172
}
142173

174+
function getUserUseRustfmt(): boolean | undefined {
175+
const configuration = getUserConfiguration();
176+
if (!configuration) {
177+
return undefined;
178+
}
179+
const useRustfmt = configuration.useRustfmt;
180+
if (typeof useRustfmt === 'boolean') {
181+
return useRustfmt;
182+
} else {
183+
return undefined;
184+
}
185+
}
143186

144187
async function getCheckedExecutableUserPath(): Promise<string | undefined> {
145188
const path = getExecutableUserPath();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.