debugger/extensions: Revert changes to extension store related to language config (#30225)
Revert #29945 Release Notes: - N/A --------- Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
parent
20387f24aa
commit
b091581e4b
9 changed files with 159 additions and 218 deletions
|
@ -666,7 +666,7 @@ pub struct CodeLabel {
|
|||
pub filter_range: Range<usize>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, JsonSchema, Serialize, Debug)]
|
||||
#[derive(Clone, Deserialize, JsonSchema)]
|
||||
pub struct LanguageConfig {
|
||||
/// Human-readable name of the language.
|
||||
pub name: LanguageName,
|
||||
|
@ -694,20 +694,12 @@ pub struct LanguageConfig {
|
|||
pub auto_indent_on_paste: Option<bool>,
|
||||
/// A regex that is used to determine whether the indentation level should be
|
||||
/// increased in the following line.
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "deserialize_regex",
|
||||
serialize_with = "serialize_regex"
|
||||
)]
|
||||
#[serde(default, deserialize_with = "deserialize_regex")]
|
||||
#[schemars(schema_with = "regex_json_schema")]
|
||||
pub increase_indent_pattern: Option<Regex>,
|
||||
/// A regex that is used to determine whether the indentation level should be
|
||||
/// decreased in the following line.
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "deserialize_regex",
|
||||
serialize_with = "serialize_regex"
|
||||
)]
|
||||
#[serde(default, deserialize_with = "deserialize_regex")]
|
||||
#[schemars(schema_with = "regex_json_schema")]
|
||||
pub decrease_indent_pattern: Option<Regex>,
|
||||
/// A list of characters that trigger the automatic insertion of a closing
|
||||
|
@ -762,7 +754,7 @@ pub struct LanguageConfig {
|
|||
pub completion_query_characters: HashSet<char>,
|
||||
/// A list of preferred debuggers for this language.
|
||||
#[serde(default)]
|
||||
pub debuggers: IndexSet<String>,
|
||||
pub debuggers: IndexSet<SharedString>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Default, JsonSchema)]
|
||||
|
@ -781,7 +773,7 @@ pub struct LanguageMatcher {
|
|||
}
|
||||
|
||||
/// The configuration for JSX tag auto-closing.
|
||||
#[derive(Clone, Deserialize, JsonSchema, Serialize, Debug)]
|
||||
#[derive(Clone, Deserialize, JsonSchema)]
|
||||
pub struct JsxTagAutoCloseConfig {
|
||||
/// The name of the node for a opening tag
|
||||
pub open_tag_node_name: String,
|
||||
|
@ -822,7 +814,7 @@ pub struct LanguageScope {
|
|||
override_id: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Default, Debug, JsonSchema, Serialize)]
|
||||
#[derive(Clone, Deserialize, Default, Debug, JsonSchema)]
|
||||
pub struct LanguageConfigOverride {
|
||||
#[serde(default)]
|
||||
pub line_comments: Override<Vec<Arc<str>>>,
|
||||
|
@ -949,7 +941,7 @@ pub struct FakeLspAdapter {
|
|||
///
|
||||
/// This struct includes settings for defining which pairs of characters are considered brackets and
|
||||
/// also specifies any language-specific scopes where these pairs should be ignored for bracket matching purposes.
|
||||
#[derive(Clone, Debug, Default, JsonSchema, Serialize)]
|
||||
#[derive(Clone, Debug, Default, JsonSchema)]
|
||||
pub struct BracketPairConfig {
|
||||
/// A list of character pairs that should be treated as brackets in the context of a given language.
|
||||
pub pairs: Vec<BracketPair>,
|
||||
|
@ -999,7 +991,7 @@ impl<'de> Deserialize<'de> for BracketPairConfig {
|
|||
|
||||
/// Describes a single bracket pair and how an editor should react to e.g. inserting
|
||||
/// an opening bracket or to a newline character insertion in between `start` and `end` characters.
|
||||
#[derive(Clone, Debug, Default, Deserialize, PartialEq, JsonSchema, Serialize)]
|
||||
#[derive(Clone, Debug, Default, Deserialize, PartialEq, JsonSchema)]
|
||||
pub struct BracketPair {
|
||||
/// Starting substring for a bracket.
|
||||
pub start: String,
|
||||
|
|
|
@ -145,24 +145,25 @@ pub enum BinaryStatus {
|
|||
#[derive(Clone)]
|
||||
pub struct AvailableLanguage {
|
||||
id: LanguageId,
|
||||
config: LanguageConfig,
|
||||
name: LanguageName,
|
||||
grammar: Option<Arc<str>>,
|
||||
matcher: LanguageMatcher,
|
||||
hidden: bool,
|
||||
load: Arc<dyn Fn() -> Result<LoadedLanguage> + 'static + Send + Sync>,
|
||||
loaded: bool,
|
||||
}
|
||||
|
||||
impl AvailableLanguage {
|
||||
pub fn name(&self) -> LanguageName {
|
||||
self.config.name.clone()
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
pub fn matcher(&self) -> &LanguageMatcher {
|
||||
&self.config.matcher
|
||||
&self.matcher
|
||||
}
|
||||
|
||||
pub fn hidden(&self) -> bool {
|
||||
self.config.hidden
|
||||
}
|
||||
pub fn config(&self) -> &LanguageConfig {
|
||||
&self.config
|
||||
self.hidden
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,7 +327,10 @@ impl LanguageRegistry {
|
|||
#[cfg(any(feature = "test-support", test))]
|
||||
pub fn register_test_language(&self, config: LanguageConfig) {
|
||||
self.register_language(
|
||||
config.clone(),
|
||||
config.name.clone(),
|
||||
config.grammar.clone(),
|
||||
config.matcher.clone(),
|
||||
config.hidden,
|
||||
Arc::new(move || {
|
||||
Ok(LoadedLanguage {
|
||||
config: config.clone(),
|
||||
|
@ -485,14 +489,18 @@ impl LanguageRegistry {
|
|||
/// Adds a language to the registry, which can be loaded if needed.
|
||||
pub fn register_language(
|
||||
&self,
|
||||
config: LanguageConfig,
|
||||
name: LanguageName,
|
||||
grammar_name: Option<Arc<str>>,
|
||||
matcher: LanguageMatcher,
|
||||
hidden: bool,
|
||||
load: Arc<dyn Fn() -> Result<LoadedLanguage> + 'static + Send + Sync>,
|
||||
) {
|
||||
let state = &mut *self.state.write();
|
||||
|
||||
for existing_language in &mut state.available_languages {
|
||||
if existing_language.config.name == config.name {
|
||||
existing_language.config = config;
|
||||
if existing_language.name == name {
|
||||
existing_language.grammar = grammar_name;
|
||||
existing_language.matcher = matcher;
|
||||
existing_language.load = load;
|
||||
return;
|
||||
}
|
||||
|
@ -500,8 +508,11 @@ impl LanguageRegistry {
|
|||
|
||||
state.available_languages.push(AvailableLanguage {
|
||||
id: LanguageId::new(),
|
||||
config,
|
||||
name,
|
||||
grammar: grammar_name,
|
||||
matcher,
|
||||
load,
|
||||
hidden,
|
||||
loaded: false,
|
||||
});
|
||||
state.version += 1;
|
||||
|
@ -547,7 +558,7 @@ impl LanguageRegistry {
|
|||
let mut result = state
|
||||
.available_languages
|
||||
.iter()
|
||||
.filter_map(|l| l.loaded.not().then_some(l.config.name.to_string()))
|
||||
.filter_map(|l| l.loaded.not().then_some(l.name.to_string()))
|
||||
.chain(state.languages.iter().map(|l| l.config.name.to_string()))
|
||||
.collect::<Vec<_>>();
|
||||
result.sort_unstable_by_key(|language_name| language_name.to_lowercase());
|
||||
|
@ -566,7 +577,10 @@ impl LanguageRegistry {
|
|||
let mut state = self.state.write();
|
||||
state.available_languages.push(AvailableLanguage {
|
||||
id: language.id,
|
||||
config: language.config.clone(),
|
||||
name: language.name(),
|
||||
grammar: language.config.grammar.clone(),
|
||||
matcher: language.config.matcher.clone(),
|
||||
hidden: language.config.hidden,
|
||||
load: Arc::new(|| Err(anyhow!("already loaded"))),
|
||||
loaded: true,
|
||||
});
|
||||
|
@ -635,7 +649,7 @@ impl LanguageRegistry {
|
|||
state
|
||||
.available_languages
|
||||
.iter()
|
||||
.find(|l| l.config.name.0.as_ref() == name)
|
||||
.find(|l| l.name.0.as_ref() == name)
|
||||
.cloned()
|
||||
}
|
||||
|
||||
|
@ -752,11 +766,8 @@ impl LanguageRegistry {
|
|||
let current_match_type = best_language_match
|
||||
.as_ref()
|
||||
.map_or(LanguageMatchPrecedence::default(), |(_, score)| *score);
|
||||
let language_score = callback(
|
||||
&language.config.name,
|
||||
&language.config.matcher,
|
||||
current_match_type,
|
||||
);
|
||||
let language_score =
|
||||
callback(&language.name, &language.matcher, current_match_type);
|
||||
debug_assert!(
|
||||
language_score.is_none_or(|new_score| new_score > current_match_type),
|
||||
"Matching callback should only return a better match than the current one"
|
||||
|
@ -804,7 +815,7 @@ impl LanguageRegistry {
|
|||
let this = self.clone();
|
||||
|
||||
let id = language.id;
|
||||
let name = language.config.name.clone();
|
||||
let name = language.name.clone();
|
||||
let language_load = language.load.clone();
|
||||
|
||||
self.executor
|
||||
|
@ -1120,7 +1131,7 @@ impl LanguageRegistryState {
|
|||
self.languages
|
||||
.retain(|language| !languages_to_remove.contains(&language.name()));
|
||||
self.available_languages
|
||||
.retain(|language| !languages_to_remove.contains(&language.config.name));
|
||||
.retain(|language| !languages_to_remove.contains(&language.name));
|
||||
self.grammars
|
||||
.retain(|name, _| !grammars_to_remove.contains(name));
|
||||
self.version += 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue