Skip to content

Added description field #2

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

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "talon-snippets",
"displayName": "Talon snippets",
"version": "1.1.0",
"version": "1.2.0",
"description": "Snippets library for Talon",
"author": "Andreas Arvidsson",
"publisher": "AndreasArvidsson",
Expand Down
3 changes: 3 additions & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ function parseContext(text: string): SnippetDocument | undefined {
case "name":
document.name = value;
break;
case "description":
document.description = value;
break;
case "phrase":
document.phrases = parseVectorValue(value);
break;
Expand Down
1 change: 1 addition & 0 deletions src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function serializeSnippetFile(snippetDocuments: SnippetDocument[]): strin
function getDocumentText(document: SnippetDocument): string {
const parts: string[] = [
getOptionalPairString("name", document.name),
getOptionalPairString("description", document.description),
getOptionalPairString("language", document.languages),
getOptionalPairString("phrase", document.phrases),
getOptionalPairString("insertionScope", document.insertionScopes),
Expand Down
44 changes: 23 additions & 21 deletions src/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,9 @@ suite("parser", () => {
});

function testFull() {
const fixture = `
name: foo
-

foo

bar
baz `;

const expected: SnippetDocument = {
name: "foo",
body: [" foo", "", " bar", "baz"],
variables: [],
};

const actual = parseSnippetFile(fixture);

assert.deepEqual(actual, [expected]);
}

function testWhitespace() {
const fixture = `\
name: mySnippet
description: My snippet
phrase: try catch
language: javascript
insertionScope: statement
Expand All @@ -54,6 +34,7 @@ try {

const expected: SnippetDocument = {
name: "mySnippet",
description: "My snippet",
phrases: ["try catch"],
languages: ["javascript"],
insertionScopes: ["statement"],
Expand All @@ -78,6 +59,27 @@ try {
assert.deepEqual(actual, [expected]);
}

function testWhitespace() {
const fixture = `
name: foo
-

foo

bar
baz `;

const expected: SnippetDocument = {
name: "foo",
body: [" foo", "", " bar", "baz"],
variables: [],
};

const actual = parseSnippetFile(fixture);

assert.deepEqual(actual, [expected]);
}

function testNameOnly() {
const fixture = "name: mySnippet";
const expected: SnippetDocument = {
Expand Down
2 changes: 2 additions & 0 deletions src/test/serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function testMultipleValues() {
const fixture: SnippetDocument[] = [
{
name: "mySnippet",
description: "My snippet",
phrases: ["first", "second"],
languages: ["javascript", "java"],
insertionScopes: ["function", "statement"],
Expand All @@ -83,6 +84,7 @@ function testMultipleValues() {

const expected = `\
name: mySnippet
description: My snippet
language: javascript | java
phrase: first | second
insertionScope: function | statement
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface SnippetDocument {
name?: string;
description?: string;
phrases?: string[];
insertionScopes?: string[];
languages?: string[];
Expand Down