diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 791e1c00f..e0251b302 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -16,7 +16,6 @@ mod foreign_function_definition; pub mod fs; mod inline_snippets; -#[cfg(any(feature = "napi", feature = "wasm_core"))] pub mod sdk; mod limits; diff --git a/crates/core/src/pattern_compiler/auto_wrap.rs b/crates/core/src/pattern_compiler/auto_wrap.rs index c0d4202a6..e95127220 100644 --- a/crates/core/src/pattern_compiler/auto_wrap.rs +++ b/crates/core/src/pattern_compiler/auto_wrap.rs @@ -470,7 +470,7 @@ fn wrap_pattern_in_file( Ok(pattern) } -pub(crate) fn wrap_pattern_in_before_and_after_each_file( +pub fn wrap_pattern_in_before_and_after_each_file( pattern: Pattern, context: &mut dyn SnippetCompilationContext, ) -> Result> { diff --git a/crates/core/src/pattern_compiler/builder.rs b/crates/core/src/pattern_compiler/builder.rs index dde65490c..ac3881722 100644 --- a/crates/core/src/pattern_compiler/builder.rs +++ b/crates/core/src/pattern_compiler/builder.rs @@ -1,8 +1,9 @@ use super::{ auto_wrap::auto_wrap_pattern, compiler::{ - filter_libs, get_definition_info, get_definitions, CompilationContext, DefinitionInfo, - DefinitionInfoKinds, NodeCompilationContext, VariableLocations, + build_standard_global_vars, filter_libs, get_definition_info, get_definitions, + CompilationContext, DefinitionInfo, DefinitionInfoKinds, NodeCompilationContext, + VariableLocations, }, pattern_compiler::PatternCompiler, CompilationResult, NodeCompiler, @@ -305,12 +306,3 @@ impl CompiledPatternBuilder { Ok(result) } } - -pub fn build_standard_global_vars() -> BTreeMap { - BTreeMap::from([ - ("$new_files".to_owned(), NEW_FILES_INDEX), - ("$filename".to_owned(), FILENAME_INDEX), - ("$program".to_owned(), PROGRAM_INDEX), - ("$absolute_filename".to_owned(), ABSOLUTE_PATH_INDEX), - ]) -} diff --git a/crates/core/src/pattern_compiler/compiler.rs b/crates/core/src/pattern_compiler/compiler.rs index fa7151b4c..47bae670f 100644 --- a/crates/core/src/pattern_compiler/compiler.rs +++ b/crates/core/src/pattern_compiler/compiler.rs @@ -16,7 +16,10 @@ use crate::{ }; use anyhow::{anyhow, bail, Result}; use grit_pattern_matcher::{ - constants::{DEFAULT_FILE_NAME, GLOBAL_VARS_SCOPE_INDEX, MATCH_VAR}, + constants::{ + ABSOLUTE_PATH_INDEX, DEFAULT_FILE_NAME, FILENAME_INDEX, GLOBAL_VARS_SCOPE_INDEX, MATCH_VAR, + NEW_FILES_INDEX, PROGRAM_INDEX, + }, pattern::{ DynamicSnippetPart, GritFunctionDefinition, Pattern, PatternDefinition, PredicateDefinition, Variable, VariableContent, VariableSource, @@ -395,7 +398,7 @@ pub(crate) fn get_definitions( global_vars .iter() .sorted_by(|x, y| Ord::cmp(x.1, y.1)) - .map(|x| VariableSource::new(x.0.clone(), context.file.to_owned())) + .map(|x| VariableSource::new(x.0.clone(), DEFAULT_FILE_NAME.to_owned())) .collect(), ); @@ -702,7 +705,7 @@ pub fn src_to_problem(src: String, default_lang: TargetLanguage) -> Result>, @@ -746,6 +749,15 @@ impl VariableLocations { } variables } + + pub(crate) fn globals() -> Self { + let global_vars = build_standard_global_vars(); + let locations = global_vars + .iter() + .map(|(name, index)| VariableSource::new_global(name.to_owned())) + .collect(); + Self::new(vec![locations]) + } } #[cfg(test)] @@ -818,3 +830,12 @@ mod tests { ); } } + +pub fn build_standard_global_vars() -> BTreeMap { + BTreeMap::from([ + ("$new_files".to_owned(), NEW_FILES_INDEX), + ("$filename".to_owned(), FILENAME_INDEX), + ("$program".to_owned(), PROGRAM_INDEX), + ("$absolute_filename".to_owned(), ABSOLUTE_PATH_INDEX), + ]) +} diff --git a/crates/core/src/pattern_compiler/mod.rs b/crates/core/src/pattern_compiler/mod.rs index 7cc3cce7e..4c0b30b61 100644 --- a/crates/core/src/pattern_compiler/mod.rs +++ b/crates/core/src/pattern_compiler/mod.rs @@ -77,7 +77,8 @@ pub(crate) mod variable_compiler; pub(crate) mod where_compiler; pub(crate) mod within_compiler; -pub use builder::build_standard_global_vars; +pub use auto_wrap::wrap_pattern_in_before_and_after_each_file; pub use builder::CompiledPatternBuilder; +pub use compiler::build_standard_global_vars; pub use compiler::{src_to_problem_libs, CompilationResult}; pub(crate) use node_compiler::NodeCompiler; diff --git a/crates/core/src/problem.rs b/crates/core/src/problem.rs index 712ea0b36..355880e41 100644 --- a/crates/core/src/problem.rs +++ b/crates/core/src/problem.rs @@ -7,7 +7,7 @@ use crate::{ marzano_code_snippet::MarzanoCodeSnippet, marzano_context::MarzanoContext, marzano_resolved_pattern::{MarzanoFile, MarzanoResolvedPattern}, - pattern_compiler::compiler::VariableLocations, + pattern_compiler::{build_standard_global_vars, compiler::VariableLocations}, }; use anyhow::{bail, Result}; use grit_pattern_matcher::{ @@ -83,6 +83,26 @@ impl Problem { } defs } + + pub fn new( + pattern: Pattern, + language: TargetLanguage, + built_ins: BuiltIns, + ) -> Self { + Self::new_from_pattern( + pattern, + language, + built_ins, + false, // is_multifile + false, // has_limit + None, // name + VariableLocations::globals(), + vec![], // pattern_definitions + vec![], // predicate_definitions + vec![], // function_definitions + vec![], // foreign_function_definitions + ) + } } enum FilePattern { diff --git a/crates/core/src/sdk/language_sdk.rs b/crates/core/src/sdk/language_sdk.rs index f91f52f00..e20187fb6 100644 --- a/crates/core/src/sdk/language_sdk.rs +++ b/crates/core/src/sdk/language_sdk.rs @@ -5,9 +5,7 @@ use marzano_language::target_language::TargetLanguage; use crate::{ built_in_functions::BuiltIns, - pattern_compiler::{ - auto_wrap::auto_wrap_pattern, build_standard_global_vars, compiler::VariableLocations, - }, + pattern_compiler::{auto_wrap::auto_wrap_pattern, compiler::VariableLocations}, problem::{MarzanoQueryContext, Problem}, }; @@ -48,7 +46,6 @@ impl LanguageSdk { pattern: Pattern, ) -> Result { let _logs: AnalysisLogs = vec![].into(); - let global_vars = build_standard_global_vars(); let mut pattern_definitions = vec![]; let is_multifile = false; @@ -69,10 +66,7 @@ impl LanguageSdk { is_multifile, false, None, - VariableLocations::new(vec![global_vars - .into_keys() - .map(VariableSource::new_global) - .collect()]), + VariableLocations::globals(), pattern_definitions, vec![], vec![], diff --git a/crates/core/src/sdk/mod.rs b/crates/core/src/sdk/mod.rs index 1f064edc7..a4e1e7006 100644 --- a/crates/core/src/sdk/mod.rs +++ b/crates/core/src/sdk/mod.rs @@ -6,6 +6,6 @@ mod test_js; #[cfg(feature = "napi")] mod binding; -pub(crate) use compiler::StatelessCompilerContext; +pub use compiler::StatelessCompilerContext; pub use language_sdk::LanguageSdk; pub use pattern_sdk::UncompiledPatternBuilder; diff --git a/crates/language/src/markdown_inline.rs b/crates/language/src/markdown_inline.rs index 148b1c8d1..282c883d5 100644 --- a/crates/language/src/markdown_inline.rs +++ b/crates/language/src/markdown_inline.rs @@ -28,7 +28,7 @@ pub struct MarkdownInline { } impl MarkdownInline { - pub(crate) fn new(lang: Option) -> Self { + pub fn new(lang: Option) -> Self { let language = LANGUAGE.get_or_init(|| lang.unwrap_or_else(language)); let node_types = NODE_TYPES.get_or_init(|| fields_for_nodes(language, NODE_TYPES_STRING)); let metavariable_sort = language.id_for_node_kind("grit_metavariable", true); diff --git a/resources/language-submodules/tree-sitter-c-sharp b/resources/language-submodules/tree-sitter-c-sharp index 80ae1c57c..dd5e59721 160000 --- a/resources/language-submodules/tree-sitter-c-sharp +++ b/resources/language-submodules/tree-sitter-c-sharp @@ -1 +1 @@ -Subproject commit 80ae1c57c2001a44e126a81ce3b149cd8af760c8 +Subproject commit dd5e59721a5f8dae34604060833902b882023aaf