Skip to content

Commit

Permalink
Merge pull request #4 from blorbb/fix/ra-source-path
Browse files Browse the repository at this point in the history
fix invalid path by rust-analyzer causing panic
  • Loading branch information
basro authored Jul 2, 2024
2 parents ca4bd6f + 9276cbb commit cc52977
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions internal/stylance-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ fn try_import_style_classes_rel(input: &LitStr) -> anyhow::Result<TokenStream> {
env::var_os("CARGO_MANIFEST_DIR").context("CARGO_MANIFEST_DIR env var not found")?;
let manifest_path = Path::new(&manifest_dir_env);

let call_site_path = proc_macro::Span::call_site().source().source_file().path();
let file_path = call_site_path
.parent()
.expect("No current path")
.join(input.value());

try_import_style_classes_with_path(manifest_path, &file_path, input.span())
let source_path = proc_macro::Span::call_site().source().source_file().path();
// rust-analyzer gives a source file with `.is_real() == true`
// but the path itself is just "".
// assume that an empty path means that rust-analyzer is running this
// and expand to nothing.
let Some(parent) = source_path.parent() else {
return Ok(TokenStream::new());
};
let css_path = parent.join(input.value());

try_import_style_classes_with_path(manifest_path, &css_path, input.span())
}

#[cfg(feature = "nightly")]
Expand Down

0 comments on commit cc52977

Please sign in to comment.