Skip to content

Commit

Permalink
Don't add document divider on empty snippet file
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Jun 16, 2024
1 parent af6bbdb commit 5dea94a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "andreas-talon",
"displayName": "Andreas Talon",
"description": "VSCode extension used by Talon Voice",
"version": "3.49.2",
"version": "3.50.0",
"publisher": "AndreasArvidsson",
"license": "MIT",
"main": "./out/extension.js",
Expand Down
13 changes: 6 additions & 7 deletions src/language/SnippetFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ class SnippetFormatter {

getText(text: string): string {
const eol = this.eol;
return (
parseSnippetFile(text)
.map((s) => this.getDocumentText(s))
// Remove empty documents
.filter(Boolean)
.join(`${eol}---${eol}${eol}`) + `${eol}---${eol}`
);
const result = parseSnippetFile(text)
.map((s) => this.getDocumentText(s))
// Remove empty documents
.filter(Boolean)
.join(`${eol}---${eol}${eol}`);
return result ? result + `${eol}---${eol}` : "";
}

private getDocumentText(document: SnippetDocument): string {
Expand Down
7 changes: 6 additions & 1 deletion src/test/snippetFormatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ baz
`
},
{
title: "Empty document",
title: "Empty snippet document",
pre: `\
name: test
---
Expand All @@ -75,6 +75,11 @@ test
---
`
},
{
title: "Empty file",
pre: "",
post: ""
},
{
title: "Large file",
pre: `\
Expand Down

0 comments on commit 5dea94a

Please sign in to comment.