Snippets: Move snippets into the core of editor (#13937)

Release Notes:

- Move snippet support into core editor experience, marking the official
extension as deprecated. Snippets now show up in any buffer (including
plain text buffers).
This commit is contained in:
Piotr Osiewicz 2024-07-09 14:02:36 +02:00 committed by GitHub
parent b3dad0bfcb
commit 9a6f30fd95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 400 additions and 6 deletions

View file

@ -19,7 +19,7 @@ use client::{
TypedEnvelope, UserStore,
};
use clock::ReplicaId;
use collections::{btree_map, hash_map, BTreeMap, HashMap, HashSet, VecDeque};
use collections::{btree_map, hash_map, BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use debounced_delay::DebouncedDelay;
use futures::{
channel::{
@ -84,6 +84,7 @@ use similar::{ChangeTag, TextDiff};
use smol::channel::{Receiver, Sender};
use smol::lock::Semaphore;
use snippet::Snippet;
use snippet_provider::SnippetProvider;
use std::{
borrow::Cow,
cmp::{self, Ordering},
@ -229,6 +230,7 @@ pub struct Project {
hosted_project_id: Option<ProjectId>,
dev_server_project_id: Option<client::DevServerProjectId>,
search_history: SearchHistory,
snippets: Model<SnippetProvider>,
}
pub enum LanguageServerToQuery {
@ -719,7 +721,9 @@ impl Project {
cx.spawn(move |this, cx| Self::send_buffer_ordered_messages(this, rx, cx))
.detach();
let tasks = Inventory::new(cx);
let global_snippets_dir = paths::config_dir().join("snippets");
let snippets =
SnippetProvider::new(fs.clone(), BTreeSet::from_iter([global_snippets_dir]), cx);
Self {
worktrees: Vec::new(),
worktrees_reordered: false,
@ -745,6 +749,7 @@ impl Project {
_maintain_buffer_languages: Self::maintain_buffer_languages(languages.clone(), cx),
_maintain_workspace_config: Self::maintain_workspace_config(cx),
active_entry: None,
snippets,
languages,
client,
user_store,
@ -841,6 +846,9 @@ impl Project {
let this = cx.new_model(|cx| {
let replica_id = response.payload.replica_id as ReplicaId;
let tasks = Inventory::new(cx);
let global_snippets_dir = paths::config_dir().join("snippets");
let snippets =
SnippetProvider::new(fs.clone(), BTreeSet::from_iter([global_snippets_dir]), cx);
// BIG CAUTION NOTE: The order in which we initialize fields here matters and it should match what's done in Self::local.
// Otherwise, you might run into issues where worktree id on remote is different than what's on local host.
// That's because Worktree's identifier is entity id, which should probably be changed.
@ -859,6 +867,7 @@ impl Project {
let (tx, rx) = mpsc::unbounded();
cx.spawn(move |this, cx| Self::send_buffer_ordered_messages(this, rx, cx))
.detach();
let mut this = Self {
worktrees: Vec::new(),
worktrees_reordered: false,
@ -877,6 +886,7 @@ impl Project {
_maintain_workspace_config: Self::maintain_workspace_config(cx),
languages,
user_store: user_store.clone(),
snippets,
fs,
next_entry_id: Default::default(),
next_diagnostic_group_id: Default::default(),
@ -1336,6 +1346,10 @@ impl Project {
&self.tasks
}
pub fn snippets(&self) -> &Model<SnippetProvider> {
&self.snippets
}
pub fn search_history(&self) -> &SearchHistory {
&self.search_history
}