Skip to content

Commit fea4c3c

Browse files
committed
consolidated file update helper
1 parent 784b135 commit fea4c3c

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

crates/common/src/file/workspace.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ impl Workspace {
9898
.expect("Failed to create file")
9999
}
100100

101+
pub fn update(&self, db: &mut dyn InputDb, url: Url, content: String) -> File {
102+
let file = self.touch(db, url, None);
103+
file.set_text(db).to(content);
104+
file
105+
}
106+
101107
pub fn all_files(&self, db: &dyn InputDb) -> StringTrie<Url, File> {
102108
self.files(db)
103109
}

crates/language-server/src/functionality/handlers.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use async_lsp::{
1111
use common::InputDb;
1212
use driver::init_ingot;
1313
use rustc_hash::FxHashSet;
14-
use salsa::Setter;
1514
use url::Url;
1615

1716
use super::{capabilities::server_capabilities, hover::hover_helper};
@@ -255,7 +254,7 @@ pub async fn handle_file_change(
255254
backend
256255
.db
257256
.workspace()
258-
.touch(&mut backend.db, url.clone(), Some(contents));
257+
.update(&mut backend.db, url.clone(), contents);
259258
}
260259
}
261260
ChangeKind::Create => {
@@ -271,7 +270,7 @@ pub async fn handle_file_change(
271270
backend
272271
.db
273272
.workspace()
274-
.touch(&mut backend.db, url.clone(), Some(contents));
273+
.update(&mut backend.db, url.clone(), contents);
275274

276275
// If a fe.toml was created, discover and load all files in the new ingot
277276
if is_fe_toml {
@@ -295,11 +294,10 @@ pub async fn handle_file_change(
295294
}
296295
};
297296
if let Ok(url) = url::Url::from_file_path(&path) {
298-
let file = backend
297+
backend
299298
.db
300299
.workspace()
301-
.touch(&mut backend.db, url.clone(), None);
302-
file.set_text(&mut backend.db).to(contents);
300+
.update(&mut backend.db, url.clone(), contents);
303301

304302
// If fe.toml was modified, re-scan the ingot for any new files
305303
if is_fe_toml {

0 commit comments

Comments
 (0)