Skip to content

Commit

Permalink
fix: fixed a formatting error when inserting import stmt into a KCL f… (
Browse files Browse the repository at this point in the history
#1307)

fix: fixed a formatting error when inserting import stmt into a KCL file with comments by OverrideFile api

Signed-off-by: zongz <zongzhe1024@163.com>
  • Loading branch information
zong-zhe authored May 13, 2024
1 parent 2345a81 commit e2c778f
Show file tree
Hide file tree
Showing 9 changed files with 855 additions and 55 deletions.
4 changes: 3 additions & 1 deletion kclvm/ast_pretty/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ impl<'p, 'ctx> MutSelfTypedResultWalker<'ctx> for Printer<'p> {

fn walk_import_stmt(&mut self, import_stmt: &'ctx ast::ImportStmt) -> Self::Result {
self.write("import ");
self.write(&import_stmt.path.node);
// use `import_stmt.rawpath` to write the raw path
// otherwise, use `import_stmt.path` will replace `import .xxx` with `import xxx`
self.write(&import_stmt.rawpath);
if let Some(as_name) = &import_stmt.asname {
self.write(" as ");
self.write(&as_name.node);
Expand Down
38 changes: 0 additions & 38 deletions kclvm/cmd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,44 +59,6 @@ pub fn app() -> Command {
.arg(arg!(recursive: -R --recursive "Compile the files directory recursively"))
.arg(arg!(package_map: -E --external <package_map> ... "Mapping of package name and path where the package is located").num_args(1..)),
)
.subcommand(
Command::new("lint")
.about("lint")
.arg(arg!([input] ... "Sets the input file to use").num_args(0..))
.arg(arg!(output: -o --output <output> "Specify the YAML output file path"))
.arg(arg!(setting: -Y --setting <setting> ... "Sets the input file to use").num_args(1..))
.arg(arg!(verbose: -v --verbose "Print test information verbosely").action(ArgAction::Count))
.arg(arg!(emit_warning: --emit_warning "Emit warning message"))
.arg(arg!(disable_none: -n --disable_none "Disable dumping None values"))
.arg(arg!(strict_range_check: -r --strict_range_check "Do perform strict numeric range checks"))
.arg(arg!(debug: -d --debug "Run in debug mode (for developers only)"))
.arg(arg!(sort_keys: -k --sort_keys "Sort result keys"))
.arg(arg!(show_hidden: -H --show_hidden "Display hidden attributes"))
.arg(arg!(fast_eval: --fast_eval "Use the fast evaluation mode"))
.arg(arg!(arguments: -D --argument <arguments> ... "Specify the top-level argument").num_args(1..))
.arg(arg!(path_selector: -S --path_selector <path_selector> ... "Specify the path selector").num_args(1..))
.arg(arg!(overrides: -O --overrides <overrides> ... "Specify the configuration override path and value").num_args(1..))
.arg(arg!(target: --target <target> "Specify the target type"))
.arg(arg!(recursive: -R --recursive "Compile the files directory recursively"))
.arg(arg!(package_map: -E --external <package_map> ... "Mapping of package name and path where the package is located").num_args(1..))
.arg(arg!(fix: -f --fix "Auto fix")),
)
.subcommand(
Command::new("fmt")
.about("Format KCL files")
.arg(arg!(<input> "Input file or path name for formatting"))
.arg(arg!(recursive: -R --recursive "Iterate through subdirectories recursively"))
.arg(arg!(std_output: -w --std_output "Whether to output format to stdout")),
)
.subcommand(
Command::new("vet")
.about("Validate data files witch KCL files")
.arg(arg!(<data_file> "Validation data file"))
.arg(arg!(<kcl_file> "KCL file"))
.arg(arg!(schema: -d --schema <schema> "Iterate through subdirectories recursively").num_args(1..))
.arg(arg!(attribute_name: -n --attribute_name <attribute_name> "The attribute name for the data loading"))
.arg(arg!(format: --format <format> "Validation data file format, support YAML and JSON, default is JSON")),
)
.subcommand(Command::new("server").about("Start a rpc server for APIs"))
.subcommand(Command::new("version").about("Show the KCL version"))
}
1 change: 1 addition & 0 deletions kclvm/query/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! function to modify the file. The main principle is to parse the AST according to the
//! input file name, and according to the ast::OverrideSpec transforms the nodes in the
//! AST, recursively modifying or deleting the values of the nodes in the AST.
pub mod node;
pub mod r#override;
pub mod path;
pub mod query;
Expand Down
Loading

0 comments on commit e2c778f

Please sign in to comment.