Skip to content

Commit aaab2e7

Browse files
committed
Work on auto generating markdown tables, and custom snippet format
1 parent 894ba12 commit aaab2e7

18 files changed

+339
-4
lines changed

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"deno.enable": true,
3+
"deno.unstable": true
4+
}

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Supported file extensions:
2727
## Setup
2828
The following is not mandatory, but provides a nicer experience.
2929

30-
Search for `editor.snippetSuggestions` and `editor.snippetSuggestions` in user settings, or edit the settings.json directly:
30+
Search for `editor.tabCompletion` in user settings, or edit the settings.json directly:
3131
```jsonc
3232
// Tab complete will insert the best matching suggestion when pressing tab.
3333
"editor.tabCompletion": "on"
@@ -54,6 +54,17 @@ You can use these snippets along with Prettier/ESLint to have your code automati
5454

5555
## Snippets
5656

57+
### Declarations
58+
| Prefix | Description | Body |
59+
| ---------- | --------------------- | ------------------------------ |
60+
| `c` | const | `const $0` |
61+
| `l` | let | `let $0` |
62+
| `ca` | const assignment | `const $1 = $0` |
63+
| `la` | let assignment | `let $1 = $0` |
64+
| `cas` | const string | `const $1 = '$0'` |
65+
| `car` | const array | `const $1 = [$0]` |
66+
| `cao` | const object | `const $1 = { $0 }` |
67+
5768
### Declarations
5869

5970
#### `c`   -   const statement

javascript.code-snippets

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"const ⚡": {
3+
"prefix": "c",
4+
"body": "const $0"
5+
},
6+
"let ⚡": {
7+
"prefix": "l",
8+
"body": "let $0"
9+
},
10+
"const assignment ⚡ ⚡": {
11+
"prefix": "ca",
12+
"body": "const $1 = $0"
13+
},
14+
"let assignment ⚡ ⚡": {
15+
"prefix": "la",
16+
"body": "let $1 = $0"
17+
},
18+
"const string ⚡ ⚡": {
19+
"prefix": "cas",
20+
"body": "const $1 = '$0'"
21+
},
22+
"const array ⚡ ⚡": {
23+
"prefix": "car",
24+
"body": "const $1 = [$0]"
25+
},
26+
"const object ⚡ ⚡": {
27+
"prefix": "cao",
28+
"body": "const $1 = { $0 }"
29+
},
30+
"promise ⚡": {
31+
"prefix": "pr",
32+
"body": "new Promise((resolve, reject) => {\n\t$0\n})"
33+
},
34+
"promise resolve ⚡": {
35+
"prefix": "prs",
36+
"body": "Promise.resolve($1)$0"
37+
},
38+
"promise reject ⚡": {
39+
"prefix": "prj",
40+
"body": "Promise.reject($1)$0"
41+
},
42+
"promise.then ⚡": {
43+
"prefix": "then",
44+
"body": "$1.then((${2:value}) => $0"
45+
},
46+
"promise.catch ⚡": {
47+
"prefix": "catch",
48+
"body": "$1.catch((${2:err}) => $0"
49+
},
50+
"promise.then.catch ⚡": {
51+
"prefix": "thenc",
52+
"body": "$1.then((${2:value}) => $3.catch((${4:err}) => $5"
53+
},
54+
"promise.all ⚡": {
55+
"prefix": "pra",
56+
"body": "Promise.all($1)$0"
57+
},
58+
"promise.allSettled ⚡": {
59+
"prefix": "prsa",
60+
"body": "Promise.allSettled($1)$0"
61+
},
62+
"promise.any ⚡": {
63+
"prefix": "pran",
64+
"body": "Promise.any($1)$0"
65+
}
66+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"vscode": "^1.x.x"
3838
},
3939
"scripts": {
40-
"publish": "vsce package && vsce publish"
40+
"publish": "vsce package && vsce publish",
41+
"generate": "deno run --allow-write src/app.ts"
4142
},
4243
"contributes": {
4344
"snippets": [

src/app.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { javascript, typescript } from "./snippets/app.ts";
2+
import {
3+
convertToVscSnippet,
4+
groupSnippets,
5+
logTables,
6+
writeSnippetFile,
7+
} from "./utils/app.ts";
8+
9+
const javascriptVscArray = javascript.map(convertToVscSnippet);
10+
const typescriptVscArray = typescript.map(convertToVscSnippet);
11+
12+
// Log tables for every section of every language
13+
logTables("JavaScript", javascriptVscArray);
14+
logTables("TypeScript", typescriptVscArray);
15+
16+
// Create single snippet object
17+
const snippetJavascript = groupSnippets(javascriptVscArray);
18+
const snippetTypescript = groupSnippets(typescriptVscArray);
19+
20+
// Single snippet files
21+
writeSnippetFile("javascript", snippetJavascript);
22+
writeSnippetFile("typescript", snippetTypescript);

src/models/app.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export type VscSnippet = {
2+
prefix: string | string[];
3+
body: string | string[];
4+
description?: string;
5+
};
6+
// name: { prefix: string | [], body: string | string[], description?: string }
7+
export type VscSnippetDict = Record<string, VscSnippet>;
8+
9+
export type XSnippet = Omit<VscSnippet, "prefix"> & { name: string };
10+
11+
// prefix: { name: string, body: string | string[], description?: string }
12+
export type XSnippetDict = Record<string, XSnippet>;

src/snippets/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./js/app.ts";
2+
export * from "./ts/app.ts";

snippets/js.code-snippets renamed to src/snippets/js.code-snippets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"const assignment ⚡": {
1212
"prefix": "ca",
13-
"body": "const $1 = $0;"
13+
"body": "const $1 = $0"
1414
},
1515
"let assignment ⚡": {
1616
"prefix": "la",

src/snippets/js/app.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { promises } from "./promises.ts";
2+
import { declarations } from "./declarations.ts";
3+
4+
export const javascript = [
5+
declarations,
6+
promises,
7+
];

src/snippets/js/declarations.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export const declarations = {
2+
c: {
3+
name: "const",
4+
body: "const $0",
5+
},
6+
l: {
7+
name: "let",
8+
body: "let $0",
9+
},
10+
ca: {
11+
name: "const assignment ⚡",
12+
body: "const $1 = $0",
13+
},
14+
la: {
15+
name: "let assignment ⚡",
16+
body: "let $1 = $0",
17+
},
18+
cas: {
19+
name: "const string ⚡",
20+
body: "const $1 = '$0'",
21+
},
22+
car: {
23+
name: "const array ⚡",
24+
body: "const $1 = [$0]",
25+
},
26+
cao: {
27+
name: "const object ⚡",
28+
body: "const $1 = { $0 }",
29+
},
30+
};

0 commit comments

Comments
 (0)