Unload languages when uninstalling their extension (#7743)
Release Notes: - N/A Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
parent
a2144faf9c
commit
e73e93f333
5 changed files with 120 additions and 28 deletions
|
@ -83,8 +83,8 @@ thread_local! {
|
|||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref NEXT_LANGUAGE_ID: AtomicUsize = Default::default();
|
||||
static ref NEXT_GRAMMAR_ID: AtomicUsize = Default::default();
|
||||
|
||||
static ref WASM_ENGINE: wasmtime::Engine = wasmtime::Engine::default();
|
||||
|
||||
/// A shared grammar for plain text, exposed for reuse by downstream crates.
|
||||
|
@ -613,7 +613,17 @@ pub struct BracketPair {
|
|||
pub newline: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
|
||||
pub(crate) struct LanguageId(usize);
|
||||
|
||||
impl LanguageId {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self(NEXT_LANGUAGE_ID.fetch_add(1, SeqCst))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Language {
|
||||
pub(crate) id: LanguageId,
|
||||
pub(crate) config: LanguageConfig,
|
||||
pub(crate) grammar: Option<Arc<Grammar>>,
|
||||
pub(crate) adapters: Vec<Arc<CachedLspAdapter>>,
|
||||
|
@ -625,8 +635,17 @@ pub struct Language {
|
|||
)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
|
||||
pub struct GrammarId(pub usize);
|
||||
|
||||
impl GrammarId {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self(NEXT_GRAMMAR_ID.fetch_add(1, SeqCst))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Grammar {
|
||||
id: usize,
|
||||
id: GrammarId,
|
||||
pub ts_language: tree_sitter::Language,
|
||||
pub(crate) error_query: Query,
|
||||
pub(crate) highlights_query: Option<Query>,
|
||||
|
@ -697,11 +716,24 @@ struct BracketConfig {
|
|||
|
||||
impl Language {
|
||||
pub fn new(config: LanguageConfig, ts_language: Option<tree_sitter::Language>) -> Self {
|
||||
Self::new_with_id(
|
||||
LanguageId(NEXT_LANGUAGE_ID.fetch_add(1, SeqCst)),
|
||||
config,
|
||||
ts_language,
|
||||
)
|
||||
}
|
||||
|
||||
fn new_with_id(
|
||||
id: LanguageId,
|
||||
config: LanguageConfig,
|
||||
ts_language: Option<tree_sitter::Language>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id,
|
||||
config,
|
||||
grammar: ts_language.map(|ts_language| {
|
||||
Arc::new(Grammar {
|
||||
id: NEXT_GRAMMAR_ID.fetch_add(1, SeqCst),
|
||||
id: GrammarId::new(),
|
||||
highlights_query: None,
|
||||
brackets_config: None,
|
||||
outline_config: None,
|
||||
|
@ -726,10 +758,6 @@ impl Language {
|
|||
&self.adapters
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<usize> {
|
||||
self.grammar.as_ref().map(|g| g.id)
|
||||
}
|
||||
|
||||
pub fn with_queries(mut self, queries: LanguageQueries) -> Result<Self> {
|
||||
if let Some(query) = queries.highlights {
|
||||
self = self
|
||||
|
@ -1237,13 +1265,13 @@ impl LanguageScope {
|
|||
|
||||
impl Hash for Language {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.id().hash(state)
|
||||
self.id.hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Language {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id().eq(&other.id())
|
||||
self.id.eq(&other.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1258,7 +1286,7 @@ impl Debug for Language {
|
|||
}
|
||||
|
||||
impl Grammar {
|
||||
pub fn id(&self) -> usize {
|
||||
pub fn id(&self) -> GrammarId {
|
||||
self.id
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue