mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Keep VSCode config mostly backwards compatible
This commit is contained in:
parent
71d2d81dcc
commit
0cdbd08149
8 changed files with 71 additions and 84 deletions
|
@ -39,22 +39,14 @@ pub struct CheckWatcher {
|
||||||
|
|
||||||
impl CheckWatcher {
|
impl CheckWatcher {
|
||||||
pub fn new(options: &Options, workspace_root: PathBuf) -> CheckWatcher {
|
pub fn new(options: &Options, workspace_root: PathBuf) -> CheckWatcher {
|
||||||
let check_enabled = options.cargo_check_enable;
|
let options = options.clone();
|
||||||
let check_command = options.cargo_check_command.clone();
|
|
||||||
let check_args = options.cargo_check_args.clone();
|
|
||||||
let shared = Arc::new(RwLock::new(CheckWatcherSharedState::new()));
|
let shared = Arc::new(RwLock::new(CheckWatcherSharedState::new()));
|
||||||
|
|
||||||
let (task_send, task_recv) = unbounded::<CheckTask>();
|
let (task_send, task_recv) = unbounded::<CheckTask>();
|
||||||
let (cmd_send, cmd_recv) = unbounded::<CheckCommand>();
|
let (cmd_send, cmd_recv) = unbounded::<CheckCommand>();
|
||||||
let shared_ = shared.clone();
|
let shared_ = shared.clone();
|
||||||
let handle = std::thread::spawn(move || {
|
let handle = std::thread::spawn(move || {
|
||||||
let mut check = CheckWatcherState::new(
|
let mut check = CheckWatcherState::new(options, workspace_root, shared_);
|
||||||
check_enabled,
|
|
||||||
check_command,
|
|
||||||
check_args,
|
|
||||||
workspace_root,
|
|
||||||
shared_,
|
|
||||||
);
|
|
||||||
check.run(&task_send, &cmd_recv);
|
check.run(&task_send, &cmd_recv);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -68,9 +60,7 @@ impl CheckWatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CheckWatcherState {
|
pub struct CheckWatcherState {
|
||||||
check_enabled: bool,
|
options: Options,
|
||||||
check_command: Option<String>,
|
|
||||||
check_args: Vec<String>,
|
|
||||||
workspace_root: PathBuf,
|
workspace_root: PathBuf,
|
||||||
running: bool,
|
running: bool,
|
||||||
watcher: WatchThread,
|
watcher: WatchThread,
|
||||||
|
@ -162,18 +152,13 @@ pub enum CheckCommand {
|
||||||
|
|
||||||
impl CheckWatcherState {
|
impl CheckWatcherState {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
check_enabled: bool,
|
options: Options,
|
||||||
check_command: Option<String>,
|
|
||||||
check_args: Vec<String>,
|
|
||||||
workspace_root: PathBuf,
|
workspace_root: PathBuf,
|
||||||
shared: Arc<RwLock<CheckWatcherSharedState>>,
|
shared: Arc<RwLock<CheckWatcherSharedState>>,
|
||||||
) -> CheckWatcherState {
|
) -> CheckWatcherState {
|
||||||
let watcher =
|
let watcher = WatchThread::new(&options, &workspace_root);
|
||||||
WatchThread::new(check_enabled, check_command.as_ref(), &check_args, &workspace_root);
|
|
||||||
CheckWatcherState {
|
CheckWatcherState {
|
||||||
check_enabled,
|
options,
|
||||||
check_command,
|
|
||||||
check_args,
|
|
||||||
workspace_root,
|
workspace_root,
|
||||||
running: false,
|
running: false,
|
||||||
watcher,
|
watcher,
|
||||||
|
@ -204,12 +189,7 @@ impl CheckWatcherState {
|
||||||
self.shared.write().clear(task_send);
|
self.shared.write().clear(task_send);
|
||||||
|
|
||||||
self.watcher.cancel();
|
self.watcher.cancel();
|
||||||
self.watcher = WatchThread::new(
|
self.watcher = WatchThread::new(&self.options, &self.workspace_root);
|
||||||
self.check_enabled,
|
|
||||||
self.check_command.as_ref(),
|
|
||||||
&self.check_args,
|
|
||||||
&self.workspace_root,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,25 +286,23 @@ enum CheckEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WatchThread {
|
impl WatchThread {
|
||||||
fn new(
|
fn new(options: &Options, workspace_root: &PathBuf) -> WatchThread {
|
||||||
check_enabled: bool,
|
|
||||||
check_command: Option<&String>,
|
|
||||||
check_args: &[String],
|
|
||||||
workspace_root: &PathBuf,
|
|
||||||
) -> WatchThread {
|
|
||||||
let check_command = check_command.cloned().unwrap_or("check".to_string());
|
|
||||||
let mut args: Vec<String> = vec![
|
let mut args: Vec<String> = vec![
|
||||||
check_command,
|
options.cargo_watch_command.clone(),
|
||||||
"--message-format=json".to_string(),
|
"--message-format=json".to_string(),
|
||||||
"--manifest-path".to_string(),
|
"--manifest-path".to_string(),
|
||||||
format!("{}/Cargo.toml", workspace_root.to_string_lossy()),
|
format!("{}/Cargo.toml", workspace_root.to_string_lossy()),
|
||||||
];
|
];
|
||||||
args.extend(check_args.iter().cloned());
|
if options.cargo_watch_all_targets {
|
||||||
|
args.push("--all-targets".to_string());
|
||||||
|
}
|
||||||
|
args.extend(options.cargo_watch_args.iter().cloned());
|
||||||
|
|
||||||
let (message_send, message_recv) = unbounded();
|
let (message_send, message_recv) = unbounded();
|
||||||
let (cancel_send, cancel_recv) = unbounded();
|
let (cancel_send, cancel_recv) = unbounded();
|
||||||
|
let enabled = options.cargo_watch_enable;
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
if !check_enabled {
|
if !enabled {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,10 @@ pub struct ServerConfig {
|
||||||
|
|
||||||
pub max_inlay_hint_length: Option<usize>,
|
pub max_inlay_hint_length: Option<usize>,
|
||||||
|
|
||||||
pub cargo_check_enable: bool,
|
pub cargo_watch_enable: bool,
|
||||||
pub cargo_check_command: Option<String>,
|
pub cargo_watch_args: Vec<String>,
|
||||||
pub cargo_check_args: Vec<String>,
|
pub cargo_watch_command: String,
|
||||||
|
pub cargo_watch_all_targets: bool,
|
||||||
|
|
||||||
/// For internal usage to make integrated tests faster.
|
/// For internal usage to make integrated tests faster.
|
||||||
#[serde(deserialize_with = "nullable_bool_true")]
|
#[serde(deserialize_with = "nullable_bool_true")]
|
||||||
|
@ -55,9 +56,10 @@ impl Default for ServerConfig {
|
||||||
use_client_watching: false,
|
use_client_watching: false,
|
||||||
lru_capacity: None,
|
lru_capacity: None,
|
||||||
max_inlay_hint_length: None,
|
max_inlay_hint_length: None,
|
||||||
cargo_check_enable: true,
|
cargo_watch_enable: true,
|
||||||
cargo_check_command: None,
|
cargo_watch_args: Vec::new(),
|
||||||
cargo_check_args: vec![],
|
cargo_watch_command: "check".to_string(),
|
||||||
|
cargo_watch_all_targets: true,
|
||||||
with_sysroot: true,
|
with_sysroot: true,
|
||||||
feature_flags: FxHashMap::default(),
|
feature_flags: FxHashMap::default(),
|
||||||
cargo_features: Default::default(),
|
cargo_features: Default::default(),
|
||||||
|
|
|
@ -127,9 +127,10 @@ pub fn main_loop(
|
||||||
.and_then(|it| it.line_folding_only)
|
.and_then(|it| it.line_folding_only)
|
||||||
.unwrap_or(false),
|
.unwrap_or(false),
|
||||||
max_inlay_hint_length: config.max_inlay_hint_length,
|
max_inlay_hint_length: config.max_inlay_hint_length,
|
||||||
cargo_check_enable: config.cargo_check_enable,
|
cargo_watch_enable: config.cargo_watch_enable,
|
||||||
cargo_check_command: config.cargo_check_command,
|
cargo_watch_args: config.cargo_watch_args,
|
||||||
cargo_check_args: config.cargo_check_args,
|
cargo_watch_command: config.cargo_watch_command,
|
||||||
|
cargo_watch_all_targets: config.cargo_watch_all_targets,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,10 @@ pub struct Options {
|
||||||
pub supports_location_link: bool,
|
pub supports_location_link: bool,
|
||||||
pub line_folding_only: bool,
|
pub line_folding_only: bool,
|
||||||
pub max_inlay_hint_length: Option<usize>,
|
pub max_inlay_hint_length: Option<usize>,
|
||||||
pub cargo_check_enable: bool,
|
pub cargo_watch_enable: bool,
|
||||||
pub cargo_check_command: Option<String>,
|
pub cargo_watch_args: Vec<String>,
|
||||||
pub cargo_check_args: Vec<String>,
|
pub cargo_watch_command: String,
|
||||||
|
pub cargo_watch_all_targets: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `WorldState` is the primary mutable state of the language server
|
/// `WorldState` is the primary mutable state of the language server
|
||||||
|
|
|
@ -188,11 +188,6 @@
|
||||||
"default": "ra_lsp_server",
|
"default": "ra_lsp_server",
|
||||||
"description": "Path to ra_lsp_server executable"
|
"description": "Path to ra_lsp_server executable"
|
||||||
},
|
},
|
||||||
"rust-analyzer.enableCargoCheck": {
|
|
||||||
"type": "boolean",
|
|
||||||
"default": true,
|
|
||||||
"description": "Run `cargo check` for diagnostics on save"
|
|
||||||
},
|
|
||||||
"rust-analyzer.excludeGlobs": {
|
"rust-analyzer.excludeGlobs": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"default": [],
|
"default": [],
|
||||||
|
@ -203,16 +198,26 @@
|
||||||
"default": true,
|
"default": true,
|
||||||
"description": "client provided file watching instead of notify watching."
|
"description": "client provided file watching instead of notify watching."
|
||||||
},
|
},
|
||||||
"rust-analyzer.cargo-check.arguments": {
|
"rust-analyzer.cargo-watch.enable": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true,
|
||||||
|
"description": "Run `cargo check` for diagnostics on save"
|
||||||
|
},
|
||||||
|
"rust-analyzer.cargo-watch.arguments": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"description": "`cargo-check` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo check --features=\"shumway,pdf\"` )",
|
"description": "`cargo-watch` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )",
|
||||||
"default": []
|
"default": []
|
||||||
},
|
},
|
||||||
"rust-analyzer.cargo-check.command": {
|
"rust-analyzer.cargo-watch.command": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "`cargo-check` command. (e.g: `clippy` will run as `cargo clippy` )",
|
"description": "`cargo-watch` command. (e.g: `clippy` will run as `cargo watch -x clippy` )",
|
||||||
"default": "check"
|
"default": "check"
|
||||||
},
|
},
|
||||||
|
"rust-analyzer.cargo-watch.allTargets": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Check all targets and tests (will be passed as `--all-targets`)",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
"rust-analyzer.trace.server": {
|
"rust-analyzer.trace.server": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"scope": "window",
|
"scope": "window",
|
||||||
|
@ -229,17 +234,6 @@
|
||||||
"default": "off",
|
"default": "off",
|
||||||
"description": "Trace requests to the ra_lsp_server"
|
"description": "Trace requests to the ra_lsp_server"
|
||||||
},
|
},
|
||||||
"rust-analyzer.trace.cargo-watch": {
|
|
||||||
"type": "string",
|
|
||||||
"scope": "window",
|
|
||||||
"enum": [
|
|
||||||
"off",
|
|
||||||
"error",
|
|
||||||
"verbose"
|
|
||||||
],
|
|
||||||
"default": "off",
|
|
||||||
"description": "Trace output of cargo-watch"
|
|
||||||
},
|
|
||||||
"rust-analyzer.lruCapacity": {
|
"rust-analyzer.lruCapacity": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"default": null,
|
"default": null,
|
||||||
|
|
|
@ -4,10 +4,11 @@ import { Server } from './server';
|
||||||
|
|
||||||
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
|
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
|
||||||
|
|
||||||
export interface CargoCheckOptions {
|
export interface CargoWatchOptions {
|
||||||
enabled: boolean;
|
enable: boolean;
|
||||||
arguments: string[];
|
arguments: string[];
|
||||||
command: null | string;
|
command: string;
|
||||||
|
allTargets: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CargoFeatures {
|
export interface CargoFeatures {
|
||||||
|
@ -29,10 +30,11 @@ export class Config {
|
||||||
public featureFlags = {};
|
public featureFlags = {};
|
||||||
// for internal use
|
// for internal use
|
||||||
public withSysroot: null | boolean = null;
|
public withSysroot: null | boolean = null;
|
||||||
public cargoCheckOptions: CargoCheckOptions = {
|
public cargoWatchOptions: CargoWatchOptions = {
|
||||||
enabled: true,
|
enable: true,
|
||||||
arguments: [],
|
arguments: [],
|
||||||
command: null,
|
command: '',
|
||||||
|
allTargets: true,
|
||||||
};
|
};
|
||||||
public cargoFeatures: CargoFeatures = {
|
public cargoFeatures: CargoFeatures = {
|
||||||
noDefaultFeatures: false,
|
noDefaultFeatures: false,
|
||||||
|
@ -91,27 +93,34 @@ export class Config {
|
||||||
RA_LSP_DEBUG || (config.get('raLspServerPath') as string);
|
RA_LSP_DEBUG || (config.get('raLspServerPath') as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.has('enableCargoCheck')) {
|
if (config.has('cargo-watch.enable')) {
|
||||||
this.cargoCheckOptions.enabled = config.get<boolean>(
|
this.cargoWatchOptions.enable = config.get<boolean>(
|
||||||
'enableCargoCheck',
|
'cargo-watch.enable',
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.has('cargo-watch.arguments')) {
|
if (config.has('cargo-watch.arguments')) {
|
||||||
this.cargoCheckOptions.arguments = config.get<string[]>(
|
this.cargoWatchOptions.arguments = config.get<string[]>(
|
||||||
'cargo-watch.arguments',
|
'cargo-watch.arguments',
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.has('cargo-watch.command')) {
|
if (config.has('cargo-watch.command')) {
|
||||||
this.cargoCheckOptions.command = config.get<string>(
|
this.cargoWatchOptions.command = config.get<string>(
|
||||||
'cargo-watch.command',
|
'cargo-watch.command',
|
||||||
'',
|
'',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.has('cargo-watch.allTargets')) {
|
||||||
|
this.cargoWatchOptions.allTargets = config.get<boolean>(
|
||||||
|
'cargo-watch.allTargets',
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (config.has('lruCapacity')) {
|
if (config.has('lruCapacity')) {
|
||||||
this.lruCapacity = config.get('lruCapacity') as number;
|
this.lruCapacity = config.get('lruCapacity') as number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const watchStatus = new StatusDisplay(
|
const watchStatus = new StatusDisplay(
|
||||||
Server.config.cargoCheckOptions.command || 'check',
|
Server.config.cargoWatchOptions.command,
|
||||||
);
|
);
|
||||||
disposeOnDeactivation(watchStatus);
|
disposeOnDeactivation(watchStatus);
|
||||||
|
|
||||||
|
|
|
@ -55,9 +55,11 @@ export class Server {
|
||||||
publishDecorations: true,
|
publishDecorations: true,
|
||||||
lruCapacity: Server.config.lruCapacity,
|
lruCapacity: Server.config.lruCapacity,
|
||||||
maxInlayHintLength: Server.config.maxInlayHintLength,
|
maxInlayHintLength: Server.config.maxInlayHintLength,
|
||||||
cargoCheckEnable: Server.config.cargoCheckOptions.enabled,
|
cargoWatchEnable: Server.config.cargoWatchOptions.enable,
|
||||||
cargoCheckCommand: Server.config.cargoCheckOptions.command,
|
cargoWatchArgumets: Server.config.cargoWatchOptions.arguments,
|
||||||
cargoCheckArgs: Server.config.cargoCheckOptions.arguments,
|
cargoWatchCommand: Server.config.cargoWatchOptions.command,
|
||||||
|
cargoWatchAllTargets:
|
||||||
|
Server.config.cargoWatchOptions.allTargets,
|
||||||
excludeGlobs: Server.config.excludeGlobs,
|
excludeGlobs: Server.config.excludeGlobs,
|
||||||
useClientWatching: Server.config.useClientWatching,
|
useClientWatching: Server.config.useClientWatching,
|
||||||
featureFlags: Server.config.featureFlags,
|
featureFlags: Server.config.featureFlags,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue