Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import * as vscode from 'vscode';
var indentString = require('indent-string');
import * as indentString from 'indent-string';

export class paramDeclaration {
constructor(public paramName) {
this.paramName = paramName;
}
}

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';
Expand All @@ -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';
}
Expand Down Expand Up @@ -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 = ''
Expand All @@ -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;
Expand Down Expand Up @@ -175,4 +177,3 @@ export function activate(ctx:vscode.ExtensionContext) {
}
});
}

2 changes: 1 addition & 1 deletion vsc-extension-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
* you can create folders inside the `test` folder to structure your tests any way you want