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

Optional quick start from snippet/template in empty files #145929

Closed
digitarald opened this issue Mar 23, 2022 · 12 comments
Closed

Optional quick start from snippet/template in empty files #145929

digitarald opened this issue Mar 23, 2022 · 12 comments
Assignees
Labels
feature-request Request for new features or functionality snippets under-discussion Issue is under discussion for relevance, priority, approach verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@digitarald
Copy link
Contributor

digitarald commented Mar 23, 2022

When starting a new file, I want to have the option to pick from template, so that I don't have to start from scratch and google for a boilerplate to paste in.

It happened a few times like this in user testing. Participants create a file, discover the intuitive language quick pick that the placeholder offers and are delighted 😁. With a blank file in hand they then wander off to search engines to find boilerplate to test 🤨. Some languages suffer worse than others from impossible to remember boilerplate (HTML 😭). I never saw participants using snippets or emmet as the magic fast path to fill a file quickly.

How might we apply the placeholder text that allows picking a language to also picking a template:

Starting with an untitled buffer:

  1. Create untitled buffer
  2. Placeholder text offers to pick a language -> Quick pick HTML
  3. Placeholder text offers to start from a template --> Quick pick html!!
  4. 🎉

From creating an empty file in the workspace:

  1. Create new index.html file in Explorer and open it.
  2. Placeholder text offers to start from a template --> Quick pick html!!
  3. 🎉

Snippets could be the existing system to provide those templates. They already have a prefix and description, which can be used in the quick pick. Their placeholders can also help to quickly name a component that is being created, set a title, etc.

cc @stevencl @sana-ajani

Ideas:

  • The quick pick selection could also preview the snippet as ghost text.
  • Easter egg for pasting a little HTML game or spinning VS Code logo.
@digitarald digitarald added the feature-request Request for new features or functionality label Mar 23, 2022
@digitarald digitarald added this to the Backlog milestone Mar 23, 2022
@digitarald digitarald self-assigned this Mar 23, 2022
@digitarald digitarald changed the title Optional quick start from snippet in empty files Optional quick start from snippet/template in empty files Mar 31, 2022
@digitarald digitarald added the under-discussion Issue is under discussion for relevance, priority, approach label Mar 31, 2022
@digitarald digitarald modified the milestones: Backlog, April 2022 Mar 31, 2022
@digitarald
Copy link
Contributor Author

Related user feedback: #145046 (comment)

@jrieken
Copy link
Member

jrieken commented Jun 27, 2022

@digitarald Let's discuss but the implementation has to wail till July

@jrieken
Copy link
Member

jrieken commented Jun 30, 2022

  • for snippets add "isTopLevel": true property
  • new file flow (plaintext): add to existing ghost text, "start from snippet" which shows all snippets of languages and sets both: language and snippet
  • Also, automatically populate new files with configured snippets. Have user/workspace setting that links langId to snippet-source or snippet-reference
  • update built-in snippets with this new feature
  • ping extension authors

@jrieken
Copy link
Member

jrieken commented Jul 15, 2022

With #155321 (a bigger PR with some other things as well)

Screen.Recording.2022-07-15.at.18.06.28.mov

Snippets that have one or more scopes (set via the JSON-property or their file-name, in case of extensions) also set the document language. Snippets without scope (rare) don't affect the language


@digitarald I believe we should reconsider the isTopLevel-name. Maybe be all explicit and name it "isForEmptyFile" or so 🤷

@ArturoDent
Copy link

Maybe newFileTemplate or just template.

@hahn-kev
Copy link

I like newFileSnippet or fileSnippet all snippets can be templates already (meaning they have a variable that gets substituted at evaluation time) so I'm not sure using the word template is helpful here.

jrieken added a commit that referenced this issue Jul 19, 2022
* rename to `isFileTemplate`

* add code snippet provider for file templates, fix setting model mode

#145929
@jrieken
Copy link
Member

jrieken commented Jul 19, 2022

We went with isFileTemplate

@jrieken
Copy link
Member

jrieken commented Jul 22, 2022

To verify:

  • have a custom or contributed snippets that uses the isFileTemplate-property (see below)
  • run F1 > Populate File From Snippet
  • verify that it replaces the file contents the selected snipppet and that it sets the language
  • verify it only sets the language when the snippets defines one (via scope for *.code-snippets files)
  • invoke code actions (cmd+.) in an empty file and make sure there is a code action for each template snippet
"css-template": {
"isFileTemplate": true,
"scope": "css,javascript",
"body": [
	"* {",
	"\tcolor: ${1:green};",
	"}",
]
},

@andreamah andreamah added the verified Verification succeeded label Jul 27, 2022
@andreamah
Copy link
Contributor

I find that files that are out-of scope are also allowing for code snippets. I made a txt file for your example above and it still allowed me to paste it in.
Recording 2022-07-27 at 11 14 27

@andreamah andreamah added verification-found Issue verification failed and removed verified Verification succeeded labels Jul 27, 2022
@connor4312 connor4312 reopened this Jul 27, 2022
@alexdima alexdima self-assigned this Jul 29, 2022
@alexdima alexdima modified the milestones: July 2022, August 2022 Jul 29, 2022
@alexdima alexdima removed their assignment Jul 29, 2022
@jrieken jrieken closed this as completed Aug 16, 2022
@jrieken
Copy link
Member

jrieken commented Aug 16, 2022

I find that files that are out-of scope are also allowing for code snippets.

It will always show all "file snippets" but it will only update the language mode if the snippets defines one. The point of the feature is to populate the (empty) file with contents and set the corresponding language. That why there is no filtering

@rzhao271
Copy link
Contributor

When I insert the JS snippet in a new empty file, the language changes to JS, but then auto-detection changes it back to CSS.

@hinell
Copy link

hinell commented Sep 6, 2022

Please, update documentation on this feature in the related documentation:

I also request to update every new snippet header file to:

// ...
// "Print to console": {
// 	"scope": "javascript,typescript",
//     "isTopLevel": true,
// 	"prefix": "log",
// 	"body": [
// 		"console.log('$1');",
// 		"$2"
// 	],
// 	"description": "Log output to console"
// }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality snippets under-discussion Issue is under discussion for relevance, priority, approach verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests