-
-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added class and module docstrings #174
base: master
Are you sure you want to change the base?
Changes from all commits
3f07a57
a8f0ef3
6ad28ab
07cb44e
125110b
11a2efa
180141e
739b166
cff0855
d099316
209f1ed
30537c3
0d7603e
e620d1f
0b08830
1ba0736
29442b7
1b2c384
c8ad667
b178d92
187d850
1f7f3ef
b6eb8a4
24de229
63e67d1
0dac472
5b43992
973fb88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Changes made to autoDocstring to incorporate module level docstrings | ||
- src/parse/get_body.ts | ||
- getBody(): if docstring is being added at first line of document, return entire document as body | ||
- src/docstring_parts.ts | ||
- DocstringParts: added Class[] and Method[] attributes | ||
- Class: Created Class interface | ||
- Method: Created Method interface | ||
- src/parse/parse_parameters.ts | ||
- parseParameters(): added positionLine argument, if positionLine == 0 return only top-level classes and methods, otherwise return normal DocstringParts | ||
- parseClasses(): returns list of top-level classes | ||
- parseMethods(): returns list of top-level methods | ||
- src/docstring/template_data.ts | ||
- TemplateData: added classes and methods attributes, updated constructor to take list of classes and list of methods | ||
- classesExist(): added method to check if classes exist, needed to parse template | ||
- methodsExist(): added method to check if methods exist, needed to parse template | ||
- src/docstring/templates/ncr.mustache | ||
- Created template file that incorporates classes and methods | ||
- package.json | ||
- contributes.configuration.properties.autoDocstring.docstringFormat.enum | ||
- Added "ncr" template (this should probably be removed) | ||
- contributes.commands[0].title | ||
- Changed to "Generate Docstring2" just to avoid any confusion, will change back when ready for PR | ||
|
||
# To run the code | ||
- Open the autoDocstring folder in VS Code | ||
- Open the command palette (Ctrl+Shift+P) and type `settings.json` to open the settings configuration file | ||
- Add the line `"autoDocstring.customTemplatePath": "/home/shared/Projects/autoDocstring/src/docstring/templates/ncr.mustache"` and make sure the path to the ncr.mustache template is correct for your computer. | ||
- Save and close settings.json. | ||
- Press F5 | ||
- Click "Debug Anyway" | ||
- When the new screen opens, open a folder to any project you want to add a module level docstring to | ||
- On line 1, click Ctrl+Shift+P or input """ and press enter. | ||
- The docstring should populate and list all top-level classes and methods in the file. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{{! NCR Docstring Template }} | ||
tracetidwell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{{summaryPlaceholder}} | ||
|
||
{{extendedSummaryPlaceholder}} | ||
|
||
{{#classesExist}} | ||
Classes | ||
------- | ||
{{#classes}} | ||
{{name}} | ||
{{/classes}} | ||
{{/classesExist}} | ||
|
||
{{#methodsExist}} | ||
Methods | ||
------- | ||
{{#methods}} | ||
{{name}} | ||
{{/methods}} | ||
{{/methodsExist}} | ||
|
||
{{#parametersExist}} | ||
Parameters | ||
---------- | ||
{{#args}} | ||
{{var}} : {{typePlaceholder}} | ||
{{descriptionPlaceholder}} | ||
|
||
{{/args}} | ||
{{#kwargs}} | ||
{{var}} : {{typePlaceholder}}, optional | ||
{{descriptionPlaceholder}}, by default {{&default}} | ||
|
||
{{/kwargs}} | ||
{{/parametersExist}} | ||
|
||
{{#attributesExist}} | ||
Attributes | ||
---------- | ||
{{#attributes}} | ||
{{var}} : {{typePlaceholder}} | ||
{{descriptionPlaceholder}} | ||
|
||
{{/attributes}} | ||
{{/attributesExist}} | ||
|
||
{{#returnsExist}} | ||
Returns | ||
------- | ||
{{#returns}} | ||
return_val : {{typePlaceholder}} | ||
{{descriptionPlaceholder}} | ||
|
||
{{/returns}} | ||
{{/returnsExist}} | ||
|
||
{{#yieldsExist}} | ||
Yields | ||
------- | ||
{{#yields}} | ||
yield_val : {{typePlaceholder}} | ||
{{descriptionPlaceholder}} | ||
|
||
{{/yields}} | ||
{{/yieldsExist}} | ||
|
||
{{#exceptionsExist}} | ||
Raises | ||
------ | ||
{{#exceptions}} | ||
{{type}} | ||
{{descriptionPlaceholder}} | ||
|
||
{{/exceptions}} | ||
{{/exceptionsExist}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ export interface DocstringParts { | |
exceptions: Exception[]; | ||
returns: Returns; | ||
yields: Yields; | ||
classes: Method[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you create a separate type for classes |
||
methods: Method[]; | ||
attributes: Attribute[]; | ||
} | ||
|
||
export interface Decorator { | ||
|
@@ -34,3 +37,16 @@ export interface Returns { | |
export interface Yields { | ||
type: string; | ||
} | ||
|
||
// export interface Class { | ||
// name: string; | ||
// } | ||
|
||
export interface Method { | ||
name: string; | ||
} | ||
|
||
export interface Attribute { | ||
var: string; | ||
type: string; | ||
} | ||
tracetidwell marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export function getClassName(functionDefinition: string): string { | ||
//const pattern1 = /(?:class)\s+(\w+)\s*\(/; | ||
const pattern1 = /(?:class)\s+(\w+)/; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These patterns look the same. |
||
const pattern2 = /(?:class)\s+(\w+)/; | ||
|
||
const match1 = pattern1.exec(functionDefinition); | ||
const match2 = pattern2.exec(functionDefinition); | ||
|
||
if (match1 != undefined && match1[1] != undefined) { | ||
return match1[1]; | ||
} | ||
else if (match2 != undefined && match2[1] != undefined) { | ||
return match2[1] | ||
} | ||
else { | ||
return ""; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this pr guide! Can you move it to a comment on the pr so that we can take it out if the code but ˆcan still read it?