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

[FGCP] Make Class Snippet Parse Filename #4981

Open
Number-3434 opened this issue Feb 10, 2024 · 2 comments
Open

[FGCP] Make Class Snippet Parse Filename #4981

Number-3434 opened this issue Feb 10, 2024 · 2 comments
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement
Milestone

Comments

@Number-3434
Copy link

Number-3434 commented Feb 10, 2024

This is a Fine-Grained Cherry-Pick (FGCP).

Replace ${1:Name} with ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}} in

"class": {
"prefix": "class",
"description": "Insert a class definition.",
"body": [
"class ${1:Name} {",
" $0",
"}"
]
},

...and replace the first $1 with ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/} in

"Flutter stateless widget": {
"prefix": "stless",
"description": "Insert a StatelessWidget",
"body": [
"class $1 extends StatelessWidget {",
" const $1({ Key? key }) : super(key: key);",
"",
" @override",
" Widget build(BuildContext context) {",
" return Container(",
" $2",
" );",
" }",
"}"
]
},

"Flutter stateful widget": {
"prefix": "stful",
"description": "Insert a StatefulWidget",
"body": [
"class $1 extends StatefulWidget {",
" const $1({ Key? key }) : super(key: key);",
"",
" @override",
" _$1State createState() => _$1State();",
"}",
"",
"class _$1State extends State<$1> {",
" @override",
" Widget build(BuildContext context) {",
" return Container(",
" $2",
" );",
" }",
"}"
]
},

"Flutter widget with AnimationController": {
"prefix": "stanim",
"description": "Insert a StatefulWidget with an AnimationController",
"body": [
"class $1 extends StatefulWidget {",
" const $1({ Key? key }) : super(key: key);",
"",
" @override",
" _$1State createState() => _$1State();",
"}",
"",
"class _$1State extends State<$1>",
" with SingleTickerProviderStateMixin {",
" late AnimationController _controller;",
"",
" @override",
" void initState() {",
" super.initState();",
" _controller = AnimationController(vsync: this);",
" }",
"",
" @override",
" void dispose() {",
" super.dispose();",
" _controller.dispose();",
" }",
"",
" @override",
" Widget build(BuildContext context) {",
" return Container(",
" $2",
" );",
" }",
"}"
]
}

This will make the snippet parse the filename (without the extensions), and sets it as the class name (converted to PascalCase).

@DanTup
Copy link
Member

DanTup commented Feb 12, 2024

Most users wouldn't see this change because these are legacy snippets and snippets now come from the server - see my comment at #4691 (comment).

I think if we do this, it should be in the server instead.

@Number-3434
Copy link
Author

Okay 👍.

@DanTup DanTup added this to the Backlog milestone Feb 13, 2024
@DanTup DanTup added in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server labels Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement
Projects
None yet
Development

No branches or pull requests

2 participants