Skip to content

fix: make file watcher config a drop-down (and clarify the options) #12804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2022
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
29 changes: 22 additions & 7 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ config_data! {
/// also need to add the folders to Code's `files.watcherExclude`.
files_excludeDirs: Vec<PathBuf> = "[]",
/// Controls file watching implementation.
files_watcher: String = "\"client\"",
files_watcher: FilesWatcherDef = "\"client\"",

/// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.
highlightRelated_breakPoints_enable: bool = "true",
Expand Down Expand Up @@ -524,7 +524,7 @@ pub struct FilesConfig {
#[derive(Debug, Clone)]
pub enum FilesWatcher {
Client,
Notify,
Server,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -903,12 +903,11 @@ impl Config {

pub fn files(&self) -> FilesConfig {
FilesConfig {
watcher: match self.data.files_watcher.as_str() {
"notify" => FilesWatcher::Notify,
"client" if self.did_change_watched_files_dynamic_registration() => {
watcher: match self.data.files_watcher {
FilesWatcherDef::Client if self.did_change_watched_files_dynamic_registration() => {
FilesWatcher::Client
}
_ => FilesWatcher::Notify,
_ => FilesWatcher::Server,
},
exclude: self.data.files_excludeDirs.iter().map(|it| self.root_path.join(it)).collect(),
}
Expand Down Expand Up @@ -1423,7 +1422,7 @@ enum ManifestOrProjectJson {

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub enum ExprFillDefaultDef {
enum ExprFillDefaultDef {
Todo,
Default,
}
Expand Down Expand Up @@ -1486,6 +1485,14 @@ enum ReborrowHintsDef {
Mutable,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
enum FilesWatcherDef {
Client,
Notify,
Server,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
enum ImportPrefixDef {
Expand Down Expand Up @@ -1843,6 +1850,14 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
"Show only the parameters."
],
},
"FilesWatcherDef" => set! {
"type": "string",
"enum": ["client", "server"],
"enumDescriptions": [
"Use the client (editor) to watch files for changes",
"Use server-side file watching",
],
},
_ => panic!("missing entry for {}: {}", ty, default),
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl GlobalState {

let watch = match files_config.watcher {
FilesWatcher::Client => vec![],
FilesWatcher::Notify => project_folders.watch,
FilesWatcher::Server => project_folders.watch,
};
self.vfs_config_version += 1;
self.loader.handle.set_config(vfs::loader::Config {
Expand Down
10 changes: 9 additions & 1 deletion editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,15 @@
"rust-analyzer.files.watcher": {
"markdownDescription": "Controls file watching implementation.",
"default": "client",
"type": "string"
"type": "string",
"enum": [
"client",
"server"
],
"enumDescriptions": [
"Use the client (editor) to watch files for changes",
"Use server-side file watching"
]
},
"rust-analyzer.highlightRelated.breakPoints.enable": {
"markdownDescription": "Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.",
Expand Down