Skip to content

Commit 0b618da

Browse files
committed
Update pathutil.rs
1 parent abc967e commit 0b618da

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

crates/erg_common/pathutil.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,12 @@ pub fn remove_verbatim(path: &Path) -> String {
238238
/// e.g.
239239
/// ```txt
240240
/// http.d/client.d.er -> http.client
241-
/// .../torch/1.0.0/src/lib.d.er -> torch
242-
/// .../torch/1.0.0/src/random.d.er -> torch/random
241+
/// $ERG_PATH/pkgs/certified/torch/1.0.0/src/lib.d.er -> torch
242+
/// $ERG_PATH/pkgs/certified/torch/1.0.0/src/random.d.er -> torch/random
243+
/// /users/foo/torch/src/lib.d.er -> torch
243244
/// math.d.er -> math
244245
/// ```
246+
/// FIXME: split by `.` instead of `/`
245247
pub fn mod_name(path: &Path) -> Str {
246248
let path = match path.strip_prefix(erg_pkgs_path()) {
247249
Ok(path) => {
@@ -267,6 +269,32 @@ pub fn mod_name(path: &Path) -> Str {
267269
.join("/");
268270
return Str::rc(format!("{mod_root}/{sub}").trim_end_matches('/'));
269271
}
272+
// using local or git path
273+
Err(_) if path.display().to_string().split("/src/").count() > 1 => {
274+
// <mod_root>/src/<sub>
275+
let path = path.display().to_string();
276+
let mod_root = path
277+
.split("/src/")
278+
.next()
279+
.unwrap()
280+
.split('/')
281+
.last()
282+
.unwrap();
283+
let sub = path
284+
.split("/src/")
285+
.nth(1)
286+
.unwrap()
287+
.split('/')
288+
.map(|c| {
289+
c.trim_end_matches("lib.d.er")
290+
.trim_end_matches(".d.er")
291+
.trim_end_matches(".d")
292+
.to_string()
293+
})
294+
.collect::<Vec<_>>()
295+
.join("/");
296+
return Str::rc(format!("{mod_root}/{sub}").trim_end_matches('/'));
297+
}
270298
Err(_) => path,
271299
};
272300
let mut name = path

0 commit comments

Comments
 (0)