Skip to content

Commit

Permalink
Use 'CARGO_WORKSPACE_DIR' if present, closes rust-analyzer#33
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Jul 19, 2022
1 parent 21f04f3 commit 15ca92f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,7 @@ fn lit_kind_for_patch(patch: &str) -> StrLitKind {
let has_dquote = patch.chars().any(|c| c == '"');
if !has_dquote {
let has_bslash_or_newline = patch.chars().any(|c| matches!(c, '\\' | '\n'));
return if has_bslash_or_newline {
StrLitKind::Raw(1)
} else {
StrLitKind::Normal
};
return if has_bslash_or_newline { StrLitKind::Raw(1) } else { StrLitKind::Normal };
}

// Find the maximum number of hashes that follow a double quote in the string.
Expand Down Expand Up @@ -649,9 +645,15 @@ fn to_abs_ws_path(path: &Path) -> PathBuf {
static WORKSPACE_ROOT: OnceCell<PathBuf> = OnceCell::new();
WORKSPACE_ROOT
.get_or_try_init(|| {
let my_manifest = env::var("CARGO_MANIFEST_DIR")?;
// Until https://github.com/rust-lang/cargo/issues/3946 is resolved, this
// is set with a hack like https://github.com/rust-lang/cargo/issues/3946#issuecomment-973132993
if let Ok(workspace_root) = env::var("CARGO_WORKSPACE_DIR") {
return Ok(workspace_root.into());
}

// Heuristic, see https://github.com/rust-lang/cargo/issues/3946
// If a hack isn't used, we use a heuristic to find the "top-level" workspace.
// This fails in some cases, see https://github.com/rust-analyzer/expect-test/issues/33
let my_manifest = env::var("CARGO_MANIFEST_DIR")?;
let workspace_root = Path::new(&my_manifest)
.ancestors()
.filter(|it| it.join("Cargo.toml").exists())
Expand Down

0 comments on commit 15ca92f

Please sign in to comment.