Skip to content

Commit

Permalink
fix: solve line break in annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
PanPanZou authored and yndu13 committed Jul 15, 2024
1 parent e7e602b commit e197f60
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
60 changes: 44 additions & 16 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,13 @@ class Visitor {
return item.text.text;
});

var descriptionText = description ? _escape(description.text.text.trimEnd()) : '';
var summaryText = summary ? _escape(summary.text.text.trimEnd()) : '';
var returnText = _return ? _return.text.text.trimEnd() : '';
let hasNextSection = false;
const summaryText = summary ? _escape(summary.text.text).trimEnd() : '';
const descriptionText = description ? _escape(description.text.text).trimEnd() : '';
const returnText = _return ? _escape(_return.text.text).trimEnd() : '';

if (deprecated) {
let deprecatedText = deprecated.text.text.trimEnd();
const deprecatedText = _escape(deprecated.text.text).trimEnd();
deprecatedText.split('\n').forEach((line, index, array) => {
if(index === 0) {
this.emit(`// Deprecated: ${line}\n`, level);
Expand Down Expand Up @@ -435,30 +436,57 @@ class Visitor {
if (hasNextSection) {
this.emit(`// \n`, level);
}
params.forEach((item, index) => {
this.emit(`// @param ${item.name} - ${item.text}`, level);
if (index < params.length - 1) {
this.emit(`// \n`, level);
}
params.forEach((item, i) => {
this.emit(`// @param ${item.name} - `, level);
const items = item.text.trimEnd().split('\n');
items.forEach((line, j) => {
if (j === 0) {
this.emit(`${line}\n`);
} else {
this.emit(`// ${line}\n`, level);
}
if (j < items.length - 1 || (j === items.length - 1 && i < params.length -1)) {
this.emit(`// \n`, level);
}
});
});
hasNextSection = true;
}
if (returnText !== '') {
if (returnText) {
if (hasNextSection) {
this.emit(`// \n`, level);
}
this.emit(`// @return ${returnText}\n`, level);
this.emit(`// @return `, level);
const returns = returnText.split('\n');
returns.forEach((line, index) => {
if (index === 0) {
this.emit(`${line}\n`);
} else {
this.emit(`// ${line}\n`, level);
}
if (index < returns.length - 1) {
this.emit(`// \n`, level);
}
});
hasNextSection = true;
}
if (throws.length > 0) {
if (hasNextSection) {
this.emit(`// \n`, level);
}
throws.forEach((item, index) => {
this.emit(`// @throws ${item}`, level);
if (index < throws.length - 1) {
this.emit(`// \n`, level);
}
throws.forEach((item, i) => {
this.emit(`// @throws `, level);
const items = item.trimEnd().split('\n');
items.forEach((line, j) => {
if (j === 0) {
this.emit(`${line}\n`);
} else {
this.emit(`// ${line}\n`, level);
}
if (j < items.length - 1 || (j === items.length - 1 && i < params.length -1)) {
this.emit(`// \n`, level);
}
});
});
}
}
Expand Down
12 changes: 9 additions & 3 deletions test/fixtures/annotation/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func TestFuncWithAnnotation1 (test *string, _test *string) (_err error) {
// @return void
//
// @throws InternalError Server error. 500 服务器端出现未知异常。
//
func TestFuncWithAnnotation2 (test *string, _test *string) (_err error) {
// empty comment1
// empty comment2
Expand All @@ -146,14 +147,19 @@ func TestFuncWithAnnotation2 (test *string, _test *string) (_err error) {
//
// @param test - string param1
//
// param test for line break.
//
// @param _test - string param2
//
// @return void
//
// return test for line break.
//
// @throws InternalError Server error. 500 服务器端出现未知异常。
func TestFuncWithAnnotation3 (test *string, _test *string) (_err error) {
// empty comment1
// empty comment2
//
// throws test for line break.
//
func LineBreakAnnotation (test *string, _test *string) (_err error) {
return _err
}

8 changes: 5 additions & 3 deletions test/fixtures/annotation/main.dara
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ static async function testFuncWithAnnotation2(test: string, _test: string): void
* deprecated test for line break.
*
* @param test string param1
* param test for line break.
* @param _test string param2
* @return void
* return test for line break.
* @throws InternalError Server error. 500 服务器端出现未知异常。
* throws test for line break.
*/
static async function testFuncWithAnnotation3(test: string, _test: string): void {
// empty comment1
// empty comment2
static async function lineBreakAnnotation(test: string, _test: string): void {
}

0 comments on commit e197f60

Please sign in to comment.