Rename 'project_core' crate to 'worktree', make it just about worktrees (#9189)
This is just a refactor. I noticed that we now have a `project_core` crate, which mainly contains the `Worktree` type and its private helpers, plus the project's settings. In this PR, I've renamed that crate to `worktree` and did some minor simplification to its module structure. I also extracted a new `WorktreeSettings` settings type from the `ProjectSettings`, so that the worktree settings could live in the worktree crate. This way, the crate is now exclusively about worktree logic. Release Notes: - N/A
This commit is contained in:
parent
2b67bb27cf
commit
dfcc143ead
22 changed files with 215 additions and 190 deletions
|
@ -2,6 +2,7 @@ pub mod debounced_delay;
|
|||
pub mod lsp_command;
|
||||
pub mod lsp_ext_command;
|
||||
mod prettier_support;
|
||||
pub mod project_settings;
|
||||
pub mod search;
|
||||
mod task_inventory;
|
||||
pub mod terminals;
|
||||
|
@ -56,9 +57,9 @@ use node_runtime::NodeRuntime;
|
|||
use parking_lot::{Mutex, RwLock};
|
||||
use postage::watch;
|
||||
use prettier_support::{DefaultPrettier, PrettierInstance};
|
||||
use project_core::project_settings::{LspSettings, ProjectSettings};
|
||||
pub use project_core::{DiagnosticSummary, ProjectEntryId};
|
||||
use project_settings::{LspSettings, ProjectSettings};
|
||||
use rand::prelude::*;
|
||||
use worktree::LocalSnapshot;
|
||||
|
||||
use rpc::{ErrorCode, ErrorExt as _};
|
||||
use search::SearchQuery;
|
||||
|
@ -96,16 +97,20 @@ use util::{
|
|||
paths::{LOCAL_SETTINGS_RELATIVE_PATH, LOCAL_TASKS_RELATIVE_PATH},
|
||||
post_inc, ResultExt, TryFutureExt as _,
|
||||
};
|
||||
use worktree::{Snapshot, Traversal};
|
||||
|
||||
pub use fs::*;
|
||||
pub use language::Location;
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub use prettier::FORMAT_SUFFIX as TEST_PRETTIER_FORMAT_SUFFIX;
|
||||
pub use project_core::project_settings;
|
||||
pub use project_core::worktree::{self, *};
|
||||
#[cfg(feature = "test-support")]
|
||||
pub use task_inventory::test_inventory::*;
|
||||
pub use task_inventory::{Inventory, TaskSourceKind};
|
||||
pub use worktree::{
|
||||
DiagnosticSummary, Entry, EntryKind, File, LocalWorktree, PathChange, ProjectEntryId,
|
||||
RepositoryEntry, UpdatedEntriesSet, UpdatedGitRepositoriesSet, Worktree, WorktreeId,
|
||||
WorktreeSettings, FS_WATCH_LATENCY,
|
||||
};
|
||||
|
||||
const MAX_SERVER_REINSTALL_ATTEMPT_COUNT: u64 = 4;
|
||||
const SERVER_REINSTALL_DEBOUNCE_TIMEOUT: Duration = Duration::from_secs(1);
|
||||
|
@ -492,6 +497,7 @@ impl SearchMatchCandidate {
|
|||
|
||||
impl Project {
|
||||
pub fn init_settings(cx: &mut AppContext) {
|
||||
WorktreeSettings::register(cx);
|
||||
ProjectSettings::register(cx);
|
||||
}
|
||||
|
||||
|
|
63
crates/project/src/project_settings.rs
Normal file
63
crates/project/src/project_settings.rs
Normal file
|
@ -0,0 +1,63 @@
|
|||
use collections::HashMap;
|
||||
use gpui::AppContext;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings::Settings;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct ProjectSettings {
|
||||
/// Configuration for language servers.
|
||||
///
|
||||
/// The following settings can be overridden for specific language servers:
|
||||
/// - initialization_options
|
||||
/// To override settings for a language, add an entry for that language server's
|
||||
/// name to the lsp value.
|
||||
/// Default: null
|
||||
#[serde(default)]
|
||||
pub lsp: HashMap<Arc<str>, LspSettings>,
|
||||
|
||||
/// Configuration for Git-related features
|
||||
#[serde(default)]
|
||||
pub git: GitSettings,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct GitSettings {
|
||||
/// Whether or not to show the git gutter.
|
||||
///
|
||||
/// Default: tracked_files
|
||||
pub git_gutter: Option<GitGutterSetting>,
|
||||
pub gutter_debounce: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GitGutterSetting {
|
||||
/// Show git gutter in tracked files.
|
||||
#[default]
|
||||
TrackedFiles,
|
||||
/// Hide git gutter
|
||||
Hide,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct LspSettings {
|
||||
pub initialization_options: Option<serde_json::Value>,
|
||||
pub settings: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
impl Settings for ProjectSettings {
|
||||
const KEY: Option<&'static str> = None;
|
||||
|
||||
type FileContent = Self;
|
||||
|
||||
fn load(
|
||||
default_value: &Self::FileContent,
|
||||
user_values: &[&Self::FileContent],
|
||||
_: &mut AppContext,
|
||||
) -> anyhow::Result<Self> {
|
||||
Self::load_via_json_merge(default_value, user_values)
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ use serde_json::json;
|
|||
use std::{os, task::Poll};
|
||||
use unindent::Unindent as _;
|
||||
use util::{assert_set_eq, paths::PathMatcher, test::temp_tree};
|
||||
use worktree::WorktreeModelHandle as _;
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_block_via_channel(cx: &mut gpui::TestAppContext) {
|
||||
|
|
|
@ -9,9 +9,9 @@ use std::{
|
|||
use collections::{HashMap, VecDeque};
|
||||
use gpui::{AppContext, Context, Model, ModelContext, Subscription};
|
||||
use itertools::Itertools;
|
||||
use project_core::worktree::WorktreeId;
|
||||
use task::{Task, TaskContext, TaskId, TaskSource};
|
||||
use util::{post_inc, NumericPrefixWithSuffix};
|
||||
use worktree::WorktreeId;
|
||||
|
||||
/// Inventory tracks available tasks for a given project.
|
||||
pub struct Inventory {
|
||||
|
@ -230,8 +230,8 @@ pub mod test_inventory {
|
|||
use std::{path::Path, sync::Arc};
|
||||
|
||||
use gpui::{AppContext, Context as _, Model, ModelContext, TestAppContext};
|
||||
use project_core::worktree::WorktreeId;
|
||||
use task::{Task, TaskContext, TaskId, TaskSource};
|
||||
use worktree::WorktreeId;
|
||||
|
||||
use crate::Inventory;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue