-
Notifications
You must be signed in to change notification settings - Fork 0
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
feature: Add ability to load snippets from file or directory #4
Comments
JFYI the frontmatter based approach is implemented in Foam extension for markdown templates https://foambubble.github.io/foam/features/note-templates. |
Hey! Thank you so much for reporting this issue! First of all, it would be possible soon to define snippets at workspace level (in However, your idea would be extremely useful in cases when snippets are large or you want to track them in individual files. Do we have some cross-IDE standard? Any extensions from other IDEs that implements something like this? I think to implement this setting with the following default: Also about frontmatter. It is okay to use it in Markdown files, however, for other languages it would be much better to define metadata in comments at the start of file. For example we can have file % .snippet
% locations: fileStart
% Licensed under the Apache License, Version 2.0 (the "License"); you may not
% ... Empty line is required as it used to denote end of metadata. Also we can skip definining It is much better to define metadata in comments, so we don't break:
Also, you can expect web support! |
"betterSnippets.customSnippets": [
{
"name": "foo",
"snippetFile": "..." This case won't be supported as this would make sense only in workspace-level configuration. In case above and in
That's why global snippets should always be defined in VSCode's |
I am not aware of cross-IDE standards.
I thought the However I do agree the syntax highlighting would be broken. |
Would it be possible to have a project specific snippets? For example by checking existence of
By default the |
Yes, that's why metadata will live in comments for now. As you said the file split in two parts: metadata and body. Metadata is commented.
Yes, it would be supported with this setting.
Great! This will be configurable! |
There is one problem with using comments. Most IDE use shebang presence to figure out which syntax to enable if file extension is not reliable. Which is the case for shell scripts. The shebang should be in the first line for this detection to work. |
Sorry for delayed response. I just started implementing this feature.
I see only two solutions:
#!/usr/bin/env bash
# .snippet
# locations: fileStart
if [[ "$OSTYPE" == "darwin"* ]]; then
# ... The body of the snippet would look like: #!/usr/bin/env bash
if [[ "$OSTYPE" == "darwin"* ]]; then
# ... However, I don't like the ambiguity it introduces. For example snippet can have > 100 lines and since snippet metadata can be placed at any line, programmer can spend some time to find it. It can be just annoying.
% ...
% License for the specific language governing permissions and limitations under
% the License.
-module(${TM_FILENAME_BASE}).
... And second file {
"locations": ["fileStart"]
} Supported formats would be: I more like the second solution and I'm currently planning to implement only it. WDYT? |
second file |
The https://github.com/asbjornh/vscode-module-templates extension supports loading templates from files using separate configuration field
module-templates.templateFiles
.This extension could use similar approach as well. For example
However ideally the configuration like follows would be perfect for my use case.
cat ./snippets/cdb-debug.erl
As you can see all configuration is contained in the frontmatter of the snippet file.
The text was updated successfully, but these errors were encountered: