Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

language server: pass correct non-POSIX paths to detect_crate_for #4388

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions crates/cairo-lang-language-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ impl Backend {

/// Tries to detect the crate root the config that contains a cairo file, and add it to the
/// system.
async fn detect_crate_for(&self, db: &mut RootDatabase, file_path: &str) {
async fn detect_crate_for(&self, db: &mut RootDatabase, file_path: PathBuf) {
let corelib_fallback = self.get_corelib_fallback_path().await;
if self.scarb.is_scarb_project(file_path.into()) {
if self.scarb.is_scarb_project(file_path.clone()) {
if self.scarb.is_scarb_found() {
// Carrying out Scarb based setup.
let corelib = match self.scarb.corelib_path(file_path.into()).await {
let corelib = match self.scarb.corelib_path(file_path.clone()).await {
Ok(corelib) => corelib,
Err(err) => {
let err =
Expand Down Expand Up @@ -346,7 +346,7 @@ impl Backend {
}

// Fallback to cairo_project manifest format.
let mut path = PathBuf::from(file_path);
let mut path = file_path.clone();
for _ in 0..MAX_CRATE_DETECTION_DEPTH {
path.pop();
// Check for a cairo project file.
Expand All @@ -357,8 +357,9 @@ impl Backend {
}

// Fallback to a single file.
if let Err(err) = setup_project(&mut *db, PathBuf::from(file_path).as_path()) {
eprintln!("Error loading file {file_path} as a single crate: {err}");
if let Err(err) = setup_project(&mut *db, file_path.as_path()) {
let file_path_s = file_path.to_string_lossy();
eprintln!("Error loading file {file_path_s} as a single crate: {err}");
}
}

Expand All @@ -368,9 +369,7 @@ impl Backend {
for file in self.state_mutex.lock().await.open_files.iter() {
let file = db.lookup_intern_file(*file);
if let FileLongId::OnDisk(file_path) = file {
if let Some(file_path) = file_path.to_str() {
self.detect_crate_for(&mut db, file_path).await;
}
self.detect_crate_for(&mut db, file_path).await;
}
}
drop(db);
Expand Down Expand Up @@ -547,7 +546,9 @@ impl LanguageServer for Backend {
// Try to detect the crate for physical files.
// The crate for virtual files is already known.
if uri.scheme() == "file" {
let path = uri.path();
let Ok(path) = uri.to_file_path() else {
return;
};
self.detect_crate_for(&mut db, path).await;
}

Expand Down