mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-09 21:26:14 +03:00
assistant: Update current project context to work with Cargo workspaces (#11935)
This PR updates the current project context to work with Cargo workspaces. Release Notes: - N/A
This commit is contained in:
parent
f8672289fc
commit
55f08c0511
@ -1,3 +1,4 @@
|
|||||||
|
use std::fmt::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@ -92,32 +93,54 @@ impl CurrentProjectContext {
|
|||||||
let cargo_toml: cargo_toml::Manifest = toml::from_str(&buffer)?;
|
let cargo_toml: cargo_toml::Manifest = toml::from_str(&buffer)?;
|
||||||
|
|
||||||
let mut message = String::new();
|
let mut message = String::new();
|
||||||
|
writeln!(message, "You are in a Rust project.")?;
|
||||||
|
|
||||||
let name = cargo_toml
|
if let Some(workspace) = cargo_toml.workspace {
|
||||||
.package
|
writeln!(
|
||||||
.as_ref()
|
message,
|
||||||
.map(|package| package.name.as_str());
|
"The project is a Cargo workspace with the following members:"
|
||||||
if let Some(name) = name {
|
)?;
|
||||||
message.push_str(&format!(" named \"{name}\""));
|
for member in workspace.members {
|
||||||
|
writeln!(message, "- {member}")?;
|
||||||
}
|
}
|
||||||
message.push_str(". ");
|
|
||||||
|
|
||||||
let description = cargo_toml
|
if !workspace.default_members.is_empty() {
|
||||||
.package
|
writeln!(message, "The default members are:")?;
|
||||||
|
for member in workspace.default_members {
|
||||||
|
writeln!(message, "- {member}")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !workspace.dependencies.is_empty() {
|
||||||
|
writeln!(
|
||||||
|
message,
|
||||||
|
"The following workspace dependencies are installed:"
|
||||||
|
)?;
|
||||||
|
for dependency in workspace.dependencies.keys() {
|
||||||
|
writeln!(message, "- {dependency}")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if let Some(package) = cargo_toml.package {
|
||||||
|
writeln!(
|
||||||
|
message,
|
||||||
|
"The project name is \"{name}\".",
|
||||||
|
name = package.name
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let description = package
|
||||||
|
.description
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|package| package.description.as_ref())
|
|
||||||
.and_then(|description| description.get().ok().cloned());
|
.and_then(|description| description.get().ok().cloned());
|
||||||
if let Some(description) = description.as_ref() {
|
if let Some(description) = description.as_ref() {
|
||||||
message.push_str("It describes itself as ");
|
writeln!(message, "It describes itself as \"{description}\".")?;
|
||||||
message.push_str(&format!("\"{description}\""));
|
|
||||||
message.push_str(". ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let dependencies = cargo_toml.dependencies.keys().cloned().collect::<Vec<_>>();
|
if !cargo_toml.dependencies.is_empty() {
|
||||||
if !dependencies.is_empty() {
|
writeln!(message, "The following dependencies are installed:")?;
|
||||||
message.push_str("The following dependencies are installed: ");
|
for dependency in cargo_toml.dependencies.keys() {
|
||||||
message.push_str(&dependencies.join(", "));
|
writeln!(message, "- {dependency}")?;
|
||||||
message.push_str(". ");
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(message)
|
Ok(message)
|
||||||
|
Loading…
Reference in New Issue
Block a user