diff --git a/README.md b/README.md index 3be0161..4085ced 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ An inspired vscode extentions for creating python docstring on new functions/met |Name | Description| Options |-----|------------|--------- |`pydocs.style`|Sets the doc style you want, currently supports [google](http://google.github.io/styleguide/pyguide.html#Comments) doc style and [numpy](https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt) docstyle| *google *numpy +|`pydocs.ignoreParameters`|Ignore some parameters in defining class or function| ## Things to do - Setup keyboard shortcuts diff --git a/package.json b/package.json index dce7920..c778f00 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,15 @@ "numpy" ], "description": "Set the pydoc string type. google inspired or NumPy: default being google pydocs" + }, + "pydocs.ignoreParameters": { + "type": "array", + "default": [ + "object", + "cls", + "self" + ], + "description": "Set the pydoc ingored parameters. This parameters will be ignored when you create pydoc" } } } diff --git a/src/extension.ts b/src/extension.ts index 45b0ff6..de19ac4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -var indentString = require('indent-string'); +import * as indentString from 'indent-string'; export class paramDeclaration { constructor(public paramName) { @@ -7,13 +7,14 @@ export class paramDeclaration { } } -export function getParameterText(paramList: paramDeclaration[], padding: string, docstyle: string): string { +export function getParameterText(paramList: paramDeclaration[], padding: string, docstyle: string, ignoreParameters: string[]): string { var textToInsert: string = ""; textToInsert = textToInsert + '"""'; + const paramsNeedDeclaration = paramList.filter(element => ignoreParameters.indexOf(element.paramName) === -1) if (docstyle == 'google') { textToInsert = textToInsert + '\ndocstring here\n'; - paramList.forEach(element => { + paramsNeedDeclaration.forEach(element => { if (element.paramName != '') { textToInsert = textToInsert + padding + ':param '; textToInsert = textToInsert + element.paramName + ': \n'; @@ -24,7 +25,7 @@ export function getParameterText(paramList: paramDeclaration[], padding: string, textToInsert = textToInsert + 'Set docstring here.\n'; textToInsert = textToInsert + '\nParameters'; textToInsert = textToInsert + '\n----------\n'; - paramList.forEach(element => { + paramsNeedDeclaration.forEach(element => { if (element.paramName != '') { textToInsert = textToInsert + element.paramName + ': \n'; } @@ -137,6 +138,7 @@ export function activate(ctx:vscode.ExtensionContext) { if (params.length > 0) { var docstyle: string = vscode.workspace.getConfiguration().pydocs.style; + var ignoreParameters: string[] = vscode.workspace.getConfiguration().pydocs.ignoreParameters; var spaces_enabled: boolean = vscode.window.activeTextEditor.options.insertSpaces; var tabSize : number = vscode.window.activeTextEditor.options.tabSize; var padding: string = '' @@ -146,7 +148,7 @@ export function activate(ctx:vscode.ExtensionContext) { else { padding = '\t'; } - var textToInsert = getParameterText(params, padding, docstyle); + var textToInsert = getParameterText(params, padding, docstyle, ignoreParameters); vscode.window.activeTextEditor.edit((editBuilder: vscode.TextEditorEdit) => { var pos:vscode.Position; @@ -175,4 +177,3 @@ export function activate(ctx:vscode.ExtensionContext) { } }); } - diff --git a/vsc-extension-quickstart.md b/vsc-extension-quickstart.md index 6cdea2b..7db5ff6 100644 --- a/vsc-extension-quickstart.md +++ b/vsc-extension-quickstart.md @@ -30,4 +30,4 @@ We pass the function containing the implementation of the command as the second * see the output of the test result in the debug console * make changes to `test/extension.test.ts` or create new test files inside the `test` folder * by convention, the test runner will only consider files matching the name pattern `**.test.ts` - * you can create folders inside the `test` folder to structure your tests any way you want \ No newline at end of file + * you can create folders inside the `test` folder to structure your tests any way you want