Skip to content

Commit

Permalink
Fix from_file_path for wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
GearsDatapacks committed Feb 27, 2025
1 parent 5e05325 commit 037be39
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion compiler-core/src/language_server/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn rename_references_in_module(
.iter()
.for_each(|location| edits.replace(*location, new_name.clone()));

let Ok(uri) = Url::from_file_path(&module.input_path) else {
let Some(uri) = url_from_path(module.input_path.as_str()) else {
return;
};

Expand All @@ -138,6 +138,29 @@ fn rename_references_in_module(
.map(|changes| changes.insert(uri, edits.edits));
}

fn url_from_path(path: &str) -> Option<Url> {
// The targets for which `from_file_path` is defined
#[cfg(any(
unix,
windows,
target_os = "redox",
target_os = "wasi",
target_os = "hermit"
))]
let uri = Url::from_file_path(path).ok();

#[cfg(not(any(
unix,
windows,
target_os = "redox",
target_os = "wasi",
target_os = "hermit"
)))]
let uri = Url::parse(&format!("file://{path}")).ok();

uri
}

pub fn find_variable_references(
module: &TypedModule,
definition_location: SrcSpan,
Expand Down

0 comments on commit 037be39

Please sign in to comment.