Skip to content

Commit

Permalink
Sync file change logic from server to shell
Browse files Browse the repository at this point in the history
Summary:
ELP shell logic was out of sync with ELP server logic, causing crashes on file/project changes.

Reload project on SUITE creation, and correctly initialise file revision on any file creation.

Reviewed By: michalmuskala

Differential Revision: D58182610

fbshipit-source-id: 3da97e23157d682f60781d81bccf324e245caed5
  • Loading branch information
VLanvin authored and facebook-github-bot committed Jun 5, 2024
1 parent 687608f commit 106b771
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions crates/elp/src/bin/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use elp::document::Document;
use elp_eqwalizer::Mode;
use elp_ide::elp_ide_db::elp_base_db::bump_file_revision;
use elp_ide::elp_ide_db::elp_base_db::AbsPathBuf;
use elp_ide::elp_ide_db::elp_base_db::ChangeKind;
use elp_ide::elp_ide_db::elp_base_db::IncludeOtp;
use elp_ide::elp_ide_db::elp_base_db::SourceDatabase;
use elp_ide::elp_ide_db::elp_base_db::SourceDatabaseExt;
Expand Down Expand Up @@ -58,6 +59,8 @@ struct WatchmanChanges {
struct WatchmanFile {
name: String,
exists: bool,
#[serde(default)]
new: bool,
}

impl Watchman {
Expand Down Expand Up @@ -243,7 +246,11 @@ fn process_changes_to_vfs_store(loaded: &mut LoadResult) -> bool {
} else {
raw_database.set_file_text(file.file_id, Arc::from(""));
};
bump_file_revision(file.file_id, raw_database);
if file.change_kind == ChangeKind::Create {
raw_database.set_file_revision(file.file_id, 0);
} else {
bump_file_revision(file.file_id, raw_database);
}
}

if changed_files
Expand Down Expand Up @@ -278,10 +285,17 @@ fn should_reload_project(watchman: &Watchman, last_read: &WatchmanClock) -> Resu
"**/rebar.config",
"**/rebar.config.script",
];
Ok(!watchman
let project_path_changed = !watchman
.get_changes(last_read, project_paths)?
.files
.is_empty())
.is_empty();
let suite_files = vec!["**/*_SUITE.erl"];
let suite_file_created = watchman
.get_changes(last_read, suite_files)?
.files
.iter()
.any(|f| f.new || !f.exists);
Ok(project_path_changed || suite_file_created)
}

fn update_changes(
Expand Down

0 comments on commit 106b771

Please sign in to comment.