Skip to content
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

Probably some mistake in class snippet #21

Open
piotrgredowski opened this issue Jun 29, 2022 · 3 comments · May be fixed by #22
Open

Probably some mistake in class snippet #21

piotrgredowski opened this issue Jun 29, 2022 · 3 comments · May be fixed by #22

Comments

@piotrgredowski
Copy link

piotrgredowski commented Jun 29, 2022

Hi,
class snippet is not working correctly.
obraz
Expression from here is such complicated that I will not try to understand it :) but it's not working correctly. There's a problem with this second arg. It's not where it should be.
I've added PR solving that issue.

@piotrgredowski piotrgredowski linked a pull request Jun 29, 2022 that will close this issue
@pchoisel
Copy link
Contributor

pchoisel commented Aug 2, 2022

Hi @piotrgredowski

The snippet is working fine, you just need to use its auto-completion feature (the reason why its code is complicated ^^)
As shown in the video, using the tab key, you can scroll through the class definition parts and modify them. If you modify the args of the __init__ function, they will automatically be updated.

If you don't need any arguments, just remove arg in the function definition, press tab and the second arg will be removed. (As shown in the second example of the video.)

Hope this helps !

PS: If you experience problems with the auto-formatting of certain snippets, make sure you have the option editor.tabCompletion set on onlySnippets or on.

SnippetExample-2022-08-02_15.49.24.mp4

@Szumak75
Copy link

Hi!
The class snippet doesn't allow us to write the type of the argument and we receive generated code that requires correction:
Screenshot_20231221_213026

I suggest considering a small change that solves this problem for me:

	"Class": {
		"prefix": "class",
		"body": [
			"class ${1:ClassName}(${2:object}):",
			"\t\"\"\"${3:docstring for $1.}\"\"\"\n",
			"\tdef __init__(self, ${4:arg}) -> None:",
			"\t\t\"\"\"${5:Constructor.}\"\"\"",
			"\t\t${6:super($1, self).__init__()}",
			"\t\t${4/\\s*([^,:=]+)([^,=]+)?(?:=[^,]+)?(,\\s*|)/self.$1$2 = $1${3:+\n\t\t}/g}",
			"\t\t$0"
		],
		"description": 'Code snippet for a class definition.'
	}

Screenshot_20231221_213646

@pchoisel
Copy link
Contributor

pchoisel commented Jan 4, 2024

Looking good !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants