Skip to content

Commit 7189efd

Browse files
Use new Talon snippet dependency
1 parent 3207be2 commit 7189efd

File tree

4 files changed

+24
-235
lines changed

4 files changed

+24
-235
lines changed

package-lock.json

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "andreas-talon",
33
"displayName": "Andreas Talon",
44
"description": "VSCode extension used by Talon Voice",
5-
"version": "3.59.0",
5+
"version": "3.60.0",
66
"publisher": "AndreasArvidsson",
77
"license": "MIT",
88
"main": "./out/extension.js",
@@ -318,8 +318,9 @@
318318
"pokey.parse-tree"
319319
],
320320
"dependencies": {
321+
"editorconfig": "^2.0.0",
321322
"ignore": "^5.2.4",
322-
"editorconfig": "^2.0.0"
323+
"talon-snippets": "1.0.1"
323324
},
324325
"devDependencies": {
325326
"@types/fs-extra": "^11.0.4",

src/language/SnippetFormatter.ts

Lines changed: 4 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,9 @@
1-
import { SnippetDocument, SnippetVariable, parseSnippetFile } from "./SnippetParser";
21
import type { LanguageFormatterText } from "./registerLanguageFormatters";
2+
import { parseSnippetFile, serializeSnippetFile } from "talon-snippets";
33

44
export const snippetFormatter: LanguageFormatterText = {
5-
getText(text: string, ident: string): string {
6-
const formatter = new SnippetFormatter(ident);
7-
return formatter.getText(text);
5+
getText(text: string, _ident: string): string {
6+
const documents = parseSnippetFile(text);
7+
return serializeSnippetFile(documents);
88
}
99
};
10-
11-
class SnippetFormatter {
12-
constructor(private ident: string) {}
13-
14-
getText(text: string): string {
15-
const result = parseSnippetFile(text)
16-
.map((s) => this.getDocumentText(s))
17-
// Remove empty documents
18-
.filter(Boolean)
19-
.join("\n---\n\n");
20-
return result ? result + "\n---\n" : "";
21-
}
22-
23-
private getDocumentText(document: SnippetDocument): string {
24-
const parts: string[] = [
25-
this.getOptionalPairString("name", document.name),
26-
this.getOptionalPairString("language", document.languages),
27-
this.getOptionalPairString("phrase", document.phrases),
28-
this.getOptionalPairString("insertionScope", document.insertionScopes)
29-
].filter(Boolean);
30-
31-
if (document.variables.length > 0) {
32-
if (parts.length > 0) {
33-
parts.push("");
34-
}
35-
parts.push(...this.getSortedVariables(document.variables));
36-
}
37-
38-
if (document.body != null) {
39-
parts.push("-", ...document.body);
40-
}
41-
42-
return parts.join("\n");
43-
}
44-
45-
private getSortedVariables(variables: SnippetVariable[]): string[] {
46-
const result = [...variables];
47-
result.sort(compareVariables);
48-
return result
49-
.flatMap((variable) => [
50-
this.getOptionalPairString(
51-
`$${variable.name}.insertionFormatter`,
52-
variable.insertionFormatters
53-
),
54-
this.getOptionalPairString(
55-
`$${variable.name}.wrapperPhrase`,
56-
variable.wrapperPhrases
57-
),
58-
this.getOptionalPairString(`$${variable.name}.wrapperScope`, variable.wrapperScope)
59-
])
60-
.filter(Boolean);
61-
}
62-
63-
private getOptionalPairString(key: string, value: string | string[] | undefined): string {
64-
if (value == null) {
65-
return "";
66-
}
67-
if (Array.isArray(value)) {
68-
return `${key}: ${value.join(" | ")}`;
69-
}
70-
return `${key}: ${value}`;
71-
}
72-
}
73-
74-
function compareVariables(a: SnippetVariable, b: SnippetVariable): number {
75-
if (a.name === "0") {
76-
return 1;
77-
}
78-
if (b.name === "0") {
79-
return -1;
80-
}
81-
return a.name.localeCompare(b.name);
82-
}

src/language/SnippetParser.ts

Lines changed: 0 additions & 153 deletions
This file was deleted.

0 commit comments

Comments
 (0)