mirror of
https://github.com/zed-industries/zed.git
synced 2026-06-01 03:14:56 +07:00
language_core: Remove imports support (#52570)
This PR removes the imports query and all surrounding support from the language_core crate. The imports query was experimented with during the addition of Zeta 2. However, it has been unused for a few months now and the direction does not seemt to be pursued anymore. Thus, removing the support here. Release Notes: - N/A
This commit is contained in:
parent
0969363698
commit
79b9cae2cf
19 changed files with 10 additions and 250 deletions
|
|
@ -17,4 +17,3 @@ brackets = [
|
|||
]
|
||||
debuggers = ["CodeLLDB", "GDB"]
|
||||
documentation_comment = { start = "/*", prefix = "* ", end = "*/", tab_size = 1 }
|
||||
import_path_strip_regex = "^<|>$"
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
(preproc_include
|
||||
path: [
|
||||
((system_lib_string) @source @wildcard
|
||||
(#strip! @source "[<>]"))
|
||||
(string_literal
|
||||
(string_content) @source @wildcard)
|
||||
]) @import
|
||||
|
|
@ -19,4 +19,3 @@ brackets = [
|
|||
]
|
||||
debuggers = ["CodeLLDB", "GDB"]
|
||||
documentation_comment = { start = "/*", prefix = "* ", end = "*/", tab_size = 1 }
|
||||
import_path_strip_regex = "^<|>$"
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
(preproc_include
|
||||
path: [
|
||||
(system_lib_string) @source @wildcard
|
||||
(string_literal
|
||||
(string_content) @source @wildcard)
|
||||
]) @import
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
(import_spec
|
||||
name: [
|
||||
(dot)
|
||||
(package_identifier)
|
||||
]
|
||||
path: (interpreted_string_literal
|
||||
(interpreted_string_literal_content) @namespace)) @wildcard @import
|
||||
|
||||
(import_spec
|
||||
!name
|
||||
path: (interpreted_string_literal
|
||||
(interpreted_string_literal_content) @namespace)) @wildcard @import
|
||||
|
|
@ -24,7 +24,6 @@ tab_size = 2
|
|||
scope_opt_in_language_servers = ["tailwindcss-language-server", "emmet-language-server"]
|
||||
prettier_parser_name = "babel"
|
||||
debuggers = ["JavaScript"]
|
||||
import_path_strip_regex = "(?:/index)?\\.[jt]s$"
|
||||
|
||||
[jsx_tag_auto_close]
|
||||
open_tag_node_name = "jsx_opening_element"
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
(import_statement
|
||||
import_clause: (import_clause
|
||||
[
|
||||
(identifier) @name
|
||||
(named_imports
|
||||
(import_specifier
|
||||
name: (_) @name
|
||||
alias: (_)? @alias))
|
||||
])
|
||||
source: (string
|
||||
(string_fragment) @source)) @import
|
||||
|
||||
(import_statement
|
||||
!import_clause
|
||||
source: (string
|
||||
(string_fragment) @source @wildcard)) @import
|
||||
|
|
@ -36,4 +36,3 @@ decrease_indent_patterns = [
|
|||
{ pattern = "^\\s*except\\b.*:\\s*(#.*)?", valid_after = ["try", "except"] },
|
||||
{ pattern = "^\\s*finally\\b.*:\\s*(#.*)?", valid_after = ["try", "except", "else"] },
|
||||
]
|
||||
import_path_strip_regex = "/__init__\\.py$"
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
(import_statement
|
||||
name: [
|
||||
(dotted_name
|
||||
((identifier) @namespace
|
||||
".")*
|
||||
(identifier) @namespace .)
|
||||
(aliased_import
|
||||
name: (dotted_name
|
||||
((identifier) @namespace
|
||||
".")*
|
||||
(identifier) @namespace .))
|
||||
]) @wildcard @import
|
||||
|
||||
(import_from_statement
|
||||
module_name: [
|
||||
(dotted_name
|
||||
((identifier) @namespace
|
||||
".")*
|
||||
(identifier) @namespace .)
|
||||
(relative_import
|
||||
(dotted_name
|
||||
((identifier) @namespace
|
||||
".")*
|
||||
(identifier) @namespace .)?)
|
||||
]
|
||||
(wildcard_import)? @wildcard
|
||||
name: [
|
||||
(dotted_name
|
||||
((identifier) @namespace
|
||||
".")*
|
||||
(identifier) @name .)
|
||||
(aliased_import
|
||||
name: (dotted_name
|
||||
((identifier) @namespace
|
||||
".")*
|
||||
(identifier) @name .)
|
||||
alias: (identifier) @alias)
|
||||
]?) @import
|
||||
|
|
@ -18,5 +18,3 @@ brackets = [
|
|||
collapsed_placeholder = " /* ... */ "
|
||||
debuggers = ["CodeLLDB", "GDB"]
|
||||
documentation_comment = { start = "/*", prefix = "* ", end = "*/", tab_size = 1 }
|
||||
ignored_import_segments = ["crate", "super"]
|
||||
import_path_strip_regex = "/(lib|mod)\\.rs$"
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
(use_declaration) @import
|
||||
|
||||
(scoped_use_list
|
||||
path: (_) @namespace
|
||||
list: (_) @list)
|
||||
|
||||
(scoped_identifier
|
||||
path: (_) @namespace
|
||||
name: (identifier) @name)
|
||||
|
||||
(use_list
|
||||
(identifier) @name)
|
||||
|
||||
(use_declaration
|
||||
(identifier) @name)
|
||||
|
||||
(use_as_clause
|
||||
path: (scoped_identifier
|
||||
path: (_) @namespace
|
||||
name: (_) @name)
|
||||
alias: (_) @alias)
|
||||
|
||||
(use_as_clause
|
||||
path: (identifier) @name
|
||||
alias: (_) @alias)
|
||||
|
||||
(use_wildcard
|
||||
(_)? @namespace
|
||||
"*" @wildcard)
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
(import_statement
|
||||
import_clause: (import_clause
|
||||
[
|
||||
(identifier) @name
|
||||
(named_imports
|
||||
(import_specifier
|
||||
name: (_) @name
|
||||
alias: (_)? @alias))
|
||||
])
|
||||
source: (string
|
||||
(string_fragment) @source)) @import
|
||||
|
||||
(import_statement
|
||||
!import_clause
|
||||
source: (string
|
||||
(string_fragment) @source @wildcard)) @import
|
||||
|
|
@ -23,7 +23,6 @@ prettier_parser_name = "typescript"
|
|||
tab_size = 2
|
||||
debuggers = ["JavaScript"]
|
||||
scope_opt_in_language_servers = ["tailwindcss-language-server"]
|
||||
import_path_strip_regex = "(?:/index)?\\.[jt]s$"
|
||||
|
||||
[overrides.string]
|
||||
completion_query_characters = ["-", "."]
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
(import_statement
|
||||
import_clause: (import_clause
|
||||
[
|
||||
(identifier) @name
|
||||
(named_imports
|
||||
(import_specifier
|
||||
name: (_) @name
|
||||
alias: (_)? @alias))
|
||||
(namespace_import) @wildcard
|
||||
])
|
||||
source: (string
|
||||
(string_fragment) @source)) @import
|
||||
|
||||
(import_statement
|
||||
!source
|
||||
import_clause: (import_require_clause
|
||||
source: (string
|
||||
(string_fragment) @source))) @wildcard @import
|
||||
|
||||
(import_statement
|
||||
!import_clause
|
||||
source: (string
|
||||
(string_fragment) @source)) @wildcard @import
|
||||
|
|
@ -39,14 +39,13 @@ pub use language_core::highlight_map::{HighlightId, HighlightMap};
|
|||
pub use language_core::{
|
||||
BlockCommentConfig, BracketPair, BracketPairConfig, BracketPairContent, BracketsConfig,
|
||||
BracketsPatternConfig, CodeLabel, CodeLabelBuilder, DebugVariablesConfig, DebuggerTextObject,
|
||||
DecreaseIndentConfig, Grammar, GrammarId, HighlightsConfig, ImportsConfig, IndentConfig,
|
||||
InjectionConfig, InjectionPatternConfig, JsxTagAutoCloseConfig, LanguageConfig,
|
||||
LanguageConfigOverride, LanguageId, LanguageMatcher, OrderedListConfig, OutlineConfig,
|
||||
Override, OverrideConfig, OverrideEntry, PromptResponseContext, RedactionConfig,
|
||||
RunnableCapture, RunnableConfig, SoftWrap, Symbol, TaskListConfig, TextObject,
|
||||
TextObjectConfig, ToLspPosition, WrapCharactersConfig,
|
||||
auto_indent_using_last_non_empty_line_default, deserialize_regex, deserialize_regex_vec,
|
||||
regex_json_schema, regex_vec_json_schema, serialize_regex,
|
||||
DecreaseIndentConfig, Grammar, GrammarId, HighlightsConfig, IndentConfig, InjectionConfig,
|
||||
InjectionPatternConfig, JsxTagAutoCloseConfig, LanguageConfig, LanguageConfigOverride,
|
||||
LanguageId, LanguageMatcher, OrderedListConfig, OutlineConfig, Override, OverrideConfig,
|
||||
OverrideEntry, PromptResponseContext, RedactionConfig, RunnableCapture, RunnableConfig,
|
||||
SoftWrap, Symbol, TaskListConfig, TextObject, TextObjectConfig, ToLspPosition,
|
||||
WrapCharactersConfig, auto_indent_using_last_non_empty_line_default, deserialize_regex,
|
||||
deserialize_regex_vec, regex_json_schema, regex_vec_json_schema, serialize_regex,
|
||||
};
|
||||
pub use language_registry::{
|
||||
LanguageName, LanguageServerStatusUpdate, LoadedLanguage, ServerHealth,
|
||||
|
|
@ -908,10 +907,6 @@ impl Language {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn with_imports_query(self, source: &str) -> Result<Self> {
|
||||
self.with_grammar_query_and_name(|grammar, name| grammar.with_imports_query(source, name))
|
||||
}
|
||||
|
||||
pub fn with_brackets_query(self, source: &str) -> Result<Self> {
|
||||
self.with_grammar_query_and_name(|grammar, name| grammar.with_brackets_query(source, name))
|
||||
}
|
||||
|
|
@ -1579,9 +1574,6 @@ pub fn rust_lang() -> Arc<Language> {
|
|||
debugger: Some(Cow::from(include_str!(
|
||||
"../../grammars/src/rust/debugger.scm"
|
||||
))),
|
||||
imports: Some(Cow::from(include_str!(
|
||||
"../../grammars/src/rust/imports.scm"
|
||||
))),
|
||||
})
|
||||
.expect("Could not parse queries");
|
||||
Arc::new(language)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ pub struct Grammar {
|
|||
pub injection_config: Option<InjectionConfig>,
|
||||
pub override_config: Option<OverrideConfig>,
|
||||
pub debug_variables_config: Option<DebugVariablesConfig>,
|
||||
pub imports_config: Option<ImportsConfig>,
|
||||
pub highlight_map: Mutex<HighlightMap>,
|
||||
}
|
||||
|
||||
|
|
@ -185,17 +184,6 @@ pub struct DebugVariablesConfig {
|
|||
pub objects_by_capture_ix: Vec<(u32, DebuggerTextObject)>,
|
||||
}
|
||||
|
||||
pub struct ImportsConfig {
|
||||
pub query: Query,
|
||||
pub import_ix: u32,
|
||||
pub name_ix: Option<u32>,
|
||||
pub namespace_ix: Option<u32>,
|
||||
pub source_ix: Option<u32>,
|
||||
pub list_ix: Option<u32>,
|
||||
pub wildcard_ix: Option<u32>,
|
||||
pub alias_ix: Option<u32>,
|
||||
}
|
||||
|
||||
enum Capture<'a> {
|
||||
Required(&'static str, &'a mut u32),
|
||||
Optional(&'static str, &'a mut Option<u32>),
|
||||
|
|
@ -273,7 +261,6 @@ impl Grammar {
|
|||
runnable_config: None,
|
||||
error_query: Query::new(&ts_language, "(ERROR) @error").ok(),
|
||||
debug_variables_config: None,
|
||||
imports_config: None,
|
||||
ts_language,
|
||||
highlight_map: Default::default(),
|
||||
}
|
||||
|
|
@ -300,10 +287,6 @@ impl Grammar {
|
|||
self.debug_variables_config.as_ref()
|
||||
}
|
||||
|
||||
pub fn imports_config(&self) -> Option<&ImportsConfig> {
|
||||
self.imports_config.as_ref()
|
||||
}
|
||||
|
||||
/// Load all queries from `LanguageQueries` into this grammar, mutating the
|
||||
/// associated `LanguageConfig` (the override query clears
|
||||
/// `brackets.disabled_scopes_by_bracket_ix`).
|
||||
|
|
@ -369,11 +352,6 @@ impl Grammar {
|
|||
.with_debug_variables_query(query.as_ref(), name)
|
||||
.context("Error loading debug variables query")?;
|
||||
}
|
||||
if let Some(query) = queries.imports {
|
||||
self = self
|
||||
.with_imports_query(query.as_ref(), name)
|
||||
.context("Error loading imports query")?;
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
|
|
@ -519,49 +497,6 @@ impl Grammar {
|
|||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with_imports_query(
|
||||
mut self,
|
||||
source: &str,
|
||||
language_name: &LanguageName,
|
||||
) -> Result<Self> {
|
||||
let query = Query::new(&self.ts_language, source)?;
|
||||
|
||||
let mut import_ix = 0;
|
||||
let mut name_ix = None;
|
||||
let mut namespace_ix = None;
|
||||
let mut source_ix = None;
|
||||
let mut list_ix = None;
|
||||
let mut wildcard_ix = None;
|
||||
let mut alias_ix = None;
|
||||
if populate_capture_indices(
|
||||
&query,
|
||||
language_name,
|
||||
"imports",
|
||||
&[],
|
||||
&mut [
|
||||
Capture::Required("import", &mut import_ix),
|
||||
Capture::Optional("name", &mut name_ix),
|
||||
Capture::Optional("namespace", &mut namespace_ix),
|
||||
Capture::Optional("source", &mut source_ix),
|
||||
Capture::Optional("list", &mut list_ix),
|
||||
Capture::Optional("wildcard", &mut wildcard_ix),
|
||||
Capture::Optional("alias", &mut alias_ix),
|
||||
],
|
||||
) {
|
||||
self.imports_config = Some(ImportsConfig {
|
||||
query,
|
||||
import_ix,
|
||||
name_ix,
|
||||
namespace_ix,
|
||||
source_ix,
|
||||
list_ix,
|
||||
wildcard_ix,
|
||||
alias_ix,
|
||||
});
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with_brackets_query(
|
||||
mut self,
|
||||
source: &str,
|
||||
|
|
|
|||
|
|
@ -148,15 +148,6 @@ pub struct LanguageConfig {
|
|||
/// A list of preferred debuggers for this language.
|
||||
#[serde(default)]
|
||||
pub debuggers: IndexSet<SharedString>,
|
||||
/// A list of import namespace segments that aren't expected to appear in file paths. For
|
||||
/// example, "super" and "crate" in Rust.
|
||||
#[serde(default)]
|
||||
pub ignored_import_segments: HashSet<Arc<str>>,
|
||||
/// Regular expression that matches substrings to omit from import paths, to make the paths more
|
||||
/// similar to how they are specified when imported. For example, "/mod\.rs$" or "/__init__\.py$".
|
||||
#[serde(default, deserialize_with = "deserialize_regex")]
|
||||
#[schemars(schema_with = "regex_json_schema")]
|
||||
pub import_path_strip_regex: Option<Regex>,
|
||||
}
|
||||
|
||||
impl LanguageConfig {
|
||||
|
|
@ -204,8 +195,6 @@ impl Default for LanguageConfig {
|
|||
completion_query_characters: Default::default(),
|
||||
linked_edit_characters: Default::default(),
|
||||
debuggers: Default::default(),
|
||||
ignored_import_segments: Default::default(),
|
||||
import_path_strip_regex: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ pub mod language_config;
|
|||
pub use diagnostic::{Diagnostic, DiagnosticSourceKind};
|
||||
pub use grammar::{
|
||||
BracketsConfig, BracketsPatternConfig, DebugVariablesConfig, DebuggerTextObject, Grammar,
|
||||
GrammarId, HighlightsConfig, ImportsConfig, IndentConfig, InjectionConfig,
|
||||
InjectionPatternConfig, NEXT_GRAMMAR_ID, OutlineConfig, OverrideConfig, OverrideEntry,
|
||||
RedactionConfig, RunnableCapture, RunnableConfig, TextObject, TextObjectConfig,
|
||||
GrammarId, HighlightsConfig, IndentConfig, InjectionConfig, InjectionPatternConfig,
|
||||
NEXT_GRAMMAR_ID, OutlineConfig, OverrideConfig, OverrideEntry, RedactionConfig,
|
||||
RunnableCapture, RunnableConfig, TextObject, TextObjectConfig,
|
||||
};
|
||||
pub use highlight_map::{HighlightId, HighlightMap};
|
||||
pub use language_config::{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ pub const QUERY_FILENAME_PREFIXES: &[(&str, QueryFieldAccessor)] = &[
|
|||
("runnables", |q| &mut q.runnables),
|
||||
("debugger", |q| &mut q.debugger),
|
||||
("textobjects", |q| &mut q.text_objects),
|
||||
("imports", |q| &mut q.imports),
|
||||
];
|
||||
|
||||
/// Tree-sitter language queries for a given language.
|
||||
|
|
@ -29,5 +28,4 @@ pub struct LanguageQueries {
|
|||
pub runnables: Option<Cow<'static, str>>,
|
||||
pub text_objects: Option<Cow<'static, str>>,
|
||||
pub debugger: Option<Cow<'static, str>>,
|
||||
pub imports: Option<Cow<'static, str>>,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue