Skip to content

Commit 26ed4dd

Browse files
committed
More FilePath naming alignment
1 parent 080eea4 commit 26ed4dd

29 files changed

Lines changed: 277 additions & 269 deletions

crates/ark/src/console/console_annotate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -933,14 +933,14 @@ pub unsafe extern "C-unwind" fn ps_annotate_source(
933933
// R source references may flow back to the frontend, which expects its
934934
// own URI representation.
935935
let uri = Url::parse(&uri)?;
936-
let uri_id = FilePath::from_url(&uri);
936+
let path = FilePath::from_url(&uri);
937937

938938
let mut dap_guard = Console::get().debug_dap.lock().unwrap();
939939

940940
// If there are no breakpoints for this file, return NULL to signal no
941941
// annotation needed. Scope the mutable borrow so we can re-borrow after.
942942
let annotated = {
943-
let Some(entry) = dap_guard.breakpoints.get_mut(&uri_id) else {
943+
let Some(entry) = dap_guard.breakpoints.get_mut(&path) else {
944944
return Ok(harp::r_null());
945945
};
946946
let breakpoints = &mut entry.breakpoints;
@@ -956,12 +956,12 @@ pub unsafe extern "C-unwind" fn ps_annotate_source(
956956
};
957957

958958
// Notify frontend about any breakpoints marked invalid during annotation
959-
dap_guard.notify_invalid_breakpoints(&uri_id);
959+
dap_guard.notify_invalid_breakpoints(&path);
960960

961961
// Remove disabled breakpoints. Their verification state is now stale since
962962
// they weren't injected during this annotation. If the user re-enables
963963
// them, they'll be treated as new unverified breakpoints.
964-
if let Some(entry) = dap_guard.breakpoints.get_mut(&uri_id) {
964+
if let Some(entry) = dap_guard.breakpoints.get_mut(&path) {
965965
entry
966966
.breakpoints
967967
.retain(|bp| !matches!(bp.state, BreakpointState::Disabled));

crates/ark/src/console/console_repl.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,27 +1513,27 @@ impl Console {
15131513
// Keep the DAP lock while we are updating breakpoints
15141514
let mut dap_guard = self.debug_dap.lock().unwrap();
15151515

1516-
let uri_id = loc.as_ref().map(crate::url::file_path_from_code_location);
1516+
let path = loc.as_ref().map(crate::url::file_path_from_code_location);
15171517

15181518
// For notebook cells (`cellId` present in metadata), synthesize
15191519
// a `CodeLocation` pointing to the temp file that `dumpCell`
15201520
// wrote. This gives `annotate_input()` the file URI it needs
15211521
// for the `#line` directive and breakpoint injection.
1522-
let (uri_id, loc) = if cell_id.is_some() {
1522+
let (path, loc) = if cell_id.is_some() {
15231523
match dap_notebook::notebook_code_location(&code) {
15241524
Some(notebook_loc) => {
15251525
let id = FilePath::from_url(&notebook_loc.uri);
15261526
(Some(id), Some(notebook_loc))
15271527
},
1528-
None => (uri_id, loc),
1528+
None => (path, loc),
15291529
}
15301530
} else {
1531-
(uri_id, loc)
1531+
(path, loc)
15321532
};
15331533

1534-
let breakpoints = uri_id
1534+
let breakpoints = path
15351535
.as_ref()
1536-
.and_then(|uri_id| dap_guard.breakpoints.get_mut(uri_id))
1536+
.and_then(|path| dap_guard.breakpoints.get_mut(path))
15371537
.map(|entry| entry.breakpoints.as_mut_slice());
15381538

15391539
match PendingInputs::read(&code, loc, breakpoints) {
@@ -1552,9 +1552,9 @@ impl Console {
15521552

15531553
// Notify frontend about any breakpoints marked invalid during annotation.
15541554
// Remove disabled breakpoints.
1555-
if let Some(uri_id) = &uri_id {
1556-
dap_guard.notify_invalid_breakpoints(uri_id);
1557-
dap_guard.remove_disabled_breakpoints(uri_id);
1555+
if let Some(path) = &path {
1556+
dap_guard.notify_invalid_breakpoints(path);
1557+
dap_guard.remove_disabled_breakpoints(path);
15581558
}
15591559

15601560
drop(dap_guard);

crates/ark/src/dap/dap_state.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ mod tests {
962962

963963
use super::*;
964964

965-
fn url_id(s: &str) -> FilePath {
965+
fn file_path(s: &str) -> FilePath {
966966
FilePath::from_url(&Url::parse(s).unwrap())
967967
}
968968

@@ -997,7 +997,7 @@ mod tests {
997997
fn test_did_change_document_removes_breakpoints() {
998998
let (mut dap, rx) = create_test_dap();
999999

1000-
let uri = url_id("file:///test.R");
1000+
let uri = file_path("file:///test.R");
10011001
let hash = blake3::hash(b"test content");
10021002

10031003
dap.breakpoints.insert(uri.clone(), BreakpointEntry {
@@ -1034,7 +1034,7 @@ mod tests {
10341034
fn test_did_change_document_no_breakpoints_is_noop() {
10351035
let (mut dap, rx) = create_test_dap();
10361036

1037-
let uri = url_id("file:///test.R");
1037+
let uri = file_path("file:///test.R");
10381038

10391039
dap.did_change_document(&uri);
10401040

@@ -1045,8 +1045,8 @@ mod tests {
10451045
fn test_did_change_document_only_affects_target_uri() {
10461046
let (mut dap, rx) = create_test_dap();
10471047

1048-
let uri1 = url_id("file:///test1.R");
1049-
let uri2 = url_id("file:///test2.R");
1048+
let uri1 = file_path("file:///test1.R");
1049+
let uri2 = file_path("file:///test2.R");
10501050
let hash1 = blake3::hash(b"content 1");
10511051
let hash2 = blake3::hash(b"content 2");
10521052

@@ -1099,7 +1099,7 @@ mod tests {
10991099
shared_self: None,
11001100
};
11011101

1102-
let uri = url_id("file:///test.R");
1102+
let uri = file_path("file:///test.R");
11031103
let hash = blake3::hash(b"test content");
11041104

11051105
dap.breakpoints.insert(uri.clone(), BreakpointEntry {

crates/ark/src/lsp/state_handlers.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ pub(crate) fn did_open(
274274
lsp_state.parsers.insert(uri.clone(), parser);
275275
state.documents.insert(uri.clone(), document.clone());
276276

277-
let url_id = FilePath::from_url(&uri);
278-
state.db.upsert_editor(url_id, contents.to_string());
277+
let path = FilePath::from_url(&uri);
278+
state.db.upsert_editor(path, contents.to_string());
279279

280280
// NOTE: Do we need to call `update_config()` here?
281281
// update_config(vec![uri]).await;
@@ -302,8 +302,8 @@ pub(crate) fn did_change(
302302
document.on_did_change(parser, &params);
303303

304304
let new_contents = document.contents.to_string();
305-
let url_id = FilePath::from_url(uri);
306-
state.db.upsert_editor(url_id, new_contents);
305+
let path = FilePath::from_url(uri);
306+
state.db.upsert_editor(path, new_contents);
307307

308308
lsp::main_loop::index_update(vec![uri.clone()], state.clone());
309309

@@ -339,8 +339,8 @@ pub(crate) fn did_close(
339339
.remove(&uri)
340340
.ok_or(anyhow!("Failed to remove parser for URI: {uri}"))?;
341341

342-
let url_id = FilePath::from_url(&uri);
343-
state.db.close_editor(&url_id);
342+
let path = FilePath::from_url(&uri);
343+
state.db.close_editor(&path);
344344

345345
lsp::log_info!("did_close(): closed document with URI: '{uri}'.");
346346

crates/ark/src/lsp/tests/state_handlers.rs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ fn test_r_file_created_routes_through_add_file() {
252252

253253
let root = state.db.workspace_roots().roots(&state.db)[0];
254254
assert_eq!(root.scripts(&state.db).len(), 1);
255-
let url = FilePath::from_path_buf(path.clone()).unwrap();
256-
let file = state.db.file_by_path(&url).unwrap();
255+
let file_path = FilePath::from_path_buf(path.clone()).unwrap();
256+
let file = state.db.file_by_path(&file_path).unwrap();
257257
assert_eq!(file.contents(&state.db), "x <- 1\n");
258258
}
259259

@@ -272,10 +272,10 @@ fn test_r_file_changed_for_editor_open_file_is_skipped() {
272272
.documents
273273
.insert(url.clone(), Document::new("editor_v2\n", None));
274274
// Pretend the editor pushed its content into oak too.
275-
let url_id = FilePath::from_url(&url);
275+
let file_path = FilePath::from_url(&url);
276276
state
277277
.db
278-
.upsert_editor(url_id.clone(), "editor_v2\n".to_string());
278+
.upsert_editor(file_path.clone(), "editor_v2\n".to_string());
279279

280280
// Now disk-side `Changed` fires with stale disk content.
281281
fs::write(&path, "disk_v3\n").unwrap();
@@ -284,7 +284,7 @@ fn test_r_file_changed_for_editor_open_file_is_skipped() {
284284
};
285285
did_change_watched_files(params, &mut state).unwrap();
286286

287-
let file = state.db.file_by_path(&url_id).unwrap();
287+
let file = state.db.file_by_path(&file_path).unwrap();
288288
assert_eq!(file.contents(&state.db), "editor_v2\n");
289289
}
290290

@@ -296,15 +296,15 @@ fn test_r_file_deleted_routes_through_remove_file() {
296296
let mut state = workspace_state(tmp.path());
297297

298298
let path = tmp.path().join("a.R");
299-
let url_id = FilePath::from_path_buf(path.clone()).unwrap();
299+
let file_path = FilePath::from_path_buf(path.clone()).unwrap();
300300
let params = DidChangeWatchedFilesParams {
301301
changes: vec![event(&path, FileChangeType::DELETED)],
302302
};
303303
did_change_watched_files(params, &mut state).unwrap();
304304

305305
let root = state.db.workspace_roots().roots(&state.db)[0];
306306
assert_eq!(root.scripts(&state.db).len(), 1);
307-
assert!(state.db.file_by_path(&url_id).is_none());
307+
assert!(state.db.file_by_path(&file_path).is_none());
308308
}
309309

310310
#[test]
@@ -317,9 +317,13 @@ fn test_r_file_changed_for_unopened_file_updates_contents() {
317317
fs::write(&path, "v1\n").unwrap();
318318
let mut state = workspace_state(tmp.path());
319319

320-
let url_id = FilePath::from_path_buf(path.clone()).unwrap();
320+
let file_path = FilePath::from_path_buf(path.clone()).unwrap();
321321
assert_eq!(
322-
state.db.file_by_path(&url_id).unwrap().contents(&state.db),
322+
state
323+
.db
324+
.file_by_path(&file_path)
325+
.unwrap()
326+
.contents(&state.db),
323327
"v1\n"
324328
);
325329

@@ -330,7 +334,11 @@ fn test_r_file_changed_for_unopened_file_updates_contents() {
330334
did_change_watched_files(params, &mut state).unwrap();
331335

332336
assert_eq!(
333-
state.db.file_by_path(&url_id).unwrap().contents(&state.db),
337+
state
338+
.db
339+
.file_by_path(&file_path)
340+
.unwrap()
341+
.contents(&state.db),
334342
"v2\n"
335343
);
336344
}
@@ -352,18 +360,18 @@ fn test_r_file_deleted_for_editor_open_file_is_skipped() {
352360
state
353361
.documents
354362
.insert(url.clone(), Document::new("editor_v2\n", None));
355-
let url_id = FilePath::from_url(&url);
363+
let file_path = FilePath::from_url(&url);
356364
state
357365
.db
358-
.upsert_editor(url_id.clone(), "editor_v2\n".to_string());
366+
.upsert_editor(file_path.clone(), "editor_v2\n".to_string());
359367

360368
fs::remove_file(&path).unwrap();
361369
let params = DidChangeWatchedFilesParams {
362370
changes: vec![event(&path, FileChangeType::DELETED)],
363371
};
364372
did_change_watched_files(params, &mut state).unwrap();
365373

366-
let file = state.db.file_by_path(&url_id).unwrap();
374+
let file = state.db.file_by_path(&file_path).unwrap();
367375
assert_eq!(file.contents(&state.db), "editor_v2\n");
368376
}
369377

@@ -393,8 +401,8 @@ fn test_description_deleted_demotes_package_to_scripts() {
393401
assert!(root.packages(&state.db).is_empty());
394402
assert_eq!(root.scripts(&state.db).len(), 1);
395403

396-
let a_url = FilePath::from_path_buf(tmp.path().join("pkg/R/a.R")).unwrap();
397-
let file = state.db.file_by_path(&a_url).unwrap();
404+
let file_path = FilePath::from_path_buf(tmp.path().join("pkg/R/a.R")).unwrap();
405+
let file = state.db.file_by_path(&file_path).unwrap();
398406
assert_eq!(file.package(&state.db), None);
399407
}
400408

@@ -568,23 +576,23 @@ fn test_did_change_workspace_folders_preserves_open_buffer_across_churn() {
568576
// Simulate `didOpen` on the package file with editor-side content.
569577
let r_path = tmp.path().join("pkg/R/a.R");
570578
let url = Url::from_file_path(&r_path).unwrap();
571-
let url_id = FilePath::from_url(&url);
579+
let file_path = FilePath::from_url(&url);
572580
state
573581
.documents
574582
.insert(url.clone(), Document::new("editor <- 2\n", None));
575583
state
576584
.db
577-
.upsert_editor(url_id.clone(), "editor <- 2\n".to_string());
585+
.upsert_editor(file_path.clone(), "editor <- 2\n".to_string());
578586

579-
let file_before = state.db.file_by_path(&url_id).unwrap();
587+
let file_before = state.db.file_by_path(&file_path).unwrap();
580588

581589
// Remove the workspace folder. The handler builds the editor_owned set
582590
// from state.documents.keys() and passes it to oak; the buffer's file
583591
// routes to OrphanRoot rather than StaleRoot.
584592
let params = folders_change(vec![], vec![folder_for(tmp.path())]);
585593
did_change_workspace_folders(params, &mut state).unwrap();
586594

587-
let after_remove = state.db.file_by_path(&url_id).unwrap();
595+
let after_remove = state.db.file_by_path(&file_path).unwrap();
588596
assert_eq!(file_before, after_remove);
589597
assert_eq!(after_remove.package(&state.db), None);
590598
assert!(state
@@ -600,7 +608,7 @@ fn test_did_change_workspace_folders_preserves_open_buffer_across_churn() {
600608
let params = folders_change(vec![folder_for(tmp.path())], vec![]);
601609
did_change_workspace_folders(params, &mut state).unwrap();
602610

603-
let after_readd = state.db.file_by_path(&url_id).unwrap();
611+
let after_readd = state.db.file_by_path(&file_path).unwrap();
604612
assert_eq!(file_before, after_readd);
605613
assert!(after_readd.package(&state.db).is_some());
606614
assert_eq!(after_readd.contents(&state.db), "editor <- 2\n");
@@ -625,7 +633,7 @@ fn test_did_close_releases_orphan_file_to_stale() {
625633

626634
let r_path = tmp.path().join("pkg/R/a.R");
627635
let url = Url::from_file_path(&r_path).unwrap();
628-
let url_id = FilePath::from_url(&url);
636+
let file_path = FilePath::from_url(&url);
629637

630638
// Simulate `didOpen` via state mutation (matches the rest of the file's
631639
// pattern).
@@ -637,15 +645,15 @@ fn test_did_close_releases_orphan_file_to_stale() {
637645
.insert(url.clone(), tree_sitter::Parser::new());
638646
state
639647
.db
640-
.upsert_editor(url_id.clone(), "edited\n".to_string());
648+
.upsert_editor(file_path.clone(), "edited\n".to_string());
641649

642650
// Remove the workspace folder; file goes to orphan (editor-owned).
643651
did_change_workspace_folders(
644652
folders_change(vec![], vec![folder_for(tmp.path())]),
645653
&mut state,
646654
)
647655
.unwrap();
648-
let file = state.db.file_by_path(&url_id).unwrap();
656+
let file = state.db.file_by_path(&file_path).unwrap();
649657
assert!(state.db.orphan_root().files(&state.db).contains(&file));
650658

651659
// Init the aux channel here, after the workspace-folders churn: the

crates/ark_test/src/dummy_frontend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,8 +1834,8 @@ impl SourceFile {
18341834
// symlinks (e.g. macOS `/var/...` -> `/private/var/...`). To match that
18351835
// in tests, we also canonicalize here.
18361836
let canonical = file.path().canonicalize().unwrap();
1837-
let url = FilePath::from_path_buf(canonical.clone()).unwrap();
1838-
let uri_id = url.to_string();
1837+
let file_path = FilePath::from_path_buf(canonical.clone()).unwrap();
1838+
let uri_id = file_path.to_string();
18391839

18401840
// Extract file name
18411841
let filename = file

crates/oak_db/src/db.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ pub trait DbInputs: salsa::Database {
4242
/// so salsa records dep edges through those.
4343
///
4444
/// Each concrete db type provides its own forwarding `impl Db`, which is
45-
/// what lets `db.file_by_path(url)` work on both `&dyn Db` (via the trait
45+
/// what lets `db.file_by_path(path)` work on both `&dyn Db` (via the trait
4646
/// method) and concrete db references (via the type's impl).
4747
#[salsa::db]
4848
pub trait Db: DbInputs {
49-
/// Look up the `File` interned at `url`, if any.
49+
/// Look up the `File` interned at `path`, if any.
5050
///
5151
/// Walks the per-root URL indices in workspace-then-library order,
5252
/// then falls back to the orphan bucket. The walk short-circuits
5353
/// on the first hit, so callers depend only on the index maps
5454
/// actually visited.
55-
fn file_by_path(&self, url: &FilePath) -> Option<File>;
55+
fn file_by_path(&self, path: &FilePath) -> Option<File>;
5656

5757
/// Look up the `Package` named `name`, applying the following precedence:
5858
/// - Workspace packages shadow installed ones
@@ -108,13 +108,13 @@ pub(crate) fn live_roots_query(db: &dyn Db) -> Vec<LiveRoot> {
108108
/// entity), but every step is: each [`root_path_index`] call returns a
109109
/// cached map, so adding a file to one root invalidates only that
110110
/// root's index.
111-
pub(crate) fn file_by_path_query(db: &dyn Db, url: &FilePath) -> Option<File> {
111+
pub(crate) fn file_by_path_query(db: &dyn Db, path: &FilePath) -> Option<File> {
112112
for &root in db.live_roots() {
113113
let hit = match root {
114114
LiveRoot::Workspace(r) | LiveRoot::Library(r) => {
115-
root_path_index(db, r).get(url).copied()
115+
root_path_index(db, r).get(path).copied()
116116
},
117-
LiveRoot::Orphan(_) => orphan_path_index(db).get(url).copied(),
117+
LiveRoot::Orphan(_) => orphan_path_index(db).get(path).copied(),
118118
};
119119
if hit.is_some() {
120120
return hit;

0 commit comments

Comments
 (0)