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

Support VSCode workspaces #333

Merged
merged 3 commits into from
Jun 12, 2018
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### Unreleased

* Support VSCode workspaces

### 0.4.5 - 2018-06-03

* Undo the change to target directory default (unnecessary with Rust 1.26.1)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ more details on building and debugging, etc., see [contributing.md](contributing
(or by entering `ext install rust` at the command palette).
* (Skip this step if you already have Rust projects that you'd like to work on.)
Create a new Rust project by following [these instructions](https://doc.rust-lang.org/book/second-edition/ch01-02-hello-world.html#creating-a-project-with-cargo).
* Open a Rust project (`File > Open Folder...`). Open the folder for the whole
* Open a Rust project (`File > Add Folder to Workspace...`). Open the folder for the whole
project (i.e., the folder containing 'Cargo.toml'), not the 'src' folder.
* You'll be prompted to install the RLS. Once installed, the RLS should start
building your project.
Expand Down
68 changes: 44 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,120 +197,140 @@
"null"
],
"default": null,
"description": "--sysroot"
"description": "--sysroot",
"scope": "resource"
},
"rust.target": {
"type": [
"string",
"null"
],
"default": null,
"description": "--target"
"description": "--target",
"scope": "resource"
},
"rust.rustflags": {
"type": [
"string",
"null"
],
"default": null,
"description": "Flags added to RUSTFLAGS."
"description": "Flags added to RUSTFLAGS.",
"scope": "resource"
},
"rust.clear_env_rust_log": {
"type": "boolean",
"default": true,
"description": "Clear the RUST_LOG environment variable before running rustc or cargo."
"description": "Clear the RUST_LOG environment variable before running rustc or cargo.",
"scope": "resource"
},
"rust.build_lib": {
"type": [
"boolean",
"null"
],
"default": null,
"description": "Specify to run analysis as if running `cargo check --lib`. Use `null` to auto-detect. (unstable)"
"description": "Specify to run analysis as if running `cargo check --lib`. Use `null` to auto-detect. (unstable)",
"scope": "resource"
},
"rust.build_bin": {
"type": [
"string",
"null"
],
"default": null,
"description": "Specify to run analysis as if running `cargo check --bin <name>`. Use `null` to auto-detect. (unstable)"
"description": "Specify to run analysis as if running `cargo check --bin <name>`. Use `null` to auto-detect. (unstable)",
"scope": "resource"
},
"rust.cfg_test": {
"type": "boolean",
"default": false,
"description": "Build cfg(test) code. (unstable)"
"description": "Build cfg(test) code. (unstable)",
"scope": "resource"
},
"rust.unstable_features": {
"type": "boolean",
"default": false,
"description": "Enable unstable features."
"description": "Enable unstable features.",
"scope": "resource"
},
"rust.wait_to_build": {
"type": "number",
"default": 1500,
"description": "Time in milliseconds between receiving a change notification and starting build."
"description": "Time in milliseconds between receiving a change notification and starting build.",
"scope": "resource"
},
"rust.show_warnings": {
"type": "boolean",
"default": true,
"description": "Show warnings."
},
"rust.goto_def_racer_fallback": {
"type": "boolean",
"default": false,
"description": "Use racer as a fallback for goto def."
"description": "Show warnings.",
"scope": "resource"
},
"rust.use_crate_blacklist": {
"type": "boolean",
"default": true,
"description": "Don't index crates on the crate blacklist."
"description": "Don't index crates on the crate blacklist.",
"scope": "resource"
},
"rust.build_on_save": {
"type": "boolean",
"default": false,
"description": "Only index the project when a file is saved and not on change."
"description": "Only index the project when a file is saved and not on change.",
"scope": "resource"
},
"rust.features": {
"type": "array",
"default": [],
"description": "A list of Cargo features to enable."
"description": "A list of Cargo features to enable.",
"scope": "resource"
},
"rust.all_features": {
"type": "boolean",
"default": false,
"description": "Enable all Cargo features."
"description": "Enable all Cargo features.",
"scope": "resource"
},
"rust.no_default_features": {
"type": "boolean",
"default": false,
"description": "Do not enable default Cargo features."
"description": "Do not enable default Cargo features.",
"scope": "resource"
},
"rust.goto_def_racer_fallback": {
"type": "boolean",
"default": false,
"description": "Use racer as a fallback for goto def.",
"scope": "resource"
},
"rust.racer_completion": {
"type": "boolean",
"default": true,
"description": "Enables code completion using racer."
"description": "Enables code completion using racer.",
"scope": "resource"
},
"rust.jobs": {
"type": [
"number",
"null"
],
"default": null,
"description": "Number of Cargo jobs to be run in parallel."
"description": "Number of Cargo jobs to be run in parallel.",
"scope": "resource"
},
"rust.all_targets": {
"type": "boolean",
"default": true,
"description": "Checks the project as if you were running cargo check --all-targets (I.e., check all targets and integration tests too)."
"description": "Checks the project as if you were running cargo check --all-targets (I.e., check all targets and integration tests too).",
"scope": "resource"
},
"rust.target_dir": {
"type": [
"string",
"null"
],
"default": null,
"description": "When specified, it places the generated analysis files at the specified target directory. By default it is placed target/rls directory."
"description": "When specified, it places the generated analysis files at the specified target directory. By default it is placed target/rls directory.",
"scope": "resource"
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { workspace, WorkspaceConfiguration } from 'vscode';
import { RevealOutputChannelOn } from 'vscode-languageclient';

import { getActiveChannel } from './rustup';
import { getActiveChannel, RustupConfig } from './rustup';

function fromStringToRevealOutputChannelOn(value: string): RevealOutputChannelOn {
switch (value && value.toLowerCase()) {
Expand Down Expand Up @@ -41,19 +41,18 @@ export class RLSConfiguration {
*/
public readonly rlsPath: string | null;

public static loadFromWorkspace(): RLSConfiguration {
public static loadFromWorkspace(wsPath: string): RLSConfiguration {
const configuration = workspace.getConfiguration();

return new RLSConfiguration(configuration);
return new RLSConfiguration(configuration, wsPath);
}

private constructor(configuration: WorkspaceConfiguration) {
private constructor(configuration: WorkspaceConfiguration, wsPath: string) {
this.rustupPath = configuration.get('rust-client.rustupPath', 'rustup');
this.logToFile = configuration.get<boolean>('rust-client.logToFile', false);
this.revealOutputChannelOn = RLSConfiguration.readRevealOutputChannelOn(configuration);
this.updateOnStartup = configuration.get<boolean>('rust-client.updateOnStartup', true);

this.channel = RLSConfiguration.readChannel(this.rustupPath, configuration);
this.channel = RLSConfiguration.readChannel(this.rustupPath, configuration, wsPath);
this.componentName = configuration.get('rust-client.rls-name', 'rls');

// Path to the rls. Prefer `rust-client.rlsPath` if present, otherwise consider
Expand All @@ -68,6 +67,10 @@ export class RLSConfiguration {
}
}

public rustupConfig(): RustupConfig {
return new RustupConfig(this.channel, this.rustupPath, this.componentName);
}

private static readRevealOutputChannelOn(configuration: WorkspaceConfiguration) {
const setting = configuration.get<string>('rust-client.revealOutputChannelOn', 'never');
return fromStringToRevealOutputChannelOn(setting);
Expand All @@ -78,13 +81,13 @@ export class RLSConfiguration {
* falls back on active toolchain specified by rustup (at `rustupPath`),
* finally defaulting to `nightly` if all fails.
*/
private static readChannel(rustupPath: string, configuration: WorkspaceConfiguration): string {
private static readChannel(rustupPath: string, configuration: WorkspaceConfiguration, wsPath: string): string {
const channel = configuration.get<string | null>('rust-client.channel', null);
if (channel !== null) {
return channel;
} else {
try {
return getActiveChannel(rustupPath);
return getActiveChannel(rustupPath, wsPath);
}
// rustup might not be installed at the time the configuration is
// initially loaded, so silently ignore the error and return a default value
Expand Down
Loading