Skip to content

Commit 8d6143d

Browse files
committed
Snippets support
1 parent bbf539a commit 8d6143d

File tree

5 files changed

+113
-1
lines changed

5 files changed

+113
-1
lines changed

CONTRIBUTING.md

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ For more grammar inspirations, check:
4646
- [TypeScript's grammar](https://github.com/microsoft/TypeScript-TmLanguage/blob/a771bc4e79deeae81a01d988a273e300290d0072/TypeScript.YAML-tmLanguage)
4747
- [Writing a TextMate Grammar: Some Lessons Learned](https://www.apeth.com/nonblog/stories/textmatebundle.html)
4848

49+
### Snippets
50+
51+
Snippets are also synced from https://github.com/rescript-lang/rescript-sublime. VSCode snippets docs [here](https://code.visualstudio.com/api/references/contribution-points#contributes.snippets).
52+
4953
## Editor Diagnostics
5054

5155
They should be synced in from `lib/bs/.compiler.log` build. Don't take them from other places.

HISTORY.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.0.x (Unreleased)
2+
3+
- All the usual features now work on `bsconfig.json` too!
4+
- Snippets, for ease a few syntaxes.
5+
- Improved highlighting for polymorphic variants
6+
17
## 1.0.1
28

39
- Fix temp file creation logic.

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
The official VSCode plugin for ReScript.
44

5+
![ezgif com-video-to-gif-2](https://user-images.githubusercontent.com/1909539/101266821-790b1400-3707-11eb-8e9f-fb7e36e660e6.gif)
6+
57
## Prerequisite
68

79
You **must** have `bs-platform 8.3.3` installed locally in your project, through the usual [npm installation](https://rescript-lang.org/docs/manual/latest/installation#integrate-into-existing-js-project). Older versions are not guaranteed to work.
@@ -20,9 +22,12 @@ The plugin activates on `.res` and `.resi` files. If you've already got Reason-L
2022
- Cannot be a temporary file.
2123
- Syntax errors diagnosis (only after formatting).
2224
- Built-in bsb watcher (optional, and exposed explicitly as a pop-up; no worries of dangling build).
23-
- Type diagnosis.
25+
- Type hint.
2426
- Jump to location.
2527
- Autocomplete.
28+
- Snippets to ease a few syntaxes:
29+
- `external` features such as `@bs.module` and `@bs.val`
30+
- `try`, `for`, etc.
2631

2732
### Upcoming Features
2833

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
"url": "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/master/docs/docson/build-schema.json"
3030
}
3131
],
32+
"snippets": [
33+
{
34+
"language": "rescript",
35+
"path": "./snippets.json"
36+
}
37+
],
3238
"taskDefinitions_unused": [
3339
{
3440
"type": "bsb",

snippets.json

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"Module": {
3+
"prefix": [
4+
"module"
5+
],
6+
"body": [
7+
"module ${1:Name} = {",
8+
"\t${2:// Module contents}",
9+
"}"
10+
]
11+
},
12+
"Switch": {
13+
"prefix": [
14+
"switch"
15+
],
16+
"body": [
17+
"switch ${1:value} {",
18+
"| ${2:pattern1} => ${3:expression}",
19+
"${4:| ${5:pattern2} => ${6:expression}}",
20+
"}"
21+
]
22+
},
23+
"Try": {
24+
"prefix": [
25+
"try"
26+
],
27+
"body": [
28+
"try {",
29+
"\t${1:expression}",
30+
"} catch {",
31+
"| ${2:MyException} => ${3:expression}",
32+
"}"
33+
]
34+
},
35+
"For Loop": {
36+
"prefix": [
37+
"for"
38+
],
39+
"body": [
40+
"for ${1:i} in ${2:startValueInclusive} to ${3:endValueInclusive} {",
41+
"\t${4:Js.log(${1:i})}",
42+
"}"
43+
]
44+
},
45+
"Reverse For Loop": {
46+
"prefix": [
47+
"for"
48+
],
49+
"body": [
50+
"for ${1:i} in ${2:startValueInclusive} downto ${3:endValueInclusive} {",
51+
"\t${4:Js.log(${1:i})}",
52+
"}"
53+
]
54+
},
55+
"Global External Object": {
56+
"prefix": [
57+
"@bs",
58+
"external"
59+
],
60+
"body": [
61+
"@val external ${1:setTimeout}: ${2:(unit => unit, int) => float} = \"${3:setTimeout}\""
62+
]
63+
},
64+
"Global External Module": {
65+
"prefix": [
66+
"@bs",
67+
"external"
68+
],
69+
"body": [
70+
"@scope(\"${1:Math}\") @val external ${2:random}: ${3:unit => float} = \"${4:random}\""
71+
]
72+
},
73+
"JS Module External": {
74+
"prefix": [
75+
"@bs",
76+
"external"
77+
],
78+
"body": [
79+
"@module(\"${1:path}\") external ${2:dirname}: ${3:string => string} = \"${4:dirname}\""
80+
]
81+
},
82+
"JS Module Default External": {
83+
"prefix": [
84+
"@bs",
85+
"external"
86+
],
87+
"body": [
88+
"@module external ${1:leftPad}: ${2:(string, int) => string} = \"${3:leftPad}\""
89+
]
90+
}
91+
}

0 commit comments

Comments
 (0)