Cursor settings import (#31424)
Closes #ISSUE Release Notes: - Added support for importing settings from cursor. Cursor settings can be imported using the `zed: import cursor settings` command from the command palette
This commit is contained in:
parent
21bd91a773
commit
b9a5d437db
6 changed files with 147 additions and 48 deletions
|
@ -22,7 +22,7 @@ pub use settings_store::{
|
|||
InvalidSettingsError, LocalSettingsKind, Settings, SettingsLocation, SettingsSources,
|
||||
SettingsStore, parse_json_with_comments,
|
||||
};
|
||||
pub use vscode_import::VsCodeSettings;
|
||||
pub use vscode_import::{VsCodeSettings, VsCodeSettingsSource};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord)]
|
||||
pub struct WorktreeId(usize);
|
||||
|
|
|
@ -1522,6 +1522,8 @@ pub fn parse_json_with_comments<T: DeserializeOwned>(content: &str) -> Result<T>
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::VsCodeSettingsSource;
|
||||
|
||||
use super::*;
|
||||
use serde_derive::Deserialize;
|
||||
use unindent::Unindent;
|
||||
|
@ -2004,7 +2006,10 @@ mod tests {
|
|||
cx: &mut App,
|
||||
) {
|
||||
store.set_user_settings(&old, cx).ok();
|
||||
let new = store.get_vscode_edits(old, &VsCodeSettings::from_str(&vscode).unwrap());
|
||||
let new = store.get_vscode_edits(
|
||||
old,
|
||||
&VsCodeSettings::from_str(&vscode, VsCodeSettingsSource::VsCode).unwrap(),
|
||||
);
|
||||
pretty_assertions::assert_eq!(new, expected);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,20 +4,42 @@ use serde_json::{Map, Value};
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub enum VsCodeSettingsSource {
|
||||
VsCode,
|
||||
Cursor,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for VsCodeSettingsSource {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
VsCodeSettingsSource::VsCode => write!(f, "VS Code"),
|
||||
VsCodeSettingsSource::Cursor => write!(f, "Cursor"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct VsCodeSettings {
|
||||
pub source: VsCodeSettingsSource,
|
||||
content: Map<String, Value>,
|
||||
}
|
||||
|
||||
impl VsCodeSettings {
|
||||
pub fn from_str(content: &str) -> Result<Self> {
|
||||
pub fn from_str(content: &str, source: VsCodeSettingsSource) -> Result<Self> {
|
||||
Ok(Self {
|
||||
source,
|
||||
content: serde_json_lenient::from_str(content)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn load_user_settings(fs: Arc<dyn Fs>) -> Result<Self> {
|
||||
let content = fs.load(paths::vscode_settings_file()).await?;
|
||||
pub async fn load_user_settings(source: VsCodeSettingsSource, fs: Arc<dyn Fs>) -> Result<Self> {
|
||||
let path = match source {
|
||||
VsCodeSettingsSource::VsCode => paths::vscode_settings_file(),
|
||||
VsCodeSettingsSource::Cursor => paths::cursor_settings_file(),
|
||||
};
|
||||
let content = fs.load(path).await?;
|
||||
Ok(Self {
|
||||
source,
|
||||
content: serde_json_lenient::from_str(&content)?,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue