Comments (6)
This request is a little difficult to complete. Currently docstring formats are integrated by creating individual classes (like this one) that conform to a base interface so that they can be called transparently by the extension. This makes it pretty easy to add new formats and you are free to create a PR integrating a new type of docstring that might be useful to others. However, it would probably be impossible to have this be a setting, since it involves at least a few dozen lines of code.
I am open to suggestions for how this could be integrated though as I think it could potentially be useful to others.
from autodocstring.
@NilsJPWerner Is there anyway i can set the custom docstring for myself?
from autodocstring.
Yes indeed customizable snippets do not seem like a low-hanging fruit feature. One possible approach is to:
- utilize some template engine (like Jinja2 in Python but something for TypeScript)
- add a plugin-specific setting "docstringTemplatesFilename"
- read and process templates from that file.
I've seen something similar in vim plugins, e.g.: https://github.com/heavenshell/vim-pydocstring/blob/master/template/pydocstring/multi.txt
from autodocstring.
It would be awesome to be able to specify own docstring template in the file like:
"""description
<arg>: type - arg description
return res - res description
"""
or in the vscode JSON options as a multi-line string like:
"autoDocstring.docstringFormat": "custom",
"autoDocstring.docstringTemplate": [
"description",
"",
"<arg>: type - arg description", // <arg> replaced with the actual argument names
"",
"return res - res description"
],
Where everything is substituted as it is except the <arg>
paragraph, which is duplicated the number of times equal to the actual number of arguments and the actual argument names are substituted.
This is seems to be easily implementable by adding a template: string
parameter to the BaseFactory::createDocstring
and using the outlined processing instead of the abstract
callbacks when that template
parameter is not null
(i.e. specified in the VSCode config).
from autodocstring.
Yes, I agree. Even something simpler such as autodetecting the formats from a folder; e.g. the different classes are:
src/docstring_factories
-- numpy.ts
-- google.ts
-- sphinx.ts
but the user would be able to specify a custom directory
"autoDocstring.docstringFormatsDirectory" : "/my/custom/directory"
/my/custom/directory/
-- format1.ts
-- awesome.ts
Each one of these could be a file such as
import * as interfaces from '../docstring_parts';
import { BaseFactory } from './base_factory'
import * as vscode from 'vscode';
export class AwesomeFactory extends BaseFactory {
...
}
Furthermore, the factories.ts
in the src/docstring_factories
could use the following
export * from vs.workspace.getConfiguration("autoDocstring").get("docstringFormatsDirectory");
(not sure if this would actually work, nor if this could be appropriately error handled, but it's an idea that certainly requires less syntax parsing on behalf of the developer)
This could probably provide some security issues too though.
from autodocstring.
Custom templates are now supported in the latest version of the extension. v0.3.0
from autodocstring.
Related Issues (20)
- [feature request] Enable use in types of files besides *.py
- exceptions may occur multiple times HOT 1
- Tab is not working to move to next editable object
- Parser gets confused with comments HOT 1
- Doesn't generate doctoring around comments using 3 quotes HOT 3
- [feature request] Update existing docstring HOT 1
- Extension host crashes
- module level google style docstring
- autodocstring
- return field should be named "returns"
- [feature request] add support for positional-only and keyword-only arguments
- Autocomplete python file metadata
- Extended summary missing HOT 1
- Update Node.js Version to 18 or Later used in Github actions
- [bug] Broken links in README.md
- [feature request] - Add setting to fold doc strings
- [feature request] - Create or update the docstring for the next declaration that preceeds the cursor
- python 3.12 generics support
- Regular code completion blocked by extension. HOT 1
- Empty doctrings being generated HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autodocstring.