diff --git a/.gitignore b/.gitignore index 3d858e1..815b42a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode/ vsc-* -.DS_Store +.DS_Store/ +flask-snippets-* \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cbb18d..5cb51aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,30 +1,55 @@ # Change Log + All notable changes to the "python-snippets" extension will be documented in this file. +## [0.1.2] 2022-02-17 + +- Merge PR #18, #19 + +## [0.1.1] 2021-10-14 + +- Merge PR #14 + +## [0.1.0] + +- Merge PRs #15, #16, #17 + +## [0.0.9] + +- Merge PR #11 + ## [0.0.8] + - Merge PR #9, #10 - Add "New property", issue #2 ## [0.0.7] + - Merge PR #7 ## [0.0.6] + - Merge PR #1 #3 #5 fix typo, new snippets added ## [0.0.5] + - Fix duplicate snippets, adding some doc ## [0.0.4] + - Added abbreviations list with description on README file ## [0.0.3] + - Initial support for Tkinter, ported from Atom snippets found on [GitHub](https://github.com/adiultra/python-snippets) - Splitting snippets into category files ## [0.0.2] + - Public repo on [GitHub](https://github.com/cstrap/python-snippets), feel free to contribute! :-) ## [0.0.1] + - Initial release - Porting Atom [language-python](https://github.com/atom/language-python) with [atomizr](https://www.npmjs.com/package/node-atomizr) - Added some snippets ported from PyCharm diff --git a/README.md b/README.md index 74ecd29..23d82de 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Python snippets +# Python snippets Python snippets collections. @@ -23,17 +23,22 @@ Thanks! | im | import | | fim | from ... import ... | | class | New class | +| classd | New dataclass | | defs | New method | | def | New function | +| dowhile | Do while structure | +| adef | Async function | | property | New property | +| enum | New Enum | | if | if | | for | for | +| lambda | lambda expression | | while | while | | try | try:except: | | tryef | try:except:else:finally: | | trye | try:except:else: | | tryf | try:except:finally: | -| . | self | +| s | self | | __ | __magic__ | | ifmain | if __name__ == "__main__" | @@ -103,7 +108,8 @@ Thanks! ## Release Notes -## 0.0.5 -- Fix duplicate snippets, adding some doc - See [changelog](CHANGELOG.md) for all changes and releases. + +## Troubleshooting + +If you experience problems with the auto-formatting of certain snippets, make sure you have the option `editor.tabCompletion` set on `onlySnippets` or `on`. \ No newline at end of file diff --git a/package.json b/package.json index d80a74c..0bf5373 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "python-snippets", "displayName": "python-snippets", "description": "Python Snippets", - "version": "0.0.8", + "version": "0.1.2", "publisher": "cstrap", "icon": "images/python.png", "engines": { @@ -20,8 +20,7 @@ "url": "https://github.com/cstrap/python-snippets.git" }, "contributes": { - "snippets": [ - { + "snippets": [{ "language": "python", "path": "./snippets/base.json" }, @@ -43,4 +42,4 @@ } ] } -} +} \ No newline at end of file diff --git a/snippets/base.json b/snippets/base.json index 96d5fee..dbfcdcd 100644 --- a/snippets/base.json +++ b/snippets/base.json @@ -47,9 +47,28 @@ }, "New class": { "prefix": "class", - "body": "class ${1:ClassName}(${2:object}):\n\t\"\"\"${3:docstring for $1.}\"\"\"\n\tdef __init__(self, ${4:arg}):\n\t\t${5:super($1, self).__init__()}\n\t\tself.arg = arg\n\t\t$0", + "body": [ + "class ${1:ClassName}(${2:object}):", + "\t\"\"\"${3:docstring for $1.}\"\"\"", + "\tdef __init__(self, ${4:arg}):", + "\t\t${5:super($1, self).__init__()}", + "\t${4/([^,=]+)(?:=[^,]+)?(,\\s*|)/\tself.$1 = $1${2:+\n\t}/g}", + "\n\t$0" + ], "description" : "Code snippet for a class definition." }, + "New dataclass": { + "prefix": "classd", + "body": [ + "from dataclasses import dataclass\n\n", + "@dataclass", + "class ${1:ClassName}(${2:object}):", + "\t\"\"\"${3:Docstring for $1.}\"\"\"", + "\t${4:property}: ${type}", + "\t$0" + ], + "description": "Code snippet for a dataclass definition." + }, "New method": { "prefix": "defs", "body": "def ${1:mname}(self, ${2:arg}):\n\t${3:pass}$0", @@ -60,6 +79,11 @@ "body": "def ${1:fname}(${2:arg}):\n\t${3:pass}$0", "description" : "Code snippet for function definition." }, + "New async function": { + "prefix": "adef", + "body": "async def ${1:fname}(${2:arg}):\n\t${3:pass}$0", + "description" : "Code snippet for async function definition." + }, "New property": { "prefix": "property", "body": "@property\ndef ${1:foo}(self):\n \"\"\"${2:The $1 property.}\"\"\"\n ${3:return self._$1}\n@${4:$1}.setter\ndef ${5:$1}(self, value):\n ${6:self._$1} = value", @@ -70,6 +94,18 @@ "body": "def ${1:foo}():\n doc = \"${2:The $1 property.}\"\n def fget(self):\n ${3:return self._$1}\n def fset(self, value):\n ${4:self._$1 = value}\n def fdel(self):\n ${5:del self._$1}\n return locals()\n$1 = property(**$1())$0", "description" : "" }, + "New enum": { + "prefix": "enum", + "body": [ + "from enum import Enum\n\n", + "class ${1:MyEnum}(Enum):", + "\t\"\"\"${2:Docstring for $1.}\"\"\"", + "\t${3:FIRST_ENUM} = \"some_value\"", + "\t${4:SECOND_ENUM} = \"some_other_value\"", + "\t$0" + ], + "description": "Code snippet for enum definition." + }, "if": { "prefix": "if", "body": "if ${1:condition}:\n\t${2:pass}$0", @@ -85,6 +121,11 @@ "body": "while ${1:condition}:\n\t${2:pass}$0", "description" : "Code snippet to create a while loop structure." }, + "dowhile": { + "prefix": "dowhile", + "body": "do = True\nwhile do or ${2:condition}:\n\tdo = False\n\t${1:body}$0", + "description" : "Code snippet to create a do-while loop structure." + }, "try:except:": { "prefix": "try", "body": "try:\n\t${1:pass}\nexcept ${2:Exception} as ${3:e}:\n\t${4:raise $3}$0", @@ -106,7 +147,7 @@ "description" : "Code Snippet for a try/except/finally." }, "self": { - "prefix": ".", + "prefix": "s", "body": "self.$0", "description" : "Shortend snippet to reference the self property in an object." }, @@ -119,5 +160,10 @@ "prefix": "ifmain", "body": "if __name__ == \"__main__\":\n\t${1:main()}$0", "description" : "Create implicitly all the code at the top level using the __name__ special variable." + }, + "lambda": { + "prefix": "lam", + "body": "lambda ${1:args}: ${2:expr}", + "description": "Create template for lambda function" } -} \ No newline at end of file +}