-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: ygqygq2 <ygqygq2@qq.com>
- Loading branch information
Showing
16 changed files
with
199 additions
and
74 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
sampleWorkspace/function-comment-for-go/function-none-params-with-return.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
func testFunc() (string) { | ||
return "test" | ||
} |
7 changes: 7 additions & 0 deletions
7
sampleWorkspace/function-comment-for-go/function-none-params-with-return.result.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* @description | ||
* @return default {string} | ||
*/ | ||
func testFunc() (string) { | ||
return "test" | ||
} |
3 changes: 3 additions & 0 deletions
3
sampleWorkspace/function-comment-for-go/function-none-params-without-return.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
func testFunc() { | ||
fmt.Println("test") | ||
} |
6 changes: 6 additions & 0 deletions
6
sampleWorkspace/function-comment-for-go/function-none-params-without-return.result.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @description | ||
*/ | ||
func testFunc() { | ||
fmt.Println("test") | ||
} |
3 changes: 3 additions & 0 deletions
3
sampleWorkspace/function-comment-for-go/function-with-params-type-with-return.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
func funcName(param1 string, param2 []int) (r1 string, r2 []int) { | ||
return param1, param2 | ||
} |
10 changes: 10 additions & 0 deletions
10
sampleWorkspace/function-comment-for-go/function-with-params-type-with-return.result.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* @description | ||
* @return r1 {string} | ||
* @return r2 {[]int} | ||
* @param param1 {string} | ||
* @param param2 {[]int} | ||
*/ | ||
func funcName(param1 string, param2 []int) (r1 string, r2 []int) { | ||
return param1, param2 | ||
} |
3 changes: 3 additions & 0 deletions
3
sampleWorkspace/function-comment-for-go/function-with-params-type-without-return.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
func funcName(param1 string, param2 []int) { | ||
return param1, param2 | ||
} |
8 changes: 8 additions & 0 deletions
8
sampleWorkspace/function-comment-for-go/function-with-params-type-without-return.result.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* @description | ||
* @param param1 {string} | ||
* @param param2 {[]int} | ||
*/ | ||
func funcName(param1 string, param2 []int) { | ||
return param1, param2 | ||
} |
9 changes: 0 additions & 9 deletions
9
sampleWorkspace/function-comment-for-go/function-with-params-type.go
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
sampleWorkspace/function-comment-for-ts/variable-function-with-params-type-update.result.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export function extractFunctionParamsString(functionDefinition: string): string { | ||
let bracketCount = 0; | ||
let paramsStartIndex = 0; | ||
let paramsEndIndex = 0; | ||
|
||
for (let i = 0; i < functionDefinition.length; i++) { | ||
const char = functionDefinition[i]; | ||
if (char === '(') { | ||
if (bracketCount === 0) { | ||
paramsStartIndex = i + 1; | ||
} | ||
bracketCount++; | ||
} else if (char === ')') { | ||
bracketCount--; | ||
if (bracketCount === 0) { | ||
paramsEndIndex = i; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return functionDefinition.slice(paramsStartIndex, paramsEndIndex); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { LanguageFunctionCommentSettings } from '@/typings/types'; | ||
|
||
import { ParamsInfo } from './types'; | ||
|
||
export function splitParams( | ||
paramsStr: string, | ||
languageSettings: LanguageFunctionCommentSettings, | ||
): ParamsInfo { | ||
const { defaultParamType = 'any', defaultReturnName = 'default' } = languageSettings; | ||
let bracketCount = 0; | ||
let paramStartIndex = 0; | ||
let defaultCount = 0; | ||
const params: ParamsInfo = {}; | ||
for (let i = 0; i < paramsStr?.length; i++) { | ||
const char = paramsStr[i]; | ||
if (char === '(' || char === '[' || char === '{' || char === '<') { | ||
bracketCount++; | ||
} else if (char === ')' || char === ']' || char === '}' || char === '>') { | ||
bracketCount--; | ||
} else if ( | ||
(char === ',' && bracketCount === 0) || | ||
(i === paramsStr.length - 1 && bracketCount === 0) | ||
) { | ||
const paramStr = paramsStr | ||
.slice(paramStartIndex, i === paramsStr.length - 1 ? i + 1 : i) | ||
.trim(); | ||
const paramPattern = /^(\w+)?\s*(.*)$/; | ||
const match = paramPattern.exec(paramStr); | ||
if (match) { | ||
let name, type; | ||
if (match[2]) { | ||
name = | ||
match[1] || | ||
(defaultCount > 0 ? `${defaultReturnName}${defaultCount++}` : defaultReturnName); | ||
type = match[2].trim() || defaultParamType; | ||
} else { | ||
name = defaultCount > 0 ? `${defaultReturnName}${defaultCount++}` : defaultReturnName; | ||
type = match[1].trim() || defaultParamType; | ||
} | ||
params[name] = { type, description: '' }; | ||
} | ||
paramStartIndex = i + 1; | ||
} | ||
} | ||
return params; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { functionCommentTester } from './common/functionCommentTester'; | ||
import { TestInfo } from './types'; | ||
|
||
const testInfo: TestInfo = [ | ||
{ | ||
testName: 'go-function', | ||
workspaceName: 'function-comment-for-go', | ||
files: [ | ||
{ fileName: 'function-none-params-with-return.go', cursorLine: 0 }, | ||
{ fileName: 'function-none-params-without-return.go', cursorLine: 0 }, | ||
{ fileName: 'function-with-params-type-with-return.go', cursorLine: 0 }, | ||
{ fileName: 'function-with-params-type-without-return.go', cursorLine: 0 }, | ||
], | ||
}, | ||
]; | ||
|
||
functionCommentTester(testInfo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters