From 5cfb20f4bc05ffc038595af815553d6bbd57573f Mon Sep 17 00:00:00 2001 From: He1pa <18012015693@163.com> Date: Wed, 9 Aug 2023 15:45:56 +0800 Subject: [PATCH] bugfix: doc parser panic when empty line length less than min margin --- kclvm/sema/src/resolver/doc.rs | 12 ++++++++---- kclvm/sema/src/resolver/test_data/doc.txt | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/kclvm/sema/src/resolver/doc.rs b/kclvm/sema/src/resolver/doc.rs index 91223aefb..7b4c88b0a 100644 --- a/kclvm/sema/src/resolver/doc.rs +++ b/kclvm/sema/src/resolver/doc.rs @@ -40,10 +40,14 @@ fn clean_doc(doc: &mut String) { .unwrap_or(0); lines[1..].iter_mut().for_each(|line| { - *line = if line.len() > 0 { - &line[margin..] + *line = if line.trim().len() > 0 { + if let Some(sub) = line.get(margin..) { + sub + } else { + line.trim() + } } else { - line + line.trim() }; // remove command indentation }); @@ -354,7 +358,7 @@ de", A Server-level attribute. The labels of the long-running service. See also: kusion_models/core/v1/metadata.k. - + Examples ---------------------- myCustomApp = AppConfiguration { diff --git a/kclvm/sema/src/resolver/test_data/doc.txt b/kclvm/sema/src/resolver/test_data/doc.txt index 895be4bf4..6cf94821d 100644 --- a/kclvm/sema/src/resolver/test_data/doc.txt +++ b/kclvm/sema/src/resolver/test_data/doc.txt @@ -16,7 +16,7 @@ A Server-level attribute. The labels of the long-running service. See also: kusion_models/core/v1/metadata.k. - + Examples ---------------------- myCustomApp = AppConfiguration {